Index: background.js |
=================================================================== |
--- a/background.js |
+++ b/background.js |
@@ -93,7 +93,15 @@ |
modules.prefs = { |
Prefs: { |
- onChanged: new Notifier() |
+ _listeners: Object.create(null), |
+ |
+ on: function(preference, callback) |
Thomas Greiner
2016/03/21 17:55:55
What about extending `Notifier` instead so that `N
Sebastian Noack
2016/03/21 19:40:07
Well, changing the calling convention of existing
|
+ { |
+ if (preference in this._listeners) |
+ this._listeners[preference].push(callback); |
+ else |
+ this._listeners[preference] = [callback]; |
+ } |
} |
}; |
var prefs = { |
@@ -114,8 +122,11 @@ |
set: function(value) |
{ |
prefs[key] = value; |
- modules.prefs.Prefs.onChanged.triggerListeners(key); |
- return prefs[key]; |
+ |
+ var listeners = modules.prefs.Prefs._listeners[key]; |
+ if (listeners) |
+ for (var i = 0; i < listeners.length; i++) |
+ listeners[i](); |
} |
}); |
}); |