Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: background.js

Issue 29338734: Issue 3839 - Adapt for Prefs event changes (Closed)
Patch Set: Created March 21, 2016, 4:17 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | messageResponder.js » ('j') | messageResponder.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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]();
}
});
});
« no previous file with comments | « no previous file | messageResponder.js » ('j') | messageResponder.js » ('J')

Powered by Google App Engine
This is Rietveld