event-registry
Keeps track of EventEmitter listeners and automatically removes them upon selected events. Useful when you want to avoid EventEmitter memory leaks caused by listeners not being removed.
Usage
const EventRegistry = const eventRegistry = const emitter = const otherEmitter = // Attach a listener using EventEmitter.prototype.on and remember it.eventRegistry // Attach a one-off listener using EventEmitter.prototype.on and remember it.eventRegistry // A single registry can track any number of event emitters.eventRegistry // When the 'end' event is emitted, remove all remembered listeners.// Note that this will also remove the progress listener from otherEmitter.eventRegistry
API
EventEmitter Proxies
An EventRegistry
proxies the following functions to the emitter
:
addListener(emitter, event, listener)
AKAon(emitter, event, listener)
once(emitter, event, listener)
removeListener(emitter, event, listener)
removeAllListeners(emitter, [event])
Additionally, it keeps track of every listener
passed. When a final event
occurs (see below), it will remove all of these listeners.
Final Events
fin(emitter, event)
Marks the given event
on the emitter
as final. When that event occurs, all
listeners will be removed.
unfin(emitter, event)
Undoes a call to fin
. Marks the event
on the emitter
as non-final.
onceFin(emitter, event, listener)
Shorthand for once(emitter, event, listener)
followed by fin(emitter, event)
.
Saves you a statement in this common scenario.
clear()
Removes all attached listeners and marks all final events as non-final. Basically what happens when a final event is emitted.
Author
License
MIT