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