| 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,83 @@ |
| }, |
| /** |
| * Yields subscriptions to which the filter belongs. |
| * @yields {Subscription} |
|
Jon Sonesen
2018/09/02 17:22:50
Should this be {(Subscription|Set.<Subscription>)?
Manish Jethani
2018/09/03 19:03:42
No, the function only ever yields a single Subscri
|
| */ |
| *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); |
| + // Since we use truthy checks in our logic, we must avoid adding a |
| + // subscription that isn't a non-null object. |
|
Jon Sonesen
2018/09/02 17:22:50
the double negative in the comment is sort of conf
Manish Jethani
2018/09/03 19:03:42
The non-null part is a bit of a distraction: the p
|
| + if (subscription === null || typeof subscription != "object") |
| + return; |
| + |
| + 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]; |
|
Jon Sonesen
2018/09/02 17:22:50
Just asking, not so much a comment but this line
Manish Jethani
2018/09/03 19:03:42
Yes, that's exactly what it does. We can't do `thi
|
| + } |
| + 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) |
| { |