Index: lib/subscriptionClasses.js |
=================================================================== |
--- a/lib/subscriptionClasses.js |
+++ b/lib/subscriptionClasses.js |
@@ -34,17 +34,17 @@ |
* @constructor |
*/ |
function Subscription(url, title) |
{ |
this.url = url; |
this.filters = []; |
if (title) |
this._title = title; |
- Subscription.knownSubscriptions[url] = this; |
+ Subscription.knownSubscriptions.set(url, this); |
} |
exports.Subscription = Subscription; |
Subscription.prototype = |
{ |
/** |
* Download location of the subscription |
* @type {string} |
@@ -149,31 +149,32 @@ |
let buffer = []; |
this.serialize(buffer); |
return buffer.join("\n"); |
} |
}; |
/** |
* Cache for known filter subscriptions, maps URL to subscription objects. |
- * @type {Object} |
+ * @type {Map.<string,Subscription>} |
*/ |
-Subscription.knownSubscriptions = Object.create(null); |
+Subscription.knownSubscriptions = new Map(); |
/** |
* Returns a subscription from its URL, creates a new one if necessary. |
* @param {string} url |
* URL of the subscription |
* @return {Subscription} |
* subscription or null if the subscription couldn't be created |
*/ |
Subscription.fromURL = function(url) |
{ |
- if (url in Subscription.knownSubscriptions) |
- return Subscription.knownSubscriptions[url]; |
+ let subscription = Subscription.knownSubscriptions.get(url); |
Manish Jethani
2018/06/06 11:04:42
No need to call both Map.has and Map.get, only the
|
+ if (subscription) |
+ return subscription; |
if (url[0] != "~") |
return new DownloadableSubscription(url, null); |
return new SpecialSubscription(url); |
}; |
/** |
* Deserializes a subscription |
@@ -301,17 +302,17 @@ |
* @return {SpecialSubscription} |
*/ |
SpecialSubscription.create = function(title) |
{ |
let url; |
do |
{ |
url = "~user~" + Math.round(Math.random() * 1000000); |
- } while (url in Subscription.knownSubscriptions); |
+ } while (Subscription.knownSubscriptions.has(url)); |
return new SpecialSubscription(url, title); |
}; |
/** |
* Creates a new user-defined filter group and adds the given filter to it. |
* This group will act as the default group for this filter type. |
* @param {Filter} filter |
* @return {SpecialSubscription} |