elistener
Usage
var EventEmitter = require('events').EventEmitter
var elistener = require('elistener')
var cat = new EventEmitter()
function Owner () {}
elistener.install(Owner.prototype)
var owner = new Owner()
owner.listenTo(cat, 'meow', feed)
cat.emit('meow')
cat.emit('meow')
cat.emit('meow')
cat.emit('meow')
cat.emit('meow')
cat.emit('meow')
function feed () {
console.log('fed cat')
owner.stopListening(cat, 'meow', feed)
owner.listenTo(cat, 'meow', pet)
}
function pet () {
console.log('petted cat')
owner.stopListening(cat, 'meow')
owner.listenTo(cat, 'meow', sell)
}
function sell () {
console.log('sold cat')
owner.stopListening(cat)
}
Methods
listenTo(emitter, event, handler)
listenOnce(emitter, event, handler)
stopListening([emitter, event, handler])