Skip to content
This repository was archived by the owner on May 17, 2021. It is now read-only.

Commit 4ad612d

Browse files
committed
Merge branch 'release/4.2.8'
2 parents 2a8307a + 09aed18 commit 4ad612d

7 files changed

+45
-59
lines changed

EventEmitter.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* EventEmitter v4.2.7 - git.io/ee
2+
* EventEmitter v4.2.8 - git.io/ee
33
* Oliver Caldwell
44
* MIT license
55
* @preserve
@@ -22,7 +22,7 @@
2222
var originalGlobalValue = exports.EventEmitter;
2323

2424
/**
25-
* Finds the index of the listener for the event in it's storage array.
25+
* Finds the index of the listener for the event in its storage array.
2626
*
2727
* @param {Function[]} listeners Array of listeners to search through.
2828
* @param {Function} listener Method to look for.
@@ -153,7 +153,7 @@
153153

154154
/**
155155
* Semi-alias of addListener. It will add a listener that will be
156-
* automatically removed after it's first execution.
156+
* automatically removed after its first execution.
157157
*
158158
* @param {String|RegExp} evt Name of the event to attach the listener to.
159159
* @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
@@ -275,7 +275,7 @@
275275
var single = remove ? this.removeListener : this.addListener;
276276
var multiple = remove ? this.removeListeners : this.addListeners;
277277

278-
// If evt is an object then pass each of it's properties to this method
278+
// If evt is an object then pass each of its properties to this method
279279
if (typeof evt === 'object' && !(evt instanceof RegExp)) {
280280
for (i in evt) {
281281
if (evt.hasOwnProperty(i) && (value = evt[i])) {

EventEmitter.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "eventEmitter",
33
"description": "Event based JavaScript for the browser",
4-
"version": "4.2.7",
4+
"version": "4.2.8",
55
"main": [
66
"./EventEmitter.js"
77
],

component.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "eventEmitter",
33
"repo": "Wolfy87/EventEmitter",
44
"description": "Event based JavaScript for the browser.",
5-
"version": "4.2.7",
5+
"version": "4.2.8",
66
"scripts": ["EventEmitter.js"],
77
"main": "EventEmitter.js",
88
"license": "MIT"

docs/api.md

+16-39
Original file line numberDiff line numberDiff line change
@@ -9,148 +9,125 @@ You may also be interested in [the guide](https://github.com/Wolfy87/EventEmitte
99
<p>Class for managing events.<br />Can be extended to provide event functionality in other classes.</p>
1010

1111
* **class** - [object Object]
12-
1312
## getListeners
1413

1514
<p>Returns the listener array for the specified event.<br />Will initialise the event object and listener arrays if required.<br />Will return an object if you use a regex search. The object contains keys for each matched event. So /ba[rz]/ might return an object containing bar and baz. But only if you have either defined them with defineEvent or added some listeners to them.<br />Each property in the object response is an array of listener functions.</p>
1615

17-
* **param** (String | RegExp) _evt_ - Name of the event to return the listeners from.
18-
* **return** (Function[] | Object) - All listener functions for the event.
19-
16+
* **param** (StringRegExp) _evt_ - Name of the event to return the listeners from.
17+
* **return** (Function[]Object) - All listener functions for the event.
2018
## flattenListeners
2119

2220
<p>Takes a list of listener objects and flattens it into a list of listener functions.</p>
2321

2422
* **param** (Object[]) _listeners_ - Raw listener objects.
2523
* **return** (Function[]) - Just the listener functions.
26-
2724
## getListenersAsObject
2825

2926
<p>Fetches the requested listeners via getListeners but will always return the results inside an object. This is mainly for internal use but others may find it useful.</p>
3027

31-
* **param** (String | RegExp) _evt_ - Name of the event to return the listeners from.
28+
* **param** (StringRegExp) _evt_ - Name of the event to return the listeners from.
3229
* **return** (Object) - All listener functions for an event in an object.
33-
3430
## addListener
3531

3632
<p>Adds a listener function to the specified event.<br />The listener will not be added if it is a duplicate.<br />If the listener returns true then it will be removed after it is called.<br />If you pass a regular expression as the event name then the listener will be added to all events that match it.</p>
3733

38-
* **param** (String | RegExp) _evt_ - Name of the event to attach the listener to.
34+
* **param** (StringRegExp) _evt_ - Name of the event to attach the listener to.
3935
* **param** (Function) _listener_ - Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
4036
* **return** (Object) - Current instance of EventEmitter for chaining.
41-
4237
## on
4338

4439
<p>Alias of addListener</p>
4540

46-
4741
## addOnceListener
4842

49-
<p>Semi-alias of addListener. It will add a listener that will be<br />automatically removed after it's first execution.</p>
43+
<p>Semi-alias of addListener. It will add a listener that will be<br />automatically removed after its first execution.</p>
5044

51-
* **param** (String | RegExp) _evt_ - Name of the event to attach the listener to.
45+
* **param** (StringRegExp) _evt_ - Name of the event to attach the listener to.
5246
* **param** (Function) _listener_ - Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
5347
* **return** (Object) - Current instance of EventEmitter for chaining.
54-
5548
## once
5649

5750
<p>Alias of addOnceListener.</p>
5851

59-
6052
## defineEvent
6153

62-
<p>Defines an event name. This is required if you want to use a regex to add a listener to multiple events at once. If you don't do this then how do you expect it to know what event to add to? Should it just add to every possible match for a regex? No. That is scary and bad.<br />You need to tell it what event names should be matched by a regex.</p>
54+
<p>Defines an event name. This is required if you want to use a regex to add a listener to multiple events at once. If you don&#39;t do this then how do you expect it to know what event to add to? Should it just add to every possible match for a regex? No. That is scary and bad.<br />You need to tell it what event names should be matched by a regex.</p>
6355

6456
* **param** (String) _evt_ - Name of the event to create.
6557
* **return** (Object) - Current instance of EventEmitter for chaining.
66-
6758
## defineEvents
6859

6960
<p>Uses defineEvent to define multiple events.</p>
7061

7162
* **param** (String[]) _evts_ - An array of event names to define.
7263
* **return** (Object) - Current instance of EventEmitter for chaining.
73-
7464
## removeListener
7565

7666
<p>Removes a listener function from the specified event.<br />When passed a regular expression as the event name, it will remove the listener from all events that match it.</p>
7767

78-
* **param** (String | RegExp) _evt_ - Name of the event to remove the listener from.
68+
* **param** (StringRegExp) _evt_ - Name of the event to remove the listener from.
7969
* **param** (Function) _listener_ - Method to remove from the event.
8070
* **return** (Object) - Current instance of EventEmitter for chaining.
81-
8271
## off
8372

8473
<p>Alias of removeListener</p>
8574

86-
8775
## addListeners
8876

89-
<p>Adds listeners in bulk using the manipulateListeners method.<br />If you pass an object as the second argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added.<br />You can also pass it a regular expression to add the array of listeners to all events that match it.<br />Yeah, this function does quite a bit. That's probably a bad thing.</p>
77+
<p>Adds listeners in bulk using the manipulateListeners method.<br />If you pass an object as the second argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added.<br />You can also pass it a regular expression to add the array of listeners to all events that match it.<br />Yeah, this function does quite a bit. That&#39;s probably a bad thing.</p>
9078

91-
* **param** (String | Object | RegExp) _evt_ - An event name if you will pass an array of listeners next. An object if you wish to add to multiple events at once.
79+
* **param** (StringObjectRegExp) _evt_ - An event name if you will pass an array of listeners next. An object if you wish to add to multiple events at once.
9280
* **param** (Function[]) _[listeners]_ - An optional array of listener functions to add.
9381
* **return** (Object) - Current instance of EventEmitter for chaining.
94-
9582
## removeListeners
9683

9784
<p>Removes listeners in bulk using the manipulateListeners method.<br />If you pass an object as the second argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.<br />You can also pass it an event name and an array of listeners to be removed.<br />You can also pass it a regular expression to remove the listeners from all events that match it.</p>
9885

99-
* **param** (String | Object | RegExp) _evt_ - An event name if you will pass an array of listeners next. An object if you wish to remove from multiple events at once.
86+
* **param** (StringObjectRegExp) _evt_ - An event name if you will pass an array of listeners next. An object if you wish to remove from multiple events at once.
10087
* **param** (Function[]) _[listeners]_ - An optional array of listener functions to remove.
10188
* **return** (Object) - Current instance of EventEmitter for chaining.
102-
10389
## manipulateListeners
10490

10591
<p>Edits listeners in bulk. The addListeners and removeListeners methods both use this to do their job. You should really use those instead, this is a little lower level.<br />The first argument will determine if the listeners are removed (true) or added (false).<br />If you pass an object as the second argument you can add/remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.<br />You can also pass it an event name and an array of listeners to be added/removed.<br />You can also pass it a regular expression to manipulate the listeners of all events that match it.</p>
10692

10793
* **param** (Boolean) _remove_ - True if you want to remove listeners, false if you want to add.
108-
* **param** (String | Object | RegExp) _evt_ - An event name if you will pass an array of listeners next. An object if you wish to add/remove from multiple events at once.
94+
* **param** (StringObjectRegExp) _evt_ - An event name if you will pass an array of listeners next. An object if you wish to add/remove from multiple events at once.
10995
* **param** (Function[]) _[listeners]_ - An optional array of listener functions to add/remove.
11096
* **return** (Object) - Current instance of EventEmitter for chaining.
111-
11297
## removeEvent
11398

11499
<p>Removes all listeners from a specified event.<br />If you do not specify an event then all listeners will be removed.<br />That means every event will be emptied.<br />You can also pass a regex to remove all events that match it.</p>
115100

116-
* **param** (String | RegExp) _[evt]_ - Optional name of the event to remove all listeners for. Will remove from every event if not passed.
101+
* **param** (StringRegExp) _[evt]_ - Optional name of the event to remove all listeners for. Will remove from every event if not passed.
117102
* **return** (Object) - Current instance of EventEmitter for chaining.
118-
119103
## removeAllListeners
120104

121-
<p>Alias of removeEvent.</p>
122-
123-
<p>Added to mirror the node API.</p>
124-
105+
<p>Alias of removeEvent.</p><p>Added to mirror the node API.</p>
125106

126107
## emitEvent
127108

128109
<p>Emits an event of your choice.<br />When emitted, every listener attached to that event will be executed.<br />If you pass the optional argument array then those arguments will be passed to every listener upon execution.<br />Because it uses <code>apply</code>, your array of arguments will be passed as if you wrote them out separately.<br />So they will not arrive within the array on the other side, they will be separate.<br />You can also pass a regular expression to emit to all events that match it.</p>
129110

130-
* **param** (String | RegExp) _evt_ - Name of the event to emit and execute listeners for.
111+
* **param** (StringRegExp) _evt_ - Name of the event to emit and execute listeners for.
131112
* **param** (Array) _[args]_ - Optional array of arguments to be passed to each listener.
132113
* **return** (Object) - Current instance of EventEmitter for chaining.
133-
134114
## trigger
135115

136116
<p>Alias of emitEvent</p>
137117

138-
139118
## emit
140119

141120
<p>Subtly different from emitEvent in that it will pass its arguments on to the listeners, as opposed to taking a single array of arguments to pass on.<br />As with emitEvent, you can pass a regex in place of the event name to emit to all events that match it.</p>
142121

143-
* **param** (String | RegExp) _evt_ - Name of the event to emit and execute listeners for.
122+
* **param** (StringRegExp) _evt_ - Name of the event to emit and execute listeners for.
144123
* **param** (...*) _Optional_ - additional arguments to be passed to each listener.
145124
* **return** (Object) - Current instance of EventEmitter for chaining.
146-
147125
## setOnceReturnValue
148126

149127
<p>Sets the current value to check against when executing listeners. If a<br />listeners return value matches the one set here then it will be removed<br />after execution. This value defaults to true.</p>
150128

151129
* **param** (*) _value_ - The new value to check for when executing listeners.
152130
* **return** (Object) - Current instance of EventEmitter for chaining.
153-
154131
## noConflict
155132

156133
<p>Reverts the global {@link EventEmitter} to its previous value and returns a reference to this version.</p>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wolfy87-eventemitter",
3-
"version": "4.2.7",
3+
"version": "4.2.8",
44
"description": "Event based JavaScript for the browser",
55
"main": "EventEmitter.js",
66
"directories": {

tests/tests.js

+21-12
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444
});
4545
});
4646

47-
test('allows you to fetch listeners by regex', function ()
48-
{
47+
test('allows you to fetch listeners by regex', function () {
4948
var check = [];
5049

5150
ee.addListener('foo', function() { check.push(1); });
@@ -122,8 +121,7 @@
122121
assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn1, fn2]);
123122
});
124123

125-
test('allows you to add listeners by regex', function ()
126-
{
124+
test('allows you to add listeners by regex', function () {
127125
var check = [];
128126

129127
ee.defineEvents(['bar', 'baz']);
@@ -133,6 +131,21 @@
133131

134132
assert.strictEqual(flattenCheck(check), '2,2');
135133
});
134+
135+
test('prevents you from adding duplicate listeners', function () {
136+
var count = 0;
137+
138+
function adder() {
139+
count += 1;
140+
}
141+
142+
ee.addListener('foo', adder);
143+
ee.addListener('foo', adder);
144+
ee.addListener('foo', adder);
145+
ee.emitEvent('foo');
146+
147+
assert.strictEqual(count, 1);
148+
});
136149
});
137150

138151
suite('addOnceListener', function () {
@@ -351,8 +364,7 @@
351364
assert.deepEqual(ee.flattenListeners(ee.getListeners('baz')), []);
352365
});
353366

354-
test('removes listeners when passed a regex', function ()
355-
{
367+
test('removes listeners when passed a regex', function () {
356368
var check = [];
357369
ee.removeEvent();
358370

@@ -493,8 +505,7 @@
493505
assert.strictEqual(flattenCheck(check), '1,1,2,3,4,4,5,5,6');
494506
});
495507

496-
test('executes all listeners that match a regular expression', function ()
497-
{
508+
test('executes all listeners that match a regular expression', function () {
498509
var check = [];
499510

500511
ee.addListener('foo', function() { check.push(1); });
@@ -505,8 +516,7 @@
505516
assert.strictEqual(flattenCheck(check), '2,3');
506517
});
507518

508-
test('global object is defined', function()
509-
{
519+
test('global object is defined', function() {
510520
ee.addListener('foo', function() {
511521
assert.equal(this, ee);
512522
});
@@ -629,8 +639,7 @@
629639
assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn3, fn2, fn5]);
630640
});
631641

632-
test('allows you to add listeners by regex', function ()
633-
{
642+
test('allows you to add listeners by regex', function () {
634643
var check = [];
635644

636645
ee.defineEvents(['bar', 'baz']);

0 commit comments

Comments
 (0)