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

Unified Diff: lib/subscriptionClasses.js

Issue 29900557: Issue 7016 - Convert serialization functions into generators (Closed)
Patch Set: Remove unelated change Created Oct. 3, 2018, 11:51 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
Index: lib/subscriptionClasses.js
===================================================================
--- a/lib/subscriptionClasses.js
+++ b/lib/subscriptionClasses.js
@@ -122,43 +122,42 @@
filterNotifier.emit("subscription.disabled", this, value, oldValue);
}
return this._disabled;
},
/**
* Serializes the subscription to an array of strings for writing
* out on the disk.
- * @param {string[]} buffer buffer to push the serialization results into
+ * @yields {string}
*/
- serialize(buffer)
+ *serialize()
{
- buffer.push("[Subscription]");
- buffer.push("url=" + this.url);
+ yield "[Subscription]";
Manish Jethani 2018/10/09 15:11:04 Let's extract the values first: let {url, type,
Jon Sonesen 2018/10/12 03:50:06 Done.
+ yield "url=" + this.url;
+
if (this.type)
- buffer.push("type=" + this.type);
+ yield "type=" + this.type;
if (this._title)
- buffer.push("title=" + this._title);
+ yield "title=" + this._title;
if (this._fixedTitle)
- buffer.push("fixedTitle=true");
+ yield "fixedTitle=true";
if (this._disabled)
- buffer.push("disabled=true");
+ yield "disabled=true";
},
- serializeFilters(buffer)
+ *serializeFilters()
Manish Jethani 2018/10/04 03:37:12 This might be a good place to introduce a generic
Jon Sonesen 2018/10/06 00:06:34 This most likely will turn into a rather large cha
Manish Jethani 2018/10/09 15:11:04 Acknowledged.
{
for (let filter of this.filters)
- buffer.push(filter.text.replace(/\[/g, "\\["));
+ yield filter.text.replace(/\[/g, "\\[");
},
toString()
{
- let buffer = [];
- this.serialize(buffer);
- return buffer.join("\n");
+ return [...this.serialize()].join("\n");
}
};
/**
* Cache for known filter subscriptions, maps URL to subscription objects.
* @type {Map.<string,Subscription>}
*/
Subscription.knownSubscriptions = new Map();
@@ -276,29 +275,29 @@
return false;
},
/**
* See Subscription.serialize()
* @inheritdoc
*/
- serialize(buffer)
+ *serialize()
{
- Subscription.prototype.serialize.call(this, buffer);
+ yield* Subscription.prototype.serialize.call(this);
Manish Jethani 2018/10/09 15:11:04 Let's extract the values first: let {defaults,
Jon Sonesen 2018/10/12 03:50:06 Done.
if (this.defaults && this.defaults.length)
{
- buffer.push("defaults=" +
+ yield "defaults=" +
Manish Jethani 2018/10/04 03:37:12 Nit: Since there is no longer a function call here
Jon Sonesen 2018/10/06 00:06:34 Acknowledged.
this.defaults.filter(
type => SpecialSubscription.defaultsMap.has(type)
).join(" ")
- );
+ ;
}
if (this._lastDownload)
- buffer.push("lastDownload=" + this._lastDownload);
+ yield "lastDownload=" + this._lastDownload;
}
});
SpecialSubscription.defaultsMap = new Map([
["whitelist", WhitelistFilter],
["blocking", BlockingFilter],
["elemhide", ElemHideBase]
]);
@@ -394,23 +393,23 @@
}
return this._lastDownload;
},
/**
* See Subscription.serialize()
* @inheritdoc
*/
- serialize(buffer)
+ *serialize()
{
- Subscription.prototype.serialize.call(this, buffer);
+ yield* Subscription.prototype.serialize.call(this);
Manish Jethani 2018/10/09 15:11:04 Same thing, let's extract _homepage and _lastDownl
Jon Sonesen 2018/10/12 03:50:06 Done.
if (this._homepage)
- buffer.push("homepage=" + this._homepage);
+ yield "homepage=" + this._homepage;
if (this._lastDownload)
- buffer.push("lastDownload=" + this._lastDownload);
+ yield "lastDownload=" + this._lastDownload;
}
});
/**
* Class for filter subscriptions updated externally (by other extension)
* @param {string} url see {@link Subscription Subscription()}
* @param {string} [title] see {@link Subscription Subscription()}
* @constructor
@@ -422,19 +421,19 @@
}
exports.ExternalSubscription = ExternalSubscription;
ExternalSubscription.prototype = extend(RegularSubscription, {
/**
* See Subscription.serialize()
* @inheritdoc
*/
- serialize(buffer)
+ *serialize()
{
- throw new Error(
+ yield new Error(
Manish Jethani 2018/10/04 03:37:12 This would still be a throw.
Manish Jethani 2018/10/04 05:30:00 I see, you're getting an error from ESLint. I hate
Jon Sonesen 2018/10/12 03:50:06 Inline disable ok?
Manish Jethani 2018/10/14 20:05:36 Yeah, that's probably better.
"Unexpected call, external subscriptions should not be serialized"
);
}
});
/**
* Class for filter subscriptions updated externally (by other extension)
* @param {string} url see {@link Subscription Subscription()}
@@ -547,31 +546,31 @@
* @type {number}
*/
downloadCount: 0,
/**
* See Subscription.serialize()
* @inheritdoc
*/
- serialize(buffer)
+ *serialize()
{
- RegularSubscription.prototype.serialize.call(this, buffer);
+ yield* RegularSubscription.prototype.serialize.call(this);
Manish Jethani 2018/10/09 15:11:04 Same thing, let's extract all the values of the pr
Jon Sonesen 2018/10/12 03:50:06 Done.
if (this.downloadStatus)
- buffer.push("downloadStatus=" + this.downloadStatus);
+ yield "downloadStatus=" + this.downloadStatus;
if (this.lastSuccess)
- buffer.push("lastSuccess=" + this.lastSuccess);
+ yield "lastSuccess=" + this.lastSuccess;
if (this.lastCheck)
- buffer.push("lastCheck=" + this.lastCheck);
+ yield "lastCheck=" + this.lastCheck;
if (this.expires)
- buffer.push("expires=" + this.expires);
+ yield "expires=" + this.expires;
if (this.softExpiration)
- buffer.push("softExpiration=" + this.softExpiration);
+ yield "softExpiration=" + this.softExpiration;
if (this.errors)
- buffer.push("errors=" + this.errors);
+ yield "errors=" + this.errors;
if (this.version)
- buffer.push("version=" + this.version);
+ yield "version=" + this.version;
if (this.requiredVersion)
- buffer.push("requiredVersion=" + this.requiredVersion);
+ yield "requiredVersion=" + this.requiredVersion;
if (this.downloadCount)
- buffer.push("downloadCount=" + this.downloadCount);
+ yield "downloadCount=" + this.downloadCount;
}
});

Powered by Google App Engine
This is Rietveld