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

Unified Diff: messageResponder.js

Issue 29338734: Issue 3839 - Adapt for Prefs event changes (Closed)
Patch Set: Created March 19, 2016, 7:14 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: messageResponder.js
===================================================================
--- a/messageResponder.js
+++ b/messageResponder.js
@@ -60,13 +60,14 @@
"subscription": "subscriptions.listen"
};
- function sendMessage(type, action, args, page)
+ function sendMessage(type, action, args)
{
- var pages = page ? [page] : changeListeners.keys();
+ var pages = changeListeners.keys();
Sebastian Noack 2016/03/19 19:17:29 This is unrelated, but since page is never specifi
for (var i = 0; i < pages.length; i++)
{
var filters = changeListeners.get(pages[i]);
- if (filters[type] && filters[type].indexOf(action) >= 0)
+ var actions = filters[type];
+ if (actions && !(actions instanceof Array && actions.indexOf(action) == -1))
Sebastian Noack 2016/03/19 19:17:29 filters.pref is an object now, not an array anymor
{
pages[i].sendMessage({
type: messageTypes[type],
@@ -110,11 +111,6 @@
sendMessage(type, action, args);
}
- function onPrefChange(name)
- {
- sendMessage("pref", name, [Prefs[name]]);
- }
-
global.ext.onMessage.addListener(function(message, sender, callback)
{
var listenerFilters = null;
@@ -124,7 +120,6 @@
{
changeListeners = new global.ext.PageMap();
FilterNotifier.addListener(onFilterChange);
- Prefs.onChanged.addListener(onPrefChange);
}
listenerFilters = changeListeners.get(sender.page);
@@ -307,8 +302,23 @@
callback(Prefs[message.key]);
break;
case "prefs.listen":
+ for (var preference in listenerFilters.pref)
+ Prefs.off(preference, listenerFilters.pref[preference]);
+
if (message.filter)
- listenerFilters.pref = message.filter;
+ {
+ listenerFilters.pref = Object.create(null);
+ message.filter.forEach(function(preference)
+ {
+ function callback()
+ {
+ sendMessage("prefs", preference, [Prefs[preference]]);
+ }
+
+ listenerFilters.pref[preference] = callback;
+ Prefs.on(preference, callback);
+ });
+ }
else
delete listenerFilters.pref;
break;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld