mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-22 19:23:31 +00:00
Added event_forwarder helper
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -16,12 +16,13 @@ limitations under the License.
|
||||
|
||||
var refTable = {};
|
||||
|
||||
function event_switcher_helper(desired_callee, target)
|
||||
function event_switcher_helper(desired_callee, target, forward)
|
||||
{
|
||||
this._ObjectID = 'event_switcher';
|
||||
this.func = function func()
|
||||
{
|
||||
var args = [];
|
||||
if (func.forward != null) { args.push(func.forward); }
|
||||
for(var i in arguments)
|
||||
{
|
||||
args.push(arguments[i]);
|
||||
@@ -30,6 +31,7 @@ function event_switcher_helper(desired_callee, target)
|
||||
};
|
||||
this.func.desired = desired_callee;
|
||||
this.func.target = target;
|
||||
this.func.forward = forward;
|
||||
this.func.self = this;
|
||||
}
|
||||
function event_switcher(desired_callee, target)
|
||||
@@ -37,6 +39,11 @@ function event_switcher(desired_callee, target)
|
||||
return (new event_switcher_helper(desired_callee, target));
|
||||
}
|
||||
|
||||
function event_forwarder(sourceObj, sourceName, targetObj, targetName)
|
||||
{
|
||||
sourceObj.on(sourceName, (new event_switcher_helper(targetObj, targetObj.emit, targetName)).func);
|
||||
}
|
||||
|
||||
function Promise(promiseFunc)
|
||||
{
|
||||
this._ObjectID = 'promise';
|
||||
@@ -208,3 +215,4 @@ Promise.all = function all(promiseList)
|
||||
|
||||
module.exports = Promise;
|
||||
module.exports.event_switcher = event_switcher;
|
||||
module.exports.event_forwarder = event_forwarder;
|
||||
Reference in New Issue
Block a user