Skip to content

Commit

Permalink
Also implement internal _emit / _removeAllListeners to make migration…
Browse files Browse the repository at this point in the history
… path easier.
  • Loading branch information
Gozala committed Feb 8, 2012
1 parent 5744120 commit 2188d86
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/api-utils/lib/events.js
Expand Up @@ -5,11 +5,14 @@
"use strict";


const { on, once, off } = require('./event/core');
const { on, once, off, emit } = require('./event/core');
const { method } = require('./utils/function');
const WARNING = 'This API is deprecated and will be removed in an upcoming ' +
'version please use "api-utils/event/target" instead';

exports.EventEmitter = require("./traits").Trait.compose({
on: function(type, listener) {
console.log(type, !listener && Error().stack)
on(this._public, type, listener);
return this._public;
},
Expand All @@ -20,6 +23,16 @@ exports.EventEmitter = require("./traits").Trait.compose({
removeListener: function(type, listener) {
off(this._public, type, listener);
return this._public;
},
_emit: function(type) {
console.warn(WARNING);
emit.apply(null, [ this._public ].concat(Array.slice(arguments)));
return this._public;
},
_removeAllListeners: function(type) {
console.warn(WARNING);
type ? off(this._public, type) : off(this._public);
return this._public;
}
});

Expand All @@ -35,5 +48,15 @@ exports.EventEmitterTrait = require('./light-traits').Trait({
removeListener: function(type, listener) {
off(this, type, listener);
return this;
},
_emit: function(type) {
console.warn(WARNING);
emit.apply(null, [ this ].concat(Array.slice(arguments)));
return this;
},
_removeAllListeners: function(type) {
console.warn(WARNING);
type ? off(this, type) : off(this);
return this;
}
});

0 comments on commit 2188d86

Please sign in to comment.