2017-03-31 11:34:43 +00:00
|
|
|
var EventEmitter = require('events');
|
2017-02-24 11:18:57 +00:00
|
|
|
|
2017-08-04 00:03:17 +00:00
|
|
|
function warnIfLegacy(eventName) {
|
|
|
|
const legacyEvents = ['abi-vanila', 'abi', 'abi-contracts-vanila', 'abi-vanila-deployment'];
|
|
|
|
if (legacyEvents.indexOf(eventName) >= 0) {
|
|
|
|
console.warn("this event is deprecated and will be removed in future versions: " + eventName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const _on = EventEmitter.prototype.on;
|
|
|
|
const _setHandler = EventEmitter.prototype.setHandler;
|
|
|
|
|
|
|
|
EventEmitter.prototype.on = function(requestName, cb) {
|
|
|
|
warnIfLegacy(requestName);
|
|
|
|
return _on.call(this, requestName, cb);
|
|
|
|
};
|
|
|
|
|
|
|
|
EventEmitter.prototype.setHandler = function(requestName, cb) {
|
|
|
|
warnIfLegacy(requestName);
|
|
|
|
return _setHandler.call(this, requestName, cb);
|
|
|
|
};
|
|
|
|
|
2017-07-06 22:48:20 +00:00
|
|
|
EventEmitter.prototype.request = function(requestName, cb) {
|
2017-08-04 00:03:17 +00:00
|
|
|
warnIfLegacy(requestName);
|
|
|
|
return this.emit('request:' + requestName, cb);
|
2017-07-06 22:48:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
EventEmitter.prototype.setCommandHandler = function(requestName, cb) {
|
2017-08-04 00:03:17 +00:00
|
|
|
return this.on('request:' + requestName, function(_cb) {
|
2017-07-06 22:48:20 +00:00
|
|
|
cb.call(this, _cb);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-02-24 11:18:57 +00:00
|
|
|
module.exports = EventEmitter;
|