Skip to content

Instantly share code, notes, and snippets.

@ThisIsMissEm
Created November 1, 2010 16:40
Show Gist options
  • Save ThisIsMissEm/658472 to your computer and use it in GitHub Desktop.
Save ThisIsMissEm/658472 to your computer and use it in GitHub Desktop.
var util = require("./_util")
, events = require("events")
EventEmitter = exports.EventEmitter = function(){
events.EventEmitter.call(this);
};
util.inherits(EventEmitter, events.EventEmitter);
EventEmitter.prototype.emit = function(type) {
if (type !== "newListener"
&& (!this._events || !this._events[type])
&& this._bubbleTarget && this._bubbleTarget[type]
) {
// util.error("\033[31mEvent: "+type+", source: "+this.constructor.name+", target: "+this._bubbleTarget[type].constructor.name+"\033[39m");
this._bubbleTarget[type].emit.apply(this._bubbleTarget[type], arguments);
} else {
// util.error("\033[31mEvent: "+type+", source: "+this.constructor.name+"\033[39m");
events.EventEmitter.prototype.emit.apply(this, arguments);
}
};
EventEmitter.prototype.bubbleEvent = function(type, target){
if(!this._bubbleTarget) this._bubbleTarget = {};
this._bubbleTarget[type] = target;
};
EventEmitter.prototype.removeBubbleEvent = function(type) {
delete this._bubbleTarget[type];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment