You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some modules use the internal _events object. It's not a good thing, and that probably means that EventEmitter is missing some API methods.
Also lib/_stream_readable.js uses the internal _events object of lib/events.js, which is ok, but not very nice. What makes that a bit worse is that lib/_stream_readable.js is also packaged as an external readable-stream module.
for (event in this.ee._events) { if (this.ee._events.hasOwnProperty(event)) {
It looks to me that there should be methods in EventEmitter to:
Get a list of all events from an EventEmmiter that currently have listeners. This is what ultron module does, and I do not see an API for that. Getting a list of events could also be usable for debugging.
(optional) Check if there are any listeners for a specific event. Like EventEmitter.listenerCount but using a prototype, like EventEmitter.prototype.listeners but returning just the count. This is what seems to be most commonly used.
It has a valid API EventEmitter.listenerCount, but why isn't it inside the prototype? That makes it a bit harder to find and that could be the reason behind modules using this._events.whatever to count (or check the presense of) the event listeners.
Moved from #1785 (comment)
Some modules use the internal
_eventsobject. It's not a good thing, and that probably means thatEventEmitteris missing some API methods.Also
lib/_stream_readable.jsuses the internal_eventsobject oflib/events.js, which is ok, but not very nice. What makes that a bit worse is thatlib/_stream_readable.jsis also packaged as an externalreadable-streammodule.Samples of
_eventsusage:if (!dest._events || !dest._events.error)else if (isArray(dest._events.error))dest._events.error.unshift(onerror);dest._events.error = [onerror, dest._events.error];if (this._events.preamble)if ((start + i) < end && this._events.trailer)if (this._events[ev])if (!boy._events.file) {for (event in this.ee._events) { if (this.ee._events.hasOwnProperty(event)) {It looks to me that there should be methods in
EventEmitterto:Get a list of all events from an
EventEmmiterthat currently have listeners. This is whatultronmodule does, and I do not see an API for that. Getting a list of events could also be usable for debugging.Implemented by @jasnell in events: add eventNames() method #5617, will be available in 6.0.
(optional) Check if there are any listeners for a specific event. Like
EventEmitter.listenerCountbut using a prototype, likeEventEmitter.prototype.listenersbut returning just the count. This is what seems to be most commonly used.It has a valid API
EventEmitter.listenerCount, but why isn't it inside the prototype? That makes it a bit harder to find and that could be the reason behind modules usingthis._events.whateverto count (or check the presense of) the event listeners.That's since 75305f3. @trevnorris
Solved by events: deprecate static listenerCount function #2349.
(optional) To prepend an event. Does the documentation specify the order in which the events are executed, btw?
This is what the internal
lib/_stream_readable.jsand thereadable-streammodule do.Implemented by @jasnell in events: add ability to prepend event listeners #6032.