refactor events handler so it can handle multiple args

This commit is contained in:
Iuri Matias 2017-12-30 17:51:52 -05:00
parent 3e1f16c673
commit c7f8698e58
1 changed files with 7 additions and 4 deletions

View File

@ -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);
}); });
}; };