{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/io.js/issues/1817","labels_url":"https://api.github.com/repos/nodejs/io.js/issues/1817/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/io.js/issues/1817/comments","events_url":"https://api.github.com/repos/nodejs/io.js/issues/1817/events","html_url":"https://github.com/nodejs/io.js/issues/1817","id":81625158,"number":1817,"title":"EventEmitter API","user":{"login":"ChALkeR","id":291301,"avatar_url":"https://avatars.githubusercontent.com/u/291301?v=3","gravatar_id":"","url":"https://api.github.com/users/ChALkeR","html_url":"https://github.com/ChALkeR","followers_url":"https://api.github.com/users/ChALkeR/followers","following_url":"https://api.github.com/users/ChALkeR/following{/other_user}","gists_url":"https://api.github.com/users/ChALkeR/gists{/gist_id}","starred_url":"https://api.github.com/users/ChALkeR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChALkeR/subscriptions","organizations_url":"https://api.github.com/users/ChALkeR/orgs","repos_url":"https://api.github.com/users/ChALkeR/repos","events_url":"https://api.github.com/users/ChALkeR/events{/privacy}","received_events_url":"https://api.github.com/users/ChALkeR/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nodejs/io.js/labels/events","name":"events","color":"bfdadc"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":19,"created_at":"2015-05-27T21:06:54Z","updated_at":"2015-05-28T11:40:35Z","closed_at":null,"body":"*Moved from https://github.com/nodejs/io.js/pull/1785#issuecomment-105223952*\r\n\r\nSome modules use the internal `_events` object. It's not a good thing, and that probably means that `EventEmitter` is missing some API methods.\r\n\r\nAlso `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.\r\n\r\nSamples of `_events` usage:\r\n* [readable-stream](https://github.com/nodejs/readable-stream)/lib/[_stream_readable.js](https://github.com/nodejs/readable-stream/blob/master/lib/_stream_readable.js#L576):\r\n 1. ```if (!dest._events || !dest._events.error)```\r\n 2. ```else if (isArray(dest._events.error))```\r\n 3. ```dest._events.error.unshift(onerror);```\r\n 4. ```dest._events.error = [onerror, dest._events.error];```\r\n* [dicer](https://github.com/mscdex/dicer)/lib/[Dicer.js](https://github.com/mscdex/dicer/blob/master/lib/Dicer.js#L91):\r\n 1. ```if (this._events.preamble)```\r\n 2. ```if ((start + i) < end && this._events.trailer)```\r\n 3. ```if (this._events[ev])```\r\n* [busboy](https://github.com/mscdex/busboy)/lib/types/[multipart.js](https://github.com/mscdex/busboy/blob/master/lib/types/multipart.js#L183):\r\n 1. ```if (!boy._events.file) {```\r\n* [ultron](https://github.com/unshiftio/ultron)/[index.js](https://github.com/unshiftio/ultron/blob/master/index.js#L79):\r\n 1. ```for (event in this.ee._events) { if (this.ee._events.hasOwnProperty(event)) {```\r\n\r\nIt looks to me that there should be methods in `EventEmitter` to:\r\n 1. 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.\r\n 2. *(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.\r\n\r\n 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. \r\n\r\n That's since 75305f3babd9e927e92b0d9b70d8bb026492ebd0. @trevnorris \r\n 3. *(optional)* To prepend an event. Does the documentation specify the order in which the events are executed, btw?\r\n\r\n This is what the internal `lib/_stream_readable.js` and the `readable-stream` module do.\r\n"},"comment":{"url":"https://api.github.com/repos/nodejs/io.js/issues/comments/106286185","html_url":"https://github.com/nodejs/io.js/issues/1817#issuecomment-106286185","issue_url":"https://api.github.com/repos/nodejs/io.js/issues/1817","id":106286185,"user":{"login":"ChALkeR","id":291301,"avatar_url":"https://avatars.githubusercontent.com/u/291301?v=3","gravatar_id":"","url":"https://api.github.com/users/ChALkeR","html_url":"https://github.com/ChALkeR","followers_url":"https://api.github.com/users/ChALkeR/followers","following_url":"https://api.github.com/users/ChALkeR/following{/other_user}","gists_url":"https://api.github.com/users/ChALkeR/gists{/gist_id}","starred_url":"https://api.github.com/users/ChALkeR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChALkeR/subscriptions","organizations_url":"https://api.github.com/users/ChALkeR/orgs","repos_url":"https://api.github.com/users/ChALkeR/repos","events_url":"https://api.github.com/users/ChALkeR/events{/privacy}","received_events_url":"https://api.github.com/users/ChALkeR/received_events","type":"User","site_admin":false},"created_at":"2015-05-28T11:40:35Z","updated_at":"2015-05-28T11:40:35Z","body":"@3rd-Eden Alternatives?"}}