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-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"; | 18 "use strict"; |
19 | 19 |
20 /** | 20 /** |
21 * @fileOverview This component manages listeners and calls them to distributes | 21 * @fileOverview This component manages listeners and calls them to distributes |
22 * messages about filter changes. | 22 * messages about filter changes. |
23 */ | 23 */ |
24 | 24 |
25 let {EventEmitter} = require("events"); | 25 const {EventEmitter} = require("events"); |
26 let {desc} = require("coreUtils"); | 26 const {desc} = require("coreUtils"); |
27 | 27 |
28 const CATCH_ALL = "__all"; | 28 const CATCH_ALL = "__all"; |
29 | 29 |
30 /** | 30 /** |
31 * @callback FilterNotifierOnListener | 31 * @callback FilterNotifierCatchAllListener |
32 * @param {String} action | 32 * @param {string} action |
33 * @param {Subscription|Filter} item | 33 * @param {Subscription|Filter} item |
34 * @param {any} newValue | 34 * @param {...*} additionalInfo |
35 * @param {any} oldValue | |
36 */ | 35 */ |
37 | 36 |
38 /** | 37 /** |
39 * This class allows registering and triggering listeners for filter events. | 38 * This class allows registering and triggering listeners for filter events. |
40 * @class | 39 * @class |
41 */ | 40 */ |
42 exports.FilterNotifier = Object.create(new EventEmitter(), desc({ | 41 exports.FilterNotifier = Object.create(new EventEmitter(), desc({ |
43 /** | 42 /** |
44 * Adds a listener | 43 * Adds a listener |
45 * | 44 * |
46 * @deprecated use FilterNotifier.on(action, callback) | 45 * @deprecated use FilterNotifier.on(action, callback) |
47 * @param {FilterNotifierOnListener} listener | 46 * @param {FilterNotifierCatchAllListener} listener |
48 */ | 47 */ |
49 addListener(listener) | 48 addListener(listener) |
50 { | 49 { |
51 let listeners = this._listeners[CATCH_ALL]; | 50 let listeners = this._listeners[CATCH_ALL]; |
52 if (!listeners || listeners.indexOf(listener) == -1) | 51 if (!listeners || listeners.indexOf(listener) == -1) |
53 this.on(CATCH_ALL, listener); | 52 this.on(CATCH_ALL, listener); |
54 }, | 53 }, |
55 | 54 |
56 /** | 55 /** |
57 * Removes a listener that was previosly added via addListener | 56 * Removes a listener that was previosly added via addListener |
58 * | 57 * |
59 * @deprecated use FilterNotifier.off(action, callback) | 58 * @deprecated use FilterNotifier.off(action, callback) |
60 * @param {FilterNotifierOnListener} listener | 59 * @param {FilterNotifierCatchAllListener} listener |
61 */ | 60 */ |
62 removeListener(listener) | 61 removeListener(listener) |
63 { | 62 { |
64 this.off(CATCH_ALL, listener); | 63 this.off(CATCH_ALL, listener); |
65 }, | 64 }, |
66 | 65 |
67 /** | 66 /** |
68 * Notifies listeners about an event | 67 * Notifies listeners about an event |
69 * @param {String} action event code ("load", "save", "elemhideupdate", | 68 * @param {string} action event code ("load", "save", "elemhideupdate", |
70 * "subscription.added", "subscription.removed", | 69 * "subscription.added", "subscription.removed", |
71 * "subscription.disabled", "subscription.title", | 70 * "subscription.disabled", "subscription.title", |
72 * "subscription.lastDownload", "subscription.downloadStatus", | 71 * "subscription.lastDownload", "subscription.downloadStatus", |
73 * "subscription.homepage", "subscription.updated", | 72 * "subscription.homepage", "subscription.updated", |
74 * "filter.added", "filter.removed", "filter.moved", | 73 * "filter.added", "filter.removed", "filter.moved", |
75 * "filter.disabled", "filter.hitCount", "filter.lastHit") | 74 * "filter.disabled", "filter.hitCount", "filter.lastHit") |
76 * @param {Subscription|Filter} item item that the change applies to | 75 * @param {Subscription|Filter} item item that the change applies to |
77 * @param {any} param1 | 76 * @param {*} param1 |
78 * @param {any} param2 | 77 * @param {*} param2 |
79 * @param {any} param3 | 78 * @param {*} param3 |
80 * @deprecated use FilterNotifier.emit(action) | 79 * @deprecated use FilterNotifier.emit(action) |
81 */ | 80 */ |
82 triggerListeners(action, item, param1, param2, param3) | 81 triggerListeners(action, item, param1, param2, param3) |
83 { | 82 { |
84 this.emit(action, item, param1, param2, param3); | 83 this.emit(action, item, param1, param2, param3); |
85 this.emit(CATCH_ALL, action, item, param1, param2, param3); | 84 this.emit(CATCH_ALL, action, item, param1, param2, param3); |
86 } | 85 } |
87 })); | 86 })); |
LEFT | RIGHT |