refactor events handler so it can handle multiple args
This commit is contained in:
parent
3e1f16c673
commit
c7f8698e58
|
@ -29,23 +29,26 @@ EventEmitter.prototype.setHandler = function(requestName, cb) {
|
||||||
return _setHandler.call(this, requestName, cb);
|
return _setHandler.call(this, requestName, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
EventEmitter.prototype.request = function(requestName, cb) {
|
EventEmitter.prototype.request = function() {
|
||||||
|
let requestName = arguments[0];
|
||||||
|
let other_args = [].slice.call(arguments, 1);
|
||||||
|
|
||||||
log("requesting: ", requestName);
|
log("requesting: ", requestName);
|
||||||
warnIfLegacy(requestName);
|
warnIfLegacy(requestName);
|
||||||
return this.emit('request:' + requestName, cb);
|
return this.emit('request:' + requestName, ...other_args);
|
||||||
};
|
};
|
||||||
|
|
||||||
EventEmitter.prototype.setCommandHandler = function(requestName, cb) {
|
EventEmitter.prototype.setCommandHandler = function(requestName, cb) {
|
||||||
log("setting command handler for: ", requestName);
|
log("setting command handler for: ", requestName);
|
||||||
return this.on('request:' + requestName, function(_cb) {
|
return this.on('request:' + requestName, function(_cb) {
|
||||||
cb.call(this, _cb);
|
cb.call(this, ...arguments);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
EventEmitter.prototype.setCommandHandlerOnce = function(requestName, cb) {
|
EventEmitter.prototype.setCommandHandlerOnce = function(requestName, cb) {
|
||||||
log("setting command handler for: ", requestName);
|
log("setting command handler for: ", requestName);
|
||||||
return this.once('request:' + requestName, function(_cb) {
|
return this.once('request:' + requestName, function(_cb) {
|
||||||
cb.call(this, _cb);
|
cb.call(this, ...arguments);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue