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

Side by Side Diff: messageResponder.js

Issue 29339088: Noissue - Use hash tables instead arrays to keep track of registered listeners (Closed)
Patch Set: Created March 29, 2016, 9:46 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 for (var i = 0; i < keys.length; i++) 62 for (var i = 0; i < keys.length; i++)
63 result[keys[i]] = obj[keys[i]]; 63 result[keys[i]] = obj[keys[i]];
64 return result; 64 return result;
65 } 65 }
66 66
67 var convertSubscription = convertObject.bind(null, ["disabled", 67 var convertSubscription = convertObject.bind(null, ["disabled",
68 "downloadStatus", "homepage", "lastDownload", "title", "url"]); 68 "downloadStatus", "homepage", "lastDownload", "title", "url"]);
69 var convertFilter = convertObject.bind(null, ["text"]); 69 var convertFilter = convertObject.bind(null, ["text"]);
70 70
71 var changeListeners = new global.ext.PageMap(); 71 var changeListeners = new global.ext.PageMap();
72 var listenedPreferences = []; 72 var listenedPreferences = Object.create(null);
73 var listenedFilterChanges = []; 73 var listenedFilterChanges = Object.create(null);
74 var messageTypes = { 74 var messageTypes = {
75 "app": "app.listen", 75 "app": "app.listen",
76 "filter": "filters.listen", 76 "filter": "filters.listen",
77 "pref": "prefs.listen", 77 "pref": "prefs.listen",
78 "subscription": "subscriptions.listen" 78 "subscription": "subscriptions.listen"
79 }; 79 };
80 80
81 function sendMessage(type, action) 81 function sendMessage(type, action)
82 { 82 {
83 var pages = changeListeners.keys(); 83 var pages = changeListeners.keys();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 function addFilterListeners(type, actions) 115 function addFilterListeners(type, actions)
116 { 116 {
117 actions.forEach(function(action) 117 actions.forEach(function(action)
118 { 118 {
119 var name; 119 var name;
120 if (type == "filter" && action == "loaded") 120 if (type == "filter" && action == "loaded")
121 name = "load"; 121 name = "load";
122 else 122 else
123 name = type + "." + action; 123 name = type + "." + action;
124 124
125 if (listenedFilterChanges.indexOf(name) == -1) 125 if (!(name in listenedFilterChanges))
126 { 126 {
127 listenedFilterChanges.push(name); 127 listenedFilterChanges[name] = null;
128 FilterNotifier.on(name, function() 128 FilterNotifier.on(name, function()
129 { 129 {
130 var args = [type, action]; 130 var args = [type, action];
131 for (var i = 0; i < arguments.length; i++) 131 for (var i = 0; i < arguments.length; i++)
132 args.push(arguments[i]); 132 args.push(arguments[i]);
133 sendMessage.apply(null, args); 133 sendMessage.apply(null, args);
134 }); 134 });
135 } 135 }
136 }); 136 });
137 } 137 }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 else 303 else
304 FilterStorage.removeFilter(filter, subscription, message.index); 304 FilterStorage.removeFilter(filter, subscription, message.index);
305 break; 305 break;
306 case "prefs.get": 306 case "prefs.get":
307 callback(Prefs[message.key]); 307 callback(Prefs[message.key]);
308 break; 308 break;
309 case "prefs.listen": 309 case "prefs.listen":
310 getListenerFilters(sender.page).pref = message.filter; 310 getListenerFilters(sender.page).pref = message.filter;
311 message.filter.forEach(function(preference) 311 message.filter.forEach(function(preference)
312 { 312 {
313 if (listenedPreferences.indexOf(preference) == -1) 313 if (!(preference in listenedPreferences))
314 { 314 {
315 listenedPreferences.push(preference); 315 listenedPreferences[preference] = null;
316 Prefs.on(preference, function() 316 Prefs.on(preference, function()
317 { 317 {
318 sendMessage("pref", preference, Prefs[preference]); 318 sendMessage("pref", preference, Prefs[preference]);
319 }); 319 });
320 } 320 }
321 }); 321 });
322 break; 322 break;
323 case "prefs.toggle": 323 case "prefs.toggle":
324 if (message.key == "notifications_ignoredcategories") 324 if (message.key == "notifications_ignoredcategories")
325 NotificationStorage.toggleIgnoreCategory("*"); 325 NotificationStorage.toggleIgnoreCategory("*");
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 if (subscription instanceof DownloadableSubscription) 399 if (subscription instanceof DownloadableSubscription)
400 Synchronizer.execute(subscription, true); 400 Synchronizer.execute(subscription, true);
401 } 401 }
402 break; 402 break;
403 case "subscriptions.isDownloading": 403 case "subscriptions.isDownloading":
404 callback(Synchronizer.isExecuting(message.url)); 404 callback(Synchronizer.isExecuting(message.url));
405 break; 405 break;
406 } 406 }
407 }); 407 });
408 })(this); 408 })(this);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld