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 PS4 Comments Created Oct. 22, 2018, 7:28 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 for writing 128 * Serializes the subscription for writing out on disk.
Manish Jethani 2018/10/22 20:18:01 Nit: We could wrap this.
Jon Sonesen 2018/10/22 22:59:36 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 let {filters} = this; 150 let {filters} = this;
152 151
153 yield "[Subscription filters]"; 152 yield "[Subscription filters]";
153
154 for (let filter of filters) 154 for (let filter of filters)
155 yield filter.text.replace(/\[/g, "\\["); 155 yield filter.text.replace(/\[/g, "\\[");
156 }, 156 },
157 157
158 toString() 158 toString()
159 { 159 {
160 return [...this.serialize()].join("\n"); 160 return [...this.serialize()].join("\n");
Jon Sonesen 2018/10/22 22:59:36 This may be unrelated, but I was reading about how
Manish Jethani 2018/10/22 23:01:29 I don't know (where is this method called?), but I
Jon Sonesen 2018/10/23 02:04:24 Acknowledged.
161 } 161 }
162 }; 162 };
163 163
164 /** 164 /**
165 * Cache for known filter subscriptions, maps URL to subscription objects. 165 * Cache for known filter subscriptions, maps URL to subscription objects.
166 * @type {Map.<string,Subscription>} 166 * @type {Map.<string,Subscription>}
167 */ 167 */
168 Subscription.knownSubscriptions = new Map(); 168 Subscription.knownSubscriptions = new Map();
169 169
170 /** 170 /**
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 /** 284 /**
285 * See Subscription.serialize() 285 * See Subscription.serialize()
286 * @inheritdoc 286 * @inheritdoc
287 */ 287 */
288 *serialize() 288 *serialize()
289 { 289 {
290 let {defaults, _lastDownload} = this; 290 let {defaults, _lastDownload} = this;
291 291
292 yield* Subscription.prototype.serialize.call(this); 292 yield* Subscription.prototype.serialize.call(this);
293 293
294 if (defaults && defaults.length) 294 if (defaults)
295 { 295 {
296 yield "defaults=" + 296 yield "defaults=" +
297 defaults.filter( 297 defaults.filter(
298 type => SpecialSubscription.defaultsMap.has(type) 298 type => SpecialSubscription.defaultsMap.has(type)
299 ).join(" "); 299 ).join(" ");
300 } 300 }
301 if (_lastDownload) 301 if (_lastDownload)
302 yield "lastDownload=" + _lastDownload; 302 yield "lastDownload=" + _lastDownload;
303 } 303 }
304 }); 304 });
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 if (errors) 582 if (errors)
583 yield "errors=" + errors; 583 yield "errors=" + errors;
584 if (version) 584 if (version)
585 yield "version=" + version; 585 yield "version=" + version;
586 if (requiredVersion) 586 if (requiredVersion)
587 yield "requiredVersion=" + requiredVersion; 587 yield "requiredVersion=" + requiredVersion;
588 if (downloadCount) 588 if (downloadCount)
589 yield "downloadCount=" + downloadCount; 589 yield "downloadCount=" + downloadCount;
590 } 590 }
591 }); 591 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld