summaryrefslogtreecommitdiff
path: root/doc/api/events.md
diff options
context:
space:
mode:
authorAnatoli Papirovski <apapirovski@mac.com>2017-11-25 13:26:28 -0500
committerAnatoli Papirovski <apapirovski@mac.com>2017-12-14 08:43:00 -0500
commitdecab712ba14b8ec577025a57b8ab460fd3b8ec5 (patch)
tree0899c36bdbeed5fc9cea552e109f9081548f9c94 /doc/api/events.md
parente24ad97832979b945ccb2af6e2cf67caf7524cb1 (diff)
downloadandroid-node-v8-decab712ba14b8ec577025a57b8ab460fd3b8ec5.tar.gz
android-node-v8-decab712ba14b8ec577025a57b8ab460fd3b8ec5.tar.bz2
android-node-v8-decab712ba14b8ec577025a57b8ab460fd3b8ec5.zip
events: remove reaches into _events internals
Refactor lib & src code to eliminate all deep reaches into the internal _events dictionary object, instead use available APIs and add an extra method to EventEmitter: rawListeners. PR-URL: https://github.com/nodejs/node/pull/17440 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'doc/api/events.md')
-rw-r--r--doc/api/events.md33
1 files changed, 33 insertions, 0 deletions
diff --git a/doc/api/events.md b/doc/api/events.md
index 8eaa8cae10..c935b7de0f 100644
--- a/doc/api/events.md
+++ b/doc/api/events.md
@@ -574,6 +574,39 @@ to indicate an unlimited number of listeners.
Returns a reference to the `EventEmitter`, so that calls can be chained.
+### emitter.rawListeners(eventName)
+<!-- YAML
+added: REPLACEME
+-->
+- `eventName` {any}
+
+Returns a copy of the array of listeners for the event named `eventName`,
+including any wrappers (such as those created by `.once`).
+
+```js
+const emitter = new EventEmitter();
+emitter.once('log', () => console.log('log once'));
+
+// Returns a new Array with a function `onceWrapper` which has a property
+// `listener` which contains the original listener bound above
+const listeners = emitter.rawListeners('log');
+const logFnWrapper = listeners[0];
+
+// logs "log once" to the console and does not unbind the `once` event
+logFnWrapper.listener();
+
+// logs "log once" to the console and removes the listener
+logFnWrapper();
+
+emitter.on('log', () => console.log('log persistently'));
+// will return a new Array with a single function bound by `on` above
+const newListeners = emitter.rawListeners('log');
+
+// logs "log persistently" twice
+newListeners[0]();
+emitter.emit('log');
+```
+
[`--trace-warnings`]: cli.html#cli_trace_warnings
[`EventEmitter.defaultMaxListeners`]: #events_eventemitter_defaultmaxlisteners
[`domain`]: domain.html