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

Unified Diff: lib/filterListener.js

Issue 29338976: Issue 3862 - Make filterListener use the new FilterNotifier API (Closed)
Patch Set: Added filter actions that were implicitly handled before Created March 23, 2016, 6: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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/filterListener.js
===================================================================
--- a/lib/filterListener.js
+++ b/lib/filterListener.js
@@ -19,6 +19,8 @@
* @fileOverview Component synchronizing filter storage with Matcher instances and ElemHide.
*/
+"use strict";
+
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
@@ -107,16 +109,28 @@
*/
function init()
{
- FilterNotifier.addListener(function(action, item, newValue, oldValue)
- {
- let match = /^(\w+)\.(.*)/.exec(action);
- if (match && match[1] == "filter")
- onFilterChange(match[2], item, newValue, oldValue);
- else if (match && match[1] == "subscription")
- onSubscriptionChange(match[2], item, newValue, oldValue);
- else
- onGenericChange(action, item);
- });
+ FilterNotifier.on("filter.hitCount", onFilterHitCount);
+ FilterNotifier.on("filter.lastHit", onFilterLastHit);
+ FilterNotifier.on("filter.added", onFilterAdded);
+ FilterNotifier.on("filter.removed", onFilterRemoved);
+ FilterNotifier.on("filter.disabled", onFilterDisabled);
+ FilterNotifier.on("filter.moved", onGenericChange);
+
+ FilterNotifier.on("subscription.added", onSubscriptionAdded);
+ FilterNotifier.on("subscription.removed", onSubscriptionRemoved);
+ FilterNotifier.on("subscription.disabled", onSubscriptionDisabled);
+ FilterNotifier.on("subscription.updated", onSubscriptionUpdated);
+ FilterNotifier.on("subscription.moved", onGenericChange);
+ FilterNotifier.on("subscription.title", onGenericChange);
+ FilterNotifier.on("subscription.fixedTitle", onGenericChange);
+ FilterNotifier.on("subscription.homepage", onGenericChange);
+ FilterNotifier.on("subscription.downloadStatus", onGenericChange);
+ FilterNotifier.on("subscription.lastCheck", onGenericChange);
+ FilterNotifier.on("subscription.errors", onGenericChange);
+
+ FilterNotifier.on("load", onLoad);
+ FilterNotifier.on("save", onSave);
+
if ("nsIStyleSheetService" in Ci)
ElemHide.init();
@@ -200,91 +214,120 @@
}
}
-/**
- * Subscription change listener
- */
-function onSubscriptionChange(action, subscription, newValue, oldValue)
+function onSubscriptionAdded(subscription)
{
FilterListener.setDirty(1);
- if (action != "added" && action != "removed" && action != "disabled" && action != "updated")
- return;
+ if (!subscription.disabled)
+ {
+ subscription.filters.forEach(addFilter);
+ flushElemHide();
+ }
+}
- if (action != "removed" && !(subscription.url in FilterStorage.knownSubscriptions))
+function onSubscriptionRemoved(subscription)
+{
+ FilterListener.setDirty(1);
+
+ if (!subscription.disabled)
{
- // Ignore updates for subscriptions not in the list
- return;
+ subscription.filters.forEach(removeFilter);
+ flushElemHide();
}
+}
- if ((action == "added" || action == "removed" || action == "updated") && subscription.disabled)
+function onSubscriptionDisabled(subscription, newValue)
+{
+ FilterListener.setDirty(1);
+
+ if (subscription.url in FilterStorage.knownSubscriptions)
{
- // Ignore adding/removing/updating of disabled subscriptions
- return;
+ if (newValue == false)
+ subscription.filters.forEach(addFilter);
+ else
+ subscription.filters.forEach(removeFilter);
+ flushElemHide();
}
+}
- if (action == "added" || action == "removed" || action == "disabled")
- {
- let method = (action == "added" || (action == "disabled" && newValue == false) ? addFilter : removeFilter);
- if (subscription.filters)
- subscription.filters.forEach(method);
- }
- else if (action == "updated")
+function onSubscriptionUpdated(subscription)
+{
+ FilterListener.setDirty(1);
+
+ if (subscription.url in FilterStorage.knownSubscriptions &&
+ !subscription.disabled)
{
subscription.oldFilters.forEach(removeFilter);
subscription.filters.forEach(addFilter);
+ flushElemHide();
}
-
- flushElemHide();
}
-/**
- * Filter change listener
- */
-function onFilterChange(action, filter, newValue, oldValue)
+function onFilterHitCount(filter, newValue)
{
- if (action == "hitCount" && newValue == 0)
+ if (newValue == 0)
+ FilterListener.setDirty(0);
+ else
+ FilterListener.setDirty(0.002);
+}
+
+function onFilterLastHit()
+{
+ FilterListener.setDirty(0.002);
+}
+
+function onFilterAdded(filter)
+{
+ FilterListener.setDirty(1);
+
+ if (!filter.disabled)
{
- // Filter hits are being reset, make sure these changes are saved.
- FilterListener.setDirty(0);
+ addFilter(filter);
+ flushElemHide();
}
- else if (action == "hitCount" || action == "lastHit")
- FilterListener.setDirty(0.002);
- else
- FilterListener.setDirty(1);
+}
- if (action != "added" && action != "removed" && action != "disabled")
- return;
+function onFilterRemoved(filter)
+{
+ FilterListener.setDirty(1);
- if ((action == "added" || action == "removed") && filter.disabled)
+ if (!filter.disabled)
{
- // Ignore adding/removing of disabled filters
- return;
+ removeFilter(filter);
+ flushElemHide();
}
+}
- if (action == "added" || (action == "disabled" && newValue == false))
+function onFilterDisabled(filter, newValue)
+{
+ FilterListener.setDirty(1);
+
+ if (newValue == false)
addFilter(filter);
else
removeFilter(filter);
flushElemHide();
}
-/**
- * Generic notification listener
- */
-function onGenericChange(action)
+function onGenericChange()
{
- if (action == "load")
- {
- isDirty = 0;
+ FilterListener.setDirty(1);
+}
- defaultMatcher.clear();
- ElemHide.clear();
- CSSRules.clear();
- for (let subscription of FilterStorage.subscriptions)
- if (!subscription.disabled)
- subscription.filters.forEach(addFilter);
- flushElemHide();
- }
- else if (action == "save")
- isDirty = 0;
+function onLoad()
+{
+ isDirty = 0;
+
+ defaultMatcher.clear();
+ ElemHide.clear();
+ CSSRules.clear();
+ for (let subscription of FilterStorage.subscriptions)
+ if (!subscription.disabled)
+ subscription.filters.forEach(addFilter);
+ flushElemHide();
}
+
+function onSave()
+{
+ isDirty = 0;
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld