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

Unified Diff: lib/devtools.js

Issue 29339020: Issue 3868 - Use the new FilterNotifier API (Closed)
Patch Set: Updated depdendencies and use EventEmitter.listeners() Created March 24, 2016, 3:29 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 | « dependencies ('k') | lib/events.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
});
« no previous file with comments | « dependencies ('k') | lib/events.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld