Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 65b1045

Browse files
tflanaganrvagg
authored andcommittedDec 4, 2015
doc: sort events alphabetically
Reorders, with minimal contextual duplication, the events documentation alphabetically. PR-URL: #3662 Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 17d1ee8 commit 65b1045

File tree

1 file changed

+89
-91
lines changed

1 file changed

+89
-91
lines changed
 

‎doc/api/events.markdown

+89-91
Original file line numberDiff line numberDiff line change
@@ -36,67 +36,68 @@ a stack trace and exit the program.
3636
All EventEmitters emit the event `'newListener'` when new listeners are
3737
added and `'removeListener'` when a listener is removed.
3838

39-
### emitter.addListener(event, listener)
40-
### emitter.on(event, listener)
39+
### Inheriting from 'EventEmitter'
4140

42-
Adds a listener to the end of the listeners array for the specified `event`.
43-
No checks are made to see if the `listener` has already been added. Multiple
44-
calls passing the same combination of `event` and `listener` will result in the
45-
`listener` being added multiple times.
41+
Inheriting from `EventEmitter` is no different from inheriting from any other
42+
constructor function. For example:
4643

47-
server.on('connection', function (stream) {
48-
console.log('someone connected!');
49-
});
44+
'use strict';
45+
const util = require('util');
46+
const EventEmitter = require('events');
5047

51-
Returns emitter, so calls can be chained.
48+
function MyEventEmitter() {
49+
// Initialize necessary properties from `EventEmitter` in this instance
50+
EventEmitter.call(this);
51+
}
5252

53-
### emitter.once(event, listener)
53+
// Inherit functions from `EventEmitter`'s prototype
54+
util.inherits(MyEventEmitter, EventEmitter);
5455

55-
Adds a **one time** listener for the event. This listener is
56-
invoked only the next time the event is fired, after which
57-
it is removed.
56+
### Class Method: EventEmitter.listenerCount(emitter, event)
5857

59-
server.once('connection', function (stream) {
60-
console.log('Ah, we have our first user!');
61-
});
58+
Stability: 0 - Deprecated: Use [emitter.listenerCount][] instead.
6259

63-
Returns emitter, so calls can be chained.
60+
Returns the number of listeners for a given event.
6461

65-
### emitter.removeListener(event, listener)
62+
### Event: 'newListener'
6663

67-
Removes a listener from the listener array for the specified event.
68-
**Caution**: changes array indices in the listener array behind the listener.
64+
* `event` {String} The event name
65+
* `listener` {Function} The event handler function
6966

70-
var callback = function(stream) {
71-
console.log('someone connected!');
72-
};
73-
server.on('connection', callback);
74-
// ...
75-
server.removeListener('connection', callback);
67+
This event is emitted *before* a listener is added. When this event is
68+
triggered, the listener has not been added to the array of listeners for the
69+
`event`. Any listeners added to the event `name` in the newListener event
70+
callback will be added *before* the listener that is in the process of being
71+
added.
7672

77-
`removeListener` will remove, at most, one instance of a listener from the
78-
listener array. If any single listener has been added multiple times to the
79-
listener array for the specified `event`, then `removeListener` must be called
80-
multiple times to remove each instance.
73+
### Event: 'removeListener'
8174

82-
Returns emitter, so calls can be chained.
75+
* `event` {String} The event name
76+
* `listener` {Function} The event handler function
8377

84-
### emitter.removeAllListeners([event])
78+
This event is emitted *after* a listener is removed. When this event is
79+
triggered, the listener has been removed from the array of listeners for the
80+
`event`.
8581

86-
Removes all listeners, or those of the specified event. It's not a good idea to
87-
remove listeners that were added elsewhere in the code, especially when it's on
88-
an emitter that you didn't create (e.g. sockets or file streams).
82+
### EventEmitter.defaultMaxListeners
8983

90-
Returns emitter, so calls can be chained.
84+
[`emitter.setMaxListeners(n)`](#events_emitter_setmaxlisteners_n) sets the
85+
maximum on a per-instance basis.
86+
This class property lets you set it for *all* `EventEmitter` instances,
87+
current and future, effective immediately. Use with care.
9188

92-
### emitter.setMaxListeners(n)
89+
Note that [`emitter.setMaxListeners(n)`](#events_emitter_setmaxlisteners_n)
90+
still has precedence over `EventEmitter.defaultMaxListeners`.
9391

94-
By default EventEmitters will print a warning if more than 10 listeners are
95-
added for a particular event. This is a useful default which helps finding
96-
memory leaks. Obviously not all Emitters should be limited to 10. This function
97-
allows that to be increased. Set to `Infinity` (or `0`) for unlimited.
92+
### emitter.addListener(event, listener)
9893

99-
Returns emitter, so calls can be chained.
94+
Alias for `emitter.on(event, listener)`.
95+
96+
### emitter.emit(event[, arg1][, arg2][, ...])
97+
98+
Calls each of the listeners in order with the supplied arguments.
99+
100+
Returns `true` if event had listeners, `false` otherwise.
100101

101102
### emitter.getMaxListeners()
102103

@@ -113,16 +114,11 @@ while not being irresponsible and setting a too big number.
113114
emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));
114115
});
115116

116-
### EventEmitter.defaultMaxListeners
117-
118-
[`emitter.setMaxListeners(n)`](#events_emitter_setmaxlisteners_n) sets the
119-
maximum on a per-instance basis.
120-
This class property lets you set it for *all* `EventEmitter` instances,
121-
current and future, effective immediately. Use with care.
117+
### emitter.listenerCount(type)
122118

123-
Note that [`emitter.setMaxListeners(n)`](#events_emitter_setmaxlisteners_n)
124-
still has precedence over `EventEmitter.defaultMaxListeners`.
119+
* `type` {Value} The type of event
125120

121+
Returns the number of listeners listening to the `type` of event.
126122

127123
### emitter.listeners(event)
128124

@@ -133,63 +129,65 @@ Returns a copy of the array of listeners for the specified event.
133129
});
134130
console.log(util.inspect(server.listeners('connection'))); // [ [Function] ]
135131

132+
### emitter.on(event, listener)
136133

137-
### emitter.emit(event[, arg1][, arg2][, ...])
138-
139-
Calls each of the listeners in order with the supplied arguments.
140-
141-
Returns `true` if event had listeners, `false` otherwise.
142-
143-
144-
### emitter.listenerCount(type)
145-
146-
* `type` {Value} The type of event
134+
Adds a listener to the end of the listeners array for the specified `event`.
135+
No checks are made to see if the `listener` has already been added. Multiple
136+
calls passing the same combination of `event` and `listener` will result in the
137+
`listener` being added multiple times.
147138

148-
Returns the number of listeners listening to the `type` of event.
139+
server.on('connection', function (stream) {
140+
console.log('someone connected!');
141+
});
149142

150-
### Class Method: EventEmitter.listenerCount(emitter, event)
143+
Returns emitter, so calls can be chained.
151144

152-
Stability: 0 - Deprecated: Use [emitter.listenerCount][] instead.
145+
### emitter.once(event, listener)
153146

154-
Returns the number of listeners for a given event.
147+
Adds a **one time** listener for the event. This listener is
148+
invoked only the next time the event is fired, after which
149+
it is removed.
155150

156-
### Event: 'newListener'
151+
server.once('connection', function (stream) {
152+
console.log('Ah, we have our first user!');
153+
});
157154

158-
* `event` {String} The event name
159-
* `listener` {Function} The event handler function
155+
Returns emitter, so calls can be chained.
160156

161-
This event is emitted *before* a listener is added. When this event is
162-
triggered, the listener has not been added to the array of listeners for the
163-
`event`. Any listeners added to the event `name` in the newListener event
164-
callback will be added *before* the listener that is in the process of being
165-
added.
157+
### emitter.removeAllListeners([event])
166158

159+
Removes all listeners, or those of the specified event. It's not a good idea to
160+
remove listeners that were added elsewhere in the code, especially when it's on
161+
an emitter that you didn't create (e.g. sockets or file streams).
167162

168-
### Event: 'removeListener'
163+
Returns emitter, so calls can be chained.
169164

170-
* `event` {String} The event name
171-
* `listener` {Function} The event handler function
165+
### emitter.removeListener(event, listener)
172166

173-
This event is emitted *after* a listener is removed. When this event is
174-
triggered, the listener has been removed from the array of listeners for the
175-
`event`.
167+
Removes a listener from the listener array for the specified event.
168+
**Caution**: changes array indices in the listener array behind the listener.
176169

177-
### Inheriting from 'EventEmitter'
170+
var callback = function(stream) {
171+
console.log('someone connected!');
172+
};
173+
server.on('connection', callback);
174+
// ...
175+
server.removeListener('connection', callback);
178176

179-
Inheriting from `EventEmitter` is no different from inheriting from any other
180-
constructor function. For example:
177+
`removeListener` will remove, at most, one instance of a listener from the
178+
listener array. If any single listener has been added multiple times to the
179+
listener array for the specified `event`, then `removeListener` must be called
180+
multiple times to remove each instance.
181181

182-
'use strict';
183-
const util = require('util');
184-
const EventEmitter = require('events');
182+
Returns emitter, so calls can be chained.
185183

186-
function MyEventEmitter() {
187-
// Initialize necessary properties from `EventEmitter` in this instance
188-
EventEmitter.call(this);
189-
}
184+
### emitter.setMaxListeners(n)
190185

191-
// Inherit functions from `EventEmitter`'s prototype
192-
util.inherits(MyEventEmitter, EventEmitter);
186+
By default EventEmitters will print a warning if more than 10 listeners are
187+
added for a particular event. This is a useful default which helps finding
188+
memory leaks. Obviously not all Emitters should be limited to 10. This function
189+
allows that to be increased. Set to `Infinity` (or `0`) for unlimited.
193190

191+
Returns emitter, so calls can be chained.
194192

195193
[emitter.listenerCount]: #events_emitter_listenercount_type

0 commit comments

Comments
 (0)
Please sign in to comment.