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

Unified Diff: lib/filterClasses.js

Issue 29900557: Issue 7016 - Convert serialization functions into generators (Closed)
Patch Set: Address PS2 Comments Created Oct. 12, 2018, 3:46 a.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
« no previous file with comments | « no previous file | lib/filterStorage.js » ('j') | lib/subscriptionClasses.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/filterClasses.js
===================================================================
--- a/lib/filterClasses.js
+++ b/lib/filterClasses.js
@@ -138,23 +138,24 @@
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
+ * Generates serialized filter.
+ * @yields {string}
*/
- serialize(buffer)
+ *serialize()
{
- buffer.push("[Filter]");
- buffer.push("text=" + this.text);
+ let text = this;
Manish Jethani 2018/10/14 20:05:36 This should be: let {text} = this; It's workin
+ yield "[Filter]";
+ yield "text=" + text;
},
toString()
{
return this.text;
}
};
@@ -321,17 +322,17 @@
* @type {string}
*/
reason: null,
/**
* See Filter.serialize()
* @inheritdoc
*/
- serialize(buffer) {}
+ *serialize() {}
});
/**
* Class for comments
* @param {string} text see {@link Filter Filter()}
* @constructor
* @augments Filter
*/
@@ -343,17 +344,17 @@
CommentFilter.prototype = extend(Filter, {
type: "comment",
/**
* See Filter.serialize()
* @inheritdoc
*/
- serialize(buffer) {}
+ *serialize() {}
});
/**
* Abstract base class for filters that can get hits
* @param {string} text
* see {@link Filter Filter()}
* @param {string} [domains]
* Domains that the filter is restricted to separated by domainSeparator
@@ -609,27 +610,28 @@
return !(sitekeys && sitekeys.length) && (!domains || domains.get(""));
},
/**
* See Filter.serialize()
* @inheritdoc
*/
- serialize(buffer)
+ *serialize()
{
- if (this._disabled || this._hitCount || this._lastHit)
+ let {_disabled, _hitCount, _lastHit} = this;
+ if (_disabled || _hitCount || _lastHit)
{
- Filter.prototype.serialize.call(this, buffer);
+ yield* Filter.prototype.serialize.call(this);
if (this._disabled)
Manish Jethani 2018/10/14 20:05:36 We extracted the values first so we would use them
- buffer.push("disabled=true");
+ yield "disabled=true";
if (this._hitCount)
- buffer.push("hitCount=" + this._hitCount);
+ yield "hitCount=" + this._hitCount;
if (this._lastHit)
- buffer.push("lastHit=" + this._lastHit);
+ yield "lastHit=" + this._lastHit;
}
}
});
/**
* Abstract base class for RegExp-based filters
* @param {string} text see {@link Filter Filter()}
* @param {string} regexpSource
« no previous file with comments | « no previous file | lib/filterStorage.js » ('j') | lib/subscriptionClasses.js » ('J')

Powered by Google App Engine
This is Rietveld