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

Unified Diff: lib/filterClasses.js

Issue 29870577: Issue 6916 - Encapsulate filter subscriptions (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Add JSDoc for addSubscription and removeSubscription Created Sept. 1, 2018, 2:10 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 | 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
@@ -35,44 +35,73 @@
* Abstract base class for filters
*
* @param {string} text string representation of the filter
* @constructor
*/
function Filter(text)
{
this.text = text;
- this.subscriptions = new Set();
+
+ /**
+ * Subscriptions to which this filter belongs.
+ * @type {Set.<Subscription>}
+ * @private
+ */
+ this._subscriptions = new Set();
}
exports.Filter = Filter;
Filter.prototype =
{
/**
* String representation of the filter
* @type {string}
*/
text: null,
/**
- * Filter subscriptions the filter belongs to
- * @type {Set.<Subscription>}
- */
- subscriptions: null,
-
- /**
* Filter type as a string, e.g. "blocking".
* @type {string}
*/
get type()
{
throw new Error("Please define filter type in the subclass");
},
/**
+ * Yields subscriptions to which the filter belongs.
+ * @yields {Subscription}
+ */
+ *subscriptions()
+ {
+ yield* this._subscriptions;
+ },
+
+ /**
+ * Adds a subscription to the set of subscriptions to which the filter
+ * belongs.
+ * @param {Subscription} subscription
+ */
+ addSubscription(subscription)
+ {
+ this._subscriptions.add(subscription);
+ },
+
+ /**
+ * Removes a subscription from the set of subscriptions to which the filter
+ * belongs.
+ * @param {Subscription} subscription
+ */
+ removeSubscription(subscription)
+ {
+ this._subscriptions.delete(subscription);
+ },
+
+ /**
* Serializes the filter to an array of strings for writing out on the disk.
* @param {string[]} buffer buffer to push the serialization results into
*/
serialize(buffer)
{
buffer.push("[Filter]");
buffer.push("text=" + this.text);
},
« 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