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; |