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

Unified Diff: lib/filterStorage.js

Issue 29853561: Issue 6854 - Remove deprecated FilterNotifier methods (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Aug. 11, 2018, 2:43 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
Index: lib/filterStorage.js
===================================================================
--- a/lib/filterStorage.js
+++ b/lib/filterStorage.js
@@ -126,34 +126,34 @@
{
if (FilterStorage.knownSubscriptions.has(subscription.url))
return;
FilterStorage.subscriptions.push(subscription);
FilterStorage.knownSubscriptions.set(subscription.url, subscription);
addSubscriptionFilters(subscription);
- FilterNotifier.triggerListeners("subscription.added", subscription);
+ FilterNotifier.emit("subscription.added", subscription);
},
/**
* Removes a filter subscription from the list
* @param {Subscription} subscription filter subscription to be removed
*/
removeSubscription(subscription)
{
for (let i = 0; i < FilterStorage.subscriptions.length; i++)
{
if (FilterStorage.subscriptions[i].url == subscription.url)
{
removeSubscriptionFilters(subscription);
FilterStorage.subscriptions.splice(i--, 1);
FilterStorage.knownSubscriptions.delete(subscription.url);
- FilterNotifier.triggerListeners("subscription.removed", subscription);
+ FilterNotifier.emit("subscription.removed", subscription);
return;
}
}
},
/**
* Moves a subscription in the list to a new position.
* @param {Subscription} subscription filter subscription to be moved
@@ -175,31 +175,31 @@
if (currentPos < newPos)
newPos--;
if (currentPos == newPos)
return;
FilterStorage.subscriptions.splice(currentPos, 1);
FilterStorage.subscriptions.splice(newPos, 0, subscription);
- FilterNotifier.triggerListeners("subscription.moved", subscription);
+ FilterNotifier.emit("subscription.moved", subscription);
},
/**
* Replaces the list of filters in a subscription by a new list
* @param {Subscription} subscription filter subscription to be updated
* @param {Filter[]} filters new filter list
*/
updateSubscriptionFilters(subscription, filters)
{
removeSubscriptionFilters(subscription);
subscription.oldFilters = subscription.filters;
subscription.filters = filters;
addSubscriptionFilters(subscription);
- FilterNotifier.triggerListeners("subscription.updated", subscription);
+ FilterNotifier.emit("subscription.updated", subscription);
delete subscription.oldFilters;
},
/**
* Adds a user-defined filter to the list
* @param {Filter} filter
* @param {SpecialSubscription} [subscription]
* particular group that the filter should be added to
@@ -226,18 +226,17 @@
}
if (typeof position == "undefined")
position = subscription.filters.length;
if (filter.subscriptions.indexOf(subscription) < 0)
filter.subscriptions.push(subscription);
subscription.filters.splice(position, 0, filter);
- FilterNotifier.triggerListeners("filter.added", filter, subscription,
- position);
+ FilterNotifier.emit("filter.added", filter, subscription, position);
},
/**
* Removes a user-defined filter from the list
* @param {Filter} filter
* @param {SpecialSubscription} [subscription] a particular filter group that
* the filter should be removed from (if ommited will be removed from all
* subscriptions)
@@ -275,19 +274,18 @@
{
currentSubscription.filters.splice(currentPosition, 1);
if (currentSubscription.filters.indexOf(filter) < 0)
{
let index = filter.subscriptions.indexOf(currentSubscription);
if (index >= 0)
filter.subscriptions.splice(index, 1);
}
- FilterNotifier.triggerListeners(
- "filter.removed", filter, currentSubscription, currentPosition
- );
+ FilterNotifier.emit("filter.removed", filter, currentSubscription,
+ currentPosition);
}
}
}
}
},
/**
* Moves a user-defined filter to a new position
@@ -307,18 +305,18 @@
newPosition = Math.min(Math.max(newPosition, 0),
subscription.filters.length - 1);
if (oldPosition == newPosition)
return;
subscription.filters.splice(oldPosition, 1);
subscription.filters.splice(newPosition, 0, filter);
- FilterNotifier.triggerListeners("filter.moved", filter, subscription,
- oldPosition, newPosition);
+ FilterNotifier.emit("filter.moved", filter, subscription, oldPosition,
+ newPosition);
},
/**
* Increases the hit count for a filter by one
* @param {Filter} filter
*/
increaseHitCount(filter)
{
@@ -374,17 +372,17 @@
this.fileProperties = parser.fileProperties;
this.subscriptions = parser.subscriptions;
this.knownSubscriptions = knownSubscriptions;
Filter.knownFilters = parser.knownFilters;
Subscription.knownSubscriptions = parser.knownSubscriptions;
if (!silent)
- FilterNotifier.triggerListeners("load");
+ FilterNotifier.emit("load");
}
};
},
/**
* Loads all subscriptions from the disk.
* @return {Promise} promise resolved or rejected when loading is complete
*/
@@ -422,17 +420,17 @@
});
}).catch(error =>
{
Cu.reportError(error);
return tryBackup(1);
}).then(() =>
{
this.initialized = true;
- FilterNotifier.triggerListeners("load");
+ FilterNotifier.emit("load");
});
},
/**
* Constructs the file name for a patterns.ini backup.
* @param {number} backupIndex
* number of the backup file (1 being the most recent)
* @return {string} backup file name
@@ -590,17 +588,17 @@
{
// Errors during backup creation shouldn't prevent writing filters.
Cu.reportError(error);
}).then(() =>
{
return IO.writeToFile(this.sourceFile, this.exportData());
}).then(() =>
{
- FilterNotifier.triggerListeners("save");
+ FilterNotifier.emit("save");
}).catch(error =>
{
// If saving failed, report error but continue - we still have to process
// flags.
Cu.reportError(error);
}).then(() =>
{
this._saving = false;
« no previous file with comments | « lib/filterNotifier.js ('k') | lib/subscriptionClasses.js » ('j') | test/filterNotifier.js » ('J')

Powered by Google App Engine
This is Rietveld