blob: 46706af26e079125e088be63f59605005734cbaf [file] [log] [blame]
'use strict'
class EmitterWrapper {
constructor (emitter) {
this.listeners = {}
this.emitter = emitter
}
addListener (event, listener) {
this.emitter.addListener(event, listener)
this.listeners[event] = this.listeners[event] || []
this.listeners[event].push(listener)
return this
}
on (event, listener) {
return this.addListener(event, listener)
}
removeAllListeners (event) {
const events = event ? [event] : Object.keys(this.listeners)
events.forEach((event) => {
this.listeners[event].forEach((listener) => {
this.emitter.removeListener(event, listener)
})
delete this.listeners[event]
})
return this
}
}
module.exports = EmitterWrapper