OLD | NEW |
| 1 "use strict"; |
| 2 |
1 let listeners = []; | 3 let listeners = []; |
2 | 4 |
3 let Prefs = exports.Prefs = { | 5 let Prefs = exports.Prefs = { |
4 enabled: true, | 6 enabled: true, |
5 savestats: true, | 7 savestats: true, |
6 subscriptions_autoupdate: true, | 8 subscriptions_autoupdate: true, |
7 subscriptions_fallbackerrors: 5, | 9 subscriptions_fallbackerrors: 5, |
8 subscriptions_fallbackurl: "", | 10 subscriptions_fallbackurl: "", |
9 notificationurl: "http://example.com/notification.json", | 11 notificationurl: "http://example.com/notification.json", |
10 notificationdata: {}, | 12 notificationdata: {}, |
11 notifications_ignoredcategories: [] | 13 notifications_ignoredcategories: [] |
12 }; | 14 }; |
13 | 15 |
14 for (let key of Object.keys(Prefs)) | 16 for (let key of Object.keys(Prefs)) |
15 { | 17 { |
16 let value = Prefs[key]; | 18 let value = Prefs[key]; |
17 Object.defineProperty(Prefs, key, { | 19 Object.defineProperty(Prefs, key, { |
18 get: () => value, | 20 get() |
19 set: newValue => | 21 { |
| 22 return value; |
| 23 }, |
| 24 set(newValue) |
20 { | 25 { |
21 if (newValue == value) | 26 if (newValue == value) |
22 return; | 27 return; |
23 | 28 |
24 value = newValue; | 29 value = newValue; |
25 for (let listener of listeners) | 30 for (let listener of listeners) |
26 listener(key); | 31 listener(key); |
27 } | 32 } |
28 }); | 33 }); |
29 } | 34 } |
30 | 35 |
31 Prefs.addListener = function(listener) | 36 Prefs.addListener = function(listener) |
32 { | 37 { |
33 if (listeners.indexOf(listener) < 0) | 38 if (listeners.indexOf(listener) < 0) |
34 listeners.push(listener); | 39 listeners.push(listener); |
35 }; | 40 }; |
36 | 41 |
37 Prefs.removeListener = function(listener) | 42 Prefs.removeListener = function(listener) |
38 { | 43 { |
39 let index = listeners.indexOf(listener); | 44 let index = listeners.indexOf(listener); |
40 if (index >= 0) | 45 if (index >= 0) |
41 listeners.splice(index, 1); | 46 listeners.splice(index, 1); |
42 }; | 47 }; |
OLD | NEW |