Index: lib/filterClasses.js |
=================================================================== |
--- a/lib/filterClasses.js |
+++ b/lib/filterClasses.js |
@@ -36,17 +36,17 @@ |
* |
* @param {string} text string representation of the filter |
* @constructor |
*/ |
function Filter(text) |
{ |
this.text = text; |
- this._subscriptions = new Set(); |
+ this._subscriptions = null; |
} |
exports.Filter = Filter; |
Filter.prototype = |
{ |
/** |
* String representation of the filter |
* @type {string} |
@@ -63,27 +63,56 @@ |
}, |
/** |
* Yields filter subscriptions the filter belongs to |
* @yields {Subscription} |
*/ |
*subscriptions() |
{ |
- yield* this._subscriptions; |
+ if (this._subscriptions) |
+ { |
+ if (this._subscriptions instanceof Set) |
+ yield* this._subscriptions; |
+ else |
+ yield this._subscriptions; |
+ } |
}, |
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; |
+ } |
}, |
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) |
{ |