1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-22 11:13:21 +00:00

Added event_forwarder helper

This commit is contained in:
Bryan Roe
2020-01-28 12:21:59 -08:00
parent 3c7d5effb2
commit 8265cafbdb
2 changed files with 11 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@@ -16,12 +16,13 @@ limitations under the License.
var refTable = {}; var refTable = {};
function event_switcher_helper(desired_callee, target) function event_switcher_helper(desired_callee, target, forward)
{ {
this._ObjectID = 'event_switcher'; this._ObjectID = 'event_switcher';
this.func = function func() this.func = function func()
{ {
var args = []; var args = [];
if (func.forward != null) { args.push(func.forward); }
for(var i in arguments) for(var i in arguments)
{ {
args.push(arguments[i]); args.push(arguments[i]);
@@ -30,6 +31,7 @@ function event_switcher_helper(desired_callee, target)
}; };
this.func.desired = desired_callee; this.func.desired = desired_callee;
this.func.target = target; this.func.target = target;
this.func.forward = forward;
this.func.self = this; this.func.self = this;
} }
function event_switcher(desired_callee, target) function event_switcher(desired_callee, target)
@@ -37,6 +39,11 @@ function event_switcher(desired_callee, target)
return (new event_switcher_helper(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) function Promise(promiseFunc)
{ {
this._ObjectID = 'promise'; this._ObjectID = 'promise';
@@ -208,3 +215,4 @@ Promise.all = function all(promiseList)
module.exports = Promise; module.exports = Promise;
module.exports.event_switcher = event_switcher; module.exports.event_switcher = event_switcher;
module.exports.event_forwarder = event_forwarder;