Created
June 28, 2015 14:02
-
-
Save extraordinaire/236d29b5ca68a87431d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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