Skip to content

Instantly share code, notes, and snippets.

@extraordinaire
Created June 28, 2015 14:02
Show Gist options
  • Save extraordinaire/236d29b5ca68a87431d0 to your computer and use it in GitHub Desktop.
Save extraordinaire/236d29b5ca68a87431d0 to your computer and use it in GitHub Desktop.
var EventEmitter = require('events').EventEmitter;
var _ = require('lodash');
function PastEventEmitter() {
EventEmitter.call(this);
this.past = [];
var old_emit = this.emit;
this.emit = function(event) {
this.past.push(event);
old_emit.apply(this, arguments);
}
this.after = function(event, listener) {
listener = _.ary(listener, 0);
if (this.past.indexOf(event) !== -1) {
return listener();
}
this.on(event, listener);
};
}
PastEventEmitter.prototype = _.create(EventEmitter.prototype, {
'constructor': PastEventEmitter
});
module.exports = PastEventEmitter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment