From c7f8698e5859df7a7a5e347db65ebda0929a35e6 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sat, 30 Dec 2017 17:51:52 -0500 Subject: [PATCH] refactor events handler so it can handle multiple args --- lib/core/events.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/core/events.js b/lib/core/events.js index f7f055fc..c561f000 100644 --- a/lib/core/events.js +++ b/lib/core/events.js @@ -29,23 +29,26 @@ EventEmitter.prototype.setHandler = function(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); warnIfLegacy(requestName); - return this.emit('request:' + requestName, cb); + return this.emit('request:' + requestName, ...other_args); }; EventEmitter.prototype.setCommandHandler = function(requestName, cb) { log("setting command handler for: ", requestName); return this.on('request:' + requestName, function(_cb) { - cb.call(this, _cb); + cb.call(this, ...arguments); }); }; EventEmitter.prototype.setCommandHandlerOnce = function(requestName, cb) { log("setting command handler for: ", requestName); return this.once('request:' + requestName, function(_cb) { - cb.call(this, _cb); + cb.call(this, ...arguments); }); };