Index: lib/devtools.js |
=================================================================== |
--- a/lib/devtools.js |
+++ b/lib/devtools.js |
@@ -257,35 +257,8 @@ |
} |
} |
-function onFilterChange(action, arg) |
+function updateFilters(filters, added) |
{ |
- let added, filters; |
- switch (action) |
- { |
- case "filter.added": |
- added = true; |
- filters = [arg]; |
- break; |
- |
- case "filter.removed": |
- added = false; |
- filters = [arg]; |
- break; |
- |
- // When there haven't ever been any user filters before, the subscription is |
- // added, triggering a "subscription.added" instead of a "filter.added" event. |
- case "subscription.added": |
- if (arg instanceof SpecialSubscription) |
- { |
- added = true; |
- filters = arg.filters; |
- break; |
- } |
- |
- default: |
- return; |
- } |
- |
for (let tabId in panels) |
{ |
let panel = panels[tabId]; |
@@ -344,6 +317,22 @@ |
} |
} |
+function onFilterAdded(filter) |
+{ |
+ updateFilters([filter], true); |
+} |
+ |
+function onFilterRemoved(filter) |
+{ |
+ updateFilters([filter], false); |
+} |
+ |
+function onSubscriptionAdded(subscription) |
+{ |
+ if (subscription instanceof SpecialSubscription) |
+ updateFilters(subscription.filters, true); |
+} |
+ |
chrome.runtime.onConnect.addListener(port => |
{ |
let match = port.name.match(/^devtools-(\d+)$/); |
@@ -365,7 +354,9 @@ |
if (!hasPanels()) |
{ |
ext.pages.onLoading.addListener(onLoading); |
- FilterNotifier.addListener(onFilterChange); |
+ FilterNotifier.on("filter.added", onFilterAdded); |
+ FilterNotifier.on("filter.removed", onFilterRemoved); |
+ FilterNotifier.on("subscription.added", onSubscriptionAdded); |
} |
port.onDisconnect.addListener(() => |
@@ -375,8 +366,10 @@ |
if (!hasPanels()) |
{ |
- FilterNotifier.removeListener(onFilterChange); |
ext.pages.onLoading.removeListener(onLoading); |
+ FilterNotifier.off("filter.added", onFilterAdded); |
+ FilterNotifier.off("filter.removed", onFilterRemoved); |
+ FilterNotifier.off("subscription.added", onSubscriptionAdded); |
} |
}); |