I'm trying to track down an issue in my SPA where an event is being triggered too many times. With that in mind, I wanted to override node's eventEmitter.on
function to add some logging in then call the original. This lead me to this answer on SO https://stackoverflow.com/a/10427757/261682 about overriding window.alert
and I came up with the following code:
// Ignore `state` here but it essentially means I can access `eventEmitter` all over my app.
var EventEmitter = ('events')
state.eventEmitter = new EventEmitter()
state.eventEmitter.on = (function (original) {
return function (name, callback) {
console.log('On Called for %s', name)
original(name, callback)
}
})(state.eventEmitter.on)
This isn't working. The event isn't triggered at all and I don't see anything in the console.
What am I doing wrong?
Note: There are other ways for me to track my original issue down but I'm interested as to why my code above isn't working.