Index: lib/filterClasses.js |
=================================================================== |
--- a/lib/filterClasses.js |
+++ b/lib/filterClasses.js |
@@ -38,20 +38,20 @@ |
* @constructor |
*/ |
function Filter(text) |
{ |
this.text = text; |
/** |
* Subscriptions to which this filter belongs. |
- * @type {Set.<Subscription>} |
+ * @type {(Subscription|Set.<Subscription>)?} |
* @private |
*/ |
- this._subscriptions = new Set(); |
+ this._subscriptions = null; |
} |
exports.Filter = Filter; |
Filter.prototype = |
{ |
/** |
* String representation of the filter |
* @type {string} |
@@ -68,46 +68,78 @@ |
}, |
/** |
* Yields subscriptions to which the filter belongs. |
* @yields {Subscription} |
*/ |
*subscriptions() |
{ |
- yield* this._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} |
*/ |
get subscriptionCount() |
{ |
- return this._subscriptions.size; |
+ 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 |
*/ |
addSubscription(subscription) |
{ |
- this._subscriptions.add(subscription); |
+ if (this._subscriptions) |
+ { |
+ if (this._subscriptions instanceof Set) |
+ this._subscriptions.add(subscription); |
+ else if (subscription != this._subscriptions) |
+ this._subscriptions = new Set([this._subscriptions, subscription]); |
+ } |
+ else |
+ { |
+ this._subscriptions = subscription; |
+ } |
}, |
/** |
* Removes a subscription from the set of subscriptions to which the filter |
* belongs. |
* @param {Subscription} subscription |
*/ |
removeSubscription(subscription) |
{ |
- this._subscriptions.delete(subscription); |
+ if (this._subscriptions) |
+ { |
+ if (this._subscriptions instanceof Set) |
+ { |
+ this._subscriptions.delete(subscription); |
+ |
+ if (this._subscriptions.size == 1) |
+ this._subscriptions = [...this._subscriptions][0]; |
+ } |
+ else if (subscription == this._subscriptions) |
+ { |
+ this._subscriptions = null; |
+ } |
+ } |
}, |
/** |
* 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) |
{ |