Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 18 matching lines...) Expand all Loading... | |
29 | 29 |
30 exports.EventEmitter.prototype = { | 30 exports.EventEmitter.prototype = { |
31 /** | 31 /** |
32 * Adds a listener for the specified event name. | 32 * Adds a listener for the specified event name. |
33 * | 33 * |
34 * @param {string} name | 34 * @param {string} name |
35 * @param {function} listener | 35 * @param {function} listener |
36 */ | 36 */ |
37 on(name, listener) | 37 on(name, listener) |
38 { | 38 { |
39 if (this._listeners.has(name)) | 39 let listeners = this._listeners.get(name); |
Manish Jethani
2018/04/01 08:44:16
It's usually not worth calling Map.has if you're g
kzar
2018/04/03 17:27:55
Done.
| |
40 this._listeners.get(name).push(listener); | 40 if (listeners) |
41 listeners.push(listener); | |
41 else | 42 else |
42 this._listeners.set(name, [listener]); | 43 this._listeners.set(name, [listener]); |
43 }, | 44 }, |
44 | 45 |
45 /** | 46 /** |
46 * Removes a listener for the specified event name. | 47 * Removes a listener for the specified event name. |
47 * | 48 * |
48 * @param {string} name | 49 * @param {string} name |
49 * @param {function} listener | 50 * @param {function} listener |
50 */ | 51 */ |
51 off(name, listener) | 52 off(name, listener) |
52 { | 53 { |
53 let listeners = this._listeners.get(name); | 54 let listeners = this._listeners.get(name); |
Manish Jethani
2018/04/01 08:44:16
While we're at it, perhaps it would be a good idea
kzar
2018/04/03 17:27:55
Good idea, but I'd rather not since this would cha
Sebastian Noack
2018/04/03 20:42:34
What change of behavior are you concerned about? M
Manish Jethani
2018/04/04 06:54:49
Dave has a point that this would be more likely to
| |
54 if (listeners) | 55 if (listeners) |
55 { | 56 { |
56 let idx = listeners.indexOf(listener); | 57 let idx = listeners.indexOf(listener); |
57 if (idx != -1) | 58 if (idx != -1) |
58 listeners.splice(idx, 1); | 59 listeners.splice(idx, 1); |
59 } | 60 } |
60 }, | 61 }, |
61 | 62 |
62 /** | 63 /** |
63 * Adds a one time listener and returns a promise that | 64 * Adds a one time listener and returns a promise that |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 * @param {string} name | 98 * @param {string} name |
98 * @param {...*} [arg] | 99 * @param {...*} [arg] |
99 */ | 100 */ |
100 emit(name, ...args) | 101 emit(name, ...args) |
101 { | 102 { |
102 let listeners = this.listeners(name); | 103 let listeners = this.listeners(name); |
103 for (let listener of listeners) | 104 for (let listener of listeners) |
104 listener(...args); | 105 listener(...args); |
105 } | 106 } |
106 }; | 107 }; |
LEFT | RIGHT |