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

Unified Diff: lib/filterClasses.js

Issue 29935568: Issue 7096 - Make it possible to lazy initialize a filter's subscriptions (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Rebase Created Nov. 18, 2018, 2:31 a.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 | lib/filterListener.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/filterClasses.js
===================================================================
--- a/lib/filterClasses.js
+++ b/lib/filterClasses.js
@@ -55,23 +55,16 @@
* Abstract base class for filters
*
* @param {string} text string representation of the filter
* @constructor
*/
function Filter(text)
{
this.text = text;
-
- /**
- * Subscriptions to which this filter belongs.
- * @type {(Subscription|Set.<Subscription>)?}
- * @private
- */
- this._subscriptions = null;
}
exports.Filter = Filter;
Filter.prototype =
{
/**
* String representation of the filter
* @type {string}
@@ -83,46 +76,73 @@
* @type {string}
*/
get type()
{
throw new Error("Please define filter type in the subclass");
},
/**
+ * Subscriptions to which this filter belongs.
+ * @type {?(Subscription|Set.<Subscription>)}
+ * @private
+ */
+ _subscriptions: null,
+
+ /**
+ * Whether the filter's subscriptions have already been added to the filter.
+ * @type {boolean}
+ * @package
+ */
+ get subscriptionsAdded()
+ {
+ return this.hasOwnProperty("_subscriptions");
+ },
+ set subscriptionsAdded(value)
+ {
+ // Once set to true, this cannot be set back to false even if all
+ // subscriptions are removed.
+ if (value)
+ this._subscriptions = this._subscriptions;
+ },
+
+ /**
* Yields subscriptions to which the filter belongs.
* @yields {Subscription}
+ * @package
*/
*subscriptions()
{
if (this._subscriptions)
{
if (this._subscriptions instanceof Set)
yield* this._subscriptions;
else
yield this._subscriptions;
}
},
/**
* The number of subscriptions to which the filter belongs.
* @type {number}
+ * @package
*/
get subscriptionCount()
{
if (this._subscriptions instanceof Set)
return this._subscriptions.size;
return this._subscriptions ? 1 : 0;
},
/**
* Adds a subscription to the set of subscriptions to which the filter
* belongs.
* @param {Subscription} subscription
+ * @package
*/
addSubscription(subscription)
{
// Since we use truthy checks in our logic, we must avoid adding a
// subscription that isn't a non-null object.
if (subscription === null || typeof subscription != "object")
return;
@@ -138,16 +158,17 @@
this._subscriptions = subscription;
}
},
/**
* Removes a subscription from the set of subscriptions to which the filter
* belongs.
* @param {Subscription} subscription
+ * @package
*/
removeSubscription(subscription)
{
if (this._subscriptions)
{
if (this._subscriptions instanceof Set)
{
this._subscriptions.delete(subscription);
« no previous file with comments | « no previous file | lib/filterListener.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld