Left: | ||
Right: |
OLD | NEW |
---|---|
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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 "use strict"; | |
19 | |
18 /** | 20 /** |
19 * @fileOverview This component manages listeners and calls them to distributes | 21 * @fileOverview This component manages listeners and calls them to distributes |
20 * messages about filter changes. | 22 * messages about filter changes. |
21 */ | 23 */ |
22 | 24 |
23 let {EventEmitter} = require("events"); | 25 const {EventEmitter} = require("events"); |
24 let {desc} = require("coreUtils"); | 26 const {desc} = require("coreUtils"); |
25 | 27 |
26 const CATCH_ALL = "__all"; | 28 const CATCH_ALL = "__all"; |
27 | 29 |
28 /** | 30 /** |
31 * @callback FilterNotifierOnListener | |
Wladimir Palant
2017/03/02 14:06:52
This is a rather weird callback name. How about Fi
kzar
2017/03/08 12:33:38
Done.
| |
32 * @param {string} action | |
33 * @param {Subscription|Filter} item | |
34 * @param {*} newValue | |
35 * @param {*} oldValue | |
Wladimir Palant
2017/03/02 14:06:53
newValue and oldValue isn't really correct, it rat
kzar
2017/03/08 12:33:37
Done.
| |
36 */ | |
37 | |
38 /** | |
29 * This class allows registering and triggering listeners for filter events. | 39 * This class allows registering and triggering listeners for filter events. |
30 * @class | 40 * @class |
31 */ | 41 */ |
32 exports.FilterNotifier = Object.create(new EventEmitter(), desc({ | 42 exports.FilterNotifier = Object.create(new EventEmitter(), desc({ |
33 /** | 43 /** |
34 * Adds a listener | 44 * Adds a listener |
35 * | 45 * |
36 * @deprecated use FilterNotifier.on(action, callback) | 46 * @deprecated use FilterNotifier.on(action, callback) |
47 * @param {FilterNotifierOnListener} listener | |
37 */ | 48 */ |
38 addListener: function(/**function(action, item, newValue, oldValue)*/ listener ) | 49 addListener(listener) |
39 { | 50 { |
40 let listeners = this._listeners[CATCH_ALL]; | 51 let listeners = this._listeners[CATCH_ALL]; |
41 if (!listeners || listeners.indexOf(listener) == -1) | 52 if (!listeners || listeners.indexOf(listener) == -1) |
42 this.on(CATCH_ALL, listener); | 53 this.on(CATCH_ALL, listener); |
43 }, | 54 }, |
44 | 55 |
45 /** | 56 /** |
46 * Removes a listener that was previosly added via addListener | 57 * Removes a listener that was previosly added via addListener |
47 * | 58 * |
48 * @deprecated use FilterNotifier.off(action, callback) | 59 * @deprecated use FilterNotifier.off(action, callback) |
60 * @param {FilterNotifierOnListener} listener | |
49 */ | 61 */ |
50 removeListener: function(/**function(action, item, newValue, oldValue)*/ liste ner) | 62 removeListener(listener) |
51 { | 63 { |
52 this.off(CATCH_ALL, listener); | 64 this.off(CATCH_ALL, listener); |
53 }, | 65 }, |
54 | 66 |
55 /** | 67 /** |
56 * Notifies listeners about an event | 68 * Notifies listeners about an event |
57 * @param {String} action event code ("load", "save", "elemhideupdate", | 69 * @param {string} action event code ("load", "save", "elemhideupdate", |
58 * "subscription.added", "subscription.removed", | 70 * "subscription.added", "subscription.removed", |
59 * "subscription.disabled", "subscription.title", | 71 * "subscription.disabled", "subscription.title", |
60 * "subscription.lastDownload", "subscription.downloadStatus", | 72 * "subscription.lastDownload", "subscription.downloadStatus", |
61 * "subscription.homepage", "subscription.updated", | 73 * "subscription.homepage", "subscription.updated", |
62 * "filter.added", "filter.removed", "filter.moved", | 74 * "filter.added", "filter.removed", "filter.moved", |
63 * "filter.disabled", "filter.hitCount", "filter.lastHit") | 75 * "filter.disabled", "filter.hitCount", "filter.lastHit") |
64 * @param {Subscription|Filter} item item that the change applies to | 76 * @param {Subscription|Filter} item item that the change applies to |
77 * @param {*} param1 | |
78 * @param {*} param2 | |
79 * @param {*} param3 | |
Wladimir Palant
2017/03/02 14:06:53
Convert this to rest parameters?
kzar
2017/03/08 12:33:37
Mind if I don't for now?
| |
65 * @deprecated use FilterNotifier.emit(action) | 80 * @deprecated use FilterNotifier.emit(action) |
66 */ | 81 */ |
67 triggerListeners: function(action, item, param1, param2, param3) | 82 triggerListeners(action, item, param1, param2, param3) |
68 { | 83 { |
69 this.emit(action, item, param1, param2, param3); | 84 this.emit(action, item, param1, param2, param3); |
70 this.emit(CATCH_ALL, action, item, param1, param2, param3); | 85 this.emit(CATCH_ALL, action, item, param1, param2, param3); |
71 } | 86 } |
72 })); | 87 })); |
OLD | NEW |