From 769f63ccd8437045af5ddf1f418c53d2319597ed Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Thu, 21 Jul 2016 15:58:56 +0200 Subject: [PATCH] doc: add `added:` information for events PR-URL: https://github.com/nodejs/node/pull/7822 Reviewed-By: James M Snell Reviewed-By: Brian White --- doc/api/events.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/doc/api/events.md b/doc/api/events.md index 32198fa5194f9c..eab0bef17ed199 100644 --- a/doc/api/events.md +++ b/doc/api/events.md @@ -167,6 +167,9 @@ myEmitter.emit('error', new Error('whoops!')); ``` ## Class: EventEmitter + The `EventEmitter` class is defined and exposed by the `events` module: @@ -178,6 +181,9 @@ All EventEmitters emit the event `'newListener'` when new listeners are added and `'removeListener'` when existing listeners are removed. ### Event: 'newListener' + * `eventName` {String|Symbol} The name of the event being listened for * `listener` {Function} The event handler function @@ -214,6 +220,9 @@ myEmitter.emit('event'); ``` ### Event: 'removeListener' + * `eventName` {String|Symbol} The event name * `listener` {Function} The event handler function @@ -221,6 +230,10 @@ myEmitter.emit('event'); The `'removeListener'` event is emitted *after* the `listener` is removed. ### EventEmitter.listenerCount(emitter, eventName) + > Stability: 0 - Deprecated: Use [`emitter.listenerCount()`][] instead. @@ -236,6 +249,9 @@ console.log(EventEmitter.listenerCount(myEmitter, 'event')); ``` ### EventEmitter.defaultMaxListeners + By default, a maximum of `10` listeners can be registered for any single event. This limit can be changed for individual `EventEmitter` instances @@ -263,10 +279,16 @@ emitter.once('event', () => { ``` ### emitter.addListener(eventName, listener) + Alias for `emitter.on(eventName, listener)`. ### emitter.emit(eventName[, arg1][, arg2][, ...]) + Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments @@ -275,6 +297,9 @@ to each. Returns `true` if the event had listeners, `false` otherwise. ### emitter.eventNames() + Returns an array listing the events for which the emitter has registered listeners. The values in the array will be strings or Symbols. @@ -293,18 +318,27 @@ console.log(myEE.eventNames()); ``` ### emitter.getMaxListeners() + Returns the current max listener value for the `EventEmitter` which is either set by [`emitter.setMaxListeners(n)`][] or defaults to [`EventEmitter.defaultMaxListeners`][]. ### emitter.listenerCount(eventName) + * `eventName` {String|Symbol} The name of the event being listened for Returns the number of listeners listening to the event named `eventName`. ### emitter.listeners(eventName) + Returns a copy of the array of listeners for the event named `eventName`. @@ -317,6 +351,9 @@ console.log(util.inspect(server.listeners('connection'))); ``` ### emitter.on(eventName, listener) + * `eventName` {String|Symbol} The name of the event. * `listener` {Function} The callback function @@ -350,6 +387,9 @@ myEE.emit('foo'); ``` ### emitter.once(eventName, listener) + * `eventName` {String|Symbol} The name of the event. * `listener` {Function} The callback function @@ -380,6 +420,9 @@ myEE.emit('foo'); ``` ### emitter.prependListener(eventName, listener) + * `eventName` {String|Symbol} The name of the event. * `listener` {Function} The callback function @@ -399,6 +442,9 @@ server.prependListener('connection', (stream) => { Returns a reference to the `EventEmitter`, so that calls can be chained. ### emitter.prependOnceListener(eventName, listener) + * `eventName` {String|Symbol} The name of the event. * `listener` {Function} The callback function @@ -416,6 +462,9 @@ server.prependOnceListener('connection', (stream) => { Returns a reference to the `EventEmitter`, so that calls can be chained. ### emitter.removeAllListeners([eventName]) + Removes all listeners, or those of the specified `eventName`. @@ -426,6 +475,9 @@ component or module (e.g. sockets or file streams). Returns a reference to the `EventEmitter`, so that calls can be chained. ### emitter.removeListener(eventName, listener) + Removes the specified `listener` from the listener array for the event named `eventName`. @@ -490,6 +542,9 @@ the `emitter.listeners()` method will need to be recreated. Returns a reference to the `EventEmitter`, so that calls can be chained. ### emitter.setMaxListeners(n) + By default EventEmitters will print a warning if more than `10` listeners are added for a particular event. This is a useful default that helps finding