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: Address PS2 Comments Created Oct. 12, 2018, 3:46 a.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.
129 * out on the disk.
130 * @yields {string} 129 * @yields {string}
131 */ 130 */
132 *serialize() 131 *serialize()
133 { 132 {
133 let {url, type, _title, _fixedTitle, _disabled} = this;
134
134 yield "[Subscription]"; 135 yield "[Subscription]";
135 let {url, type, _title, _fixedTitle, _disabled} = this;
Manish Jethani 2018/10/14 20:05:37 Let's place this line first before any yield state
Jon Sonesen 2018/10/21 06:18:23 Done.
Manish Jethani 2018/10/21 13:08:58 Sorry if I wasn't clear, it should be the first li
136 yield "url=" + url; 136 yield "url=" + url;
137 137
138 if (this.type) 138 if (type)
Manish Jethani 2018/10/14 20:05:37 Similarly, we should remove the `this.` prefix her
Jon Sonesen 2018/10/21 06:18:23 Done.
Manish Jethani 2018/10/21 13:08:58 What about `this.type` and `this._title`?
139 yield "type=" + type; 139 yield "type=" + type;
140 if (this._title) 140 if (_title)
141 yield "title=" + _title; 141 yield "title=" + _title;
142 if (_fixedTitle) 142 if (_fixedTitle)
143 yield "fixedTitle=true"; 143 yield "fixedTitle=true";
144 if (_disabled) 144 if (_disabled)
145 yield "disabled=true"; 145 yield "disabled=true";
146 }, 146 },
147 147
148 *serializeFilters() 148 *serializeFilters()
149 { 149 {
150 for (let filter of this.filters) 150 let {filters} = this;
151
152 yield "[Subscription filters]";
153
154 for (let filter of filters)
151 yield filter.text.replace(/\[/g, "\\["); 155 yield filter.text.replace(/\[/g, "\\[");
152 }, 156 },
153 157
154 toString() 158 toString()
155 { 159 {
156 return [...this.serialize()].join("\n"); 160 return [...this.serialize()].join("\n");
157 } 161 }
158 }; 162 };
159 163
160 /** 164 /**
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 return false; 281 return false;
278 }, 282 },
279 283
280 /** 284 /**
281 * See Subscription.serialize() 285 * See Subscription.serialize()
282 * @inheritdoc 286 * @inheritdoc
283 */ 287 */
284 *serialize() 288 *serialize()
285 { 289 {
286 let {defaults, _lastDownload} = this; 290 let {defaults, _lastDownload} = this;
291
287 yield* Subscription.prototype.serialize.call(this); 292 yield* Subscription.prototype.serialize.call(this);
288 if (defaults && defaults.length) 293
294 if (defaults)
289 { 295 {
290 yield "defaults=" + 296 yield "defaults=" +
291 defaults.filter( 297 defaults.filter(
292 type => SpecialSubscription.defaultsMap.has(type) 298 type => SpecialSubscription.defaultsMap.has(type)
293 ).join(" ") 299 ).join(" ");
294 ;
295 } 300 }
296 if (_lastDownload) 301 if (_lastDownload)
297 yield "lastDownload=" + _lastDownload; 302 yield "lastDownload=" + _lastDownload;
298 } 303 }
299 }); 304 });
300 305
301 SpecialSubscription.defaultsMap = new Map([ 306 SpecialSubscription.defaultsMap = new Map([
302 ["whitelist", WhitelistFilter], 307 ["whitelist", WhitelistFilter],
303 ["blocking", BlockingFilter], 308 ["blocking", BlockingFilter],
304 ["elemhide", ElemHideBase] 309 ["elemhide", ElemHideBase]
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 return this._lastDownload; 401 return this._lastDownload;
397 }, 402 },
398 403
399 /** 404 /**
400 * See Subscription.serialize() 405 * See Subscription.serialize()
401 * @inheritdoc 406 * @inheritdoc
402 */ 407 */
403 *serialize() 408 *serialize()
404 { 409 {
405 let {_homepage, _lastDownload} = this; 410 let {_homepage, _lastDownload} = this;
411
406 yield* Subscription.prototype.serialize.call(this); 412 yield* Subscription.prototype.serialize.call(this);
413
407 if (_homepage) 414 if (_homepage)
408 yield "homepage=" + _homepage; 415 yield "homepage=" + _homepage;
409 if (_lastDownload) 416 if (_lastDownload)
410 yield "lastDownload=" + _lastDownload; 417 yield "lastDownload=" + _lastDownload;
411 } 418 }
412 }); 419 });
413 420
414 /** 421 /**
415 * Class for filter subscriptions updated externally (by other extension) 422 * Class for filter subscriptions updated externally (by other extension)
416 * @param {string} url see {@link Subscription Subscription()} 423 * @param {string} url see {@link Subscription Subscription()}
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 * @type {number} 556 * @type {number}
550 */ 557 */
551 downloadCount: 0, 558 downloadCount: 0,
552 559
553 /** 560 /**
554 * See Subscription.serialize() 561 * See Subscription.serialize()
555 * @inheritdoc 562 * @inheritdoc
556 */ 563 */
557 *serialize() 564 *serialize()
558 { 565 {
559 yield* RegularSubscription.prototype.serialize.call(this);
560
561 let {downloadStatus, lastSuccess, lastCheck, expires, 566 let {downloadStatus, lastSuccess, lastCheck, expires,
Manish Jethani 2018/10/14 20:05:36 Let's move this line to the top of the function bo
Jon Sonesen 2018/10/21 06:18:24 Done.
562 softExpiration, errors, version, requiredVersion, 567 softExpiration, errors, version, requiredVersion,
563 downloadCount} = this; 568 downloadCount} = this;
569
570 yield* RegularSubscription.prototype.serialize.call(this);
564 571
565 if (downloadStatus) 572 if (downloadStatus)
566 yield "downloadStatus=" + downloadStatus; 573 yield "downloadStatus=" + downloadStatus;
567 if (lastSuccess) 574 if (lastSuccess)
568 yield "lastSuccess=" + lastSuccess; 575 yield "lastSuccess=" + lastSuccess;
569 if (lastCheck) 576 if (lastCheck)
570 yield "lastCheck=" + lastCheck; 577 yield "lastCheck=" + lastCheck;
571 if (expires) 578 if (expires)
572 yield "expires=" + expires; 579 yield "expires=" + expires;
573 if (softExpiration) 580 if (softExpiration)
574 yield "softExpiration=" + softExpiration; 581 yield "softExpiration=" + softExpiration;
575 if (errors) 582 if (errors)
576 yield "errors=" + errors; 583 yield "errors=" + errors;
577 if (version) 584 if (version)
578 yield "version=" + version; 585 yield "version=" + version;
579 if (requiredVersion) 586 if (requiredVersion)
580 yield "requiredVersion=" + requiredVersion; 587 yield "requiredVersion=" + requiredVersion;
581 if (downloadCount) 588 if (downloadCount)
582 yield "downloadCount=" + downloadCount; 589 yield "downloadCount=" + downloadCount;
583 } 590 }
584 }); 591 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld