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

Delta Between Two Patch Sets: lib/subscriptionClasses.js

Issue 29900557: Issue 7016 - Convert serialization functions into generators (Closed)
Left Patch Set: Actually Address PS2 Comments Created Oct. 21, 2018, 5:25 p.m.
Right Patch Set: Actually address nits Created Oct. 23, 2018, 3:21 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/filterStorage.js ('k') | test/filterClasses.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 if (value != this._disabled) 118 if (value != this._disabled)
119 { 119 {
120 let oldValue = this._disabled; 120 let oldValue = this._disabled;
121 this._disabled = value; 121 this._disabled = value;
122 filterNotifier.emit("subscription.disabled", this, value, oldValue); 122 filterNotifier.emit("subscription.disabled", this, value, oldValue);
123 } 123 }
124 return this._disabled; 124 return this._disabled;
125 }, 125 },
126 126
127 /** 127 /**
128 * Serializes the subscription to an array of strings for writing 128 * Serializes the subscription for writing out on disk.
Manish Jethani 2018/10/21 21:51:43 We could remove the "to an array of strings" part
Jon Sonesen 2018/10/22 19:27:47 Acknowledged.
129 * out on the disk.
130 * @yields {string} 129 * @yields {string}
131 */ 130 */
132 *serialize() 131 *serialize()
133 { 132 {
134 let {url, type, _title, _fixedTitle, _disabled} = this; 133 let {url, type, _title, _fixedTitle, _disabled} = this;
135 134
136 yield "[Subscription]"; 135 yield "[Subscription]";
137 yield "url=" + url; 136 yield "url=" + url;
138 137
139 if (type) 138 if (type)
140 yield "type=" + type; 139 yield "type=" + type;
141 if (_title) 140 if (_title)
142 yield "title=" + _title; 141 yield "title=" + _title;
143 if (_fixedTitle) 142 if (_fixedTitle)
144 yield "fixedTitle=true"; 143 yield "fixedTitle=true";
145 if (_disabled) 144 if (_disabled)
146 yield "disabled=true"; 145 yield "disabled=true";
147 }, 146 },
148 147
149 *serializeFilters() 148 *serializeFilters()
150 { 149 {
151 for (let filter of this.filters) 150 let {filters} = this;
Jon Sonesen 2018/10/22 19:32:40 I noticed this method goes against our pattern els
Manish Jethani 2018/10/22 20:18:01 Just for the sake of consistency, I wouldn't mind
Jon Sonesen 2018/10/23 02:04:24 Done.
151
152 yield "[Subscription filters]";
153
154 for (let filter of filters)
152 yield filter.text.replace(/\[/g, "\\["); 155 yield filter.text.replace(/\[/g, "\\[");
153 }, 156 },
154 157
155 toString() 158 toString()
156 { 159 {
157 return [...this.serialize()].join("\n"); 160 return [...this.serialize()].join("\n");
158 } 161 }
159 }; 162 };
160 163
161 /** 164 /**
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 /** 284 /**
282 * See Subscription.serialize() 285 * See Subscription.serialize()
283 * @inheritdoc 286 * @inheritdoc
284 */ 287 */
285 *serialize() 288 *serialize()
286 { 289 {
287 let {defaults, _lastDownload} = this; 290 let {defaults, _lastDownload} = this;
288 291
289 yield* Subscription.prototype.serialize.call(this); 292 yield* Subscription.prototype.serialize.call(this);
290 293
291 if (defaults && defaults.length) 294 if (defaults)
292 { 295 {
293 yield "defaults=" + 296 yield "defaults=" +
294 defaults.filter( 297 defaults.filter(
295 type => SpecialSubscription.defaultsMap.has(type) 298 type => SpecialSubscription.defaultsMap.has(type)
296 ).join(" "); 299 ).join(" ");
297 } 300 }
298 if (_lastDownload) 301 if (_lastDownload)
299 yield "lastDownload=" + _lastDownload; 302 yield "lastDownload=" + _lastDownload;
300 } 303 }
301 }); 304 });
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 if (errors) 582 if (errors)
580 yield "errors=" + errors; 583 yield "errors=" + errors;
581 if (version) 584 if (version)
582 yield "version=" + version; 585 yield "version=" + version;
583 if (requiredVersion) 586 if (requiredVersion)
584 yield "requiredVersion=" + requiredVersion; 587 yield "requiredVersion=" + requiredVersion;
585 if (downloadCount) 588 if (downloadCount)
586 yield "downloadCount=" + downloadCount; 589 yield "downloadCount=" + downloadCount;
587 } 590 }
588 }); 591 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld