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

Delta Between Two Patch Sets: lib/subscriptionClasses.js

Issue 29934588: Issue 7094 - Encapsulate management of subscription filters (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Update JSDoc Created Nov. 18, 2018, 2:27 a.m.
Right Patch Set: Remove hasFilter and related code Created Nov. 18, 2018, 10:21 p.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/iniParser.js ('k') | lib/synchronizer.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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 * Type of the subscription 59 * Type of the subscription
60 * @type {?string} 60 * @type {?string}
61 */ 61 */
62 type: null, 62 type: null,
63 63
64 /** 64 /**
65 * Filter text contained in the filter subscription. 65 * Filter text contained in the filter subscription.
66 * @type {Array.<string>} 66 * @type {Array.<string>}
67 * @private 67 * @private
68 */ 68 */
69 _filterText: null, 69 _filterText: null,
hub 2018/11/19 17:47:49 shouldn't this be named `_filtersText` since it is
Manish Jethani 2018/11/20 00:19:39 I thought about calling it _filtersText but that s
hub 2018/11/20 19:30:19 my bad. let's leave it at that.
70 70
71 /** 71 /**
72 * {@link Filter} objects corresponding to the subscription's filter text. 72 * {@link Filter} objects corresponding to the subscription's filter text.
73 * @type {Array.<Filter>} 73 * @type {Array.<Filter>}
74 * @private 74 * @private
75 */ 75 */
76 _filters: null, 76 _filters: null,
77 77
78 /**
79 * Set of filter text contained in the filter subscription, used for faster
80 * lookup.
81 * @type {?Set.<string>}
82 * @private
83 */
84 _filterTextLookup: null,
85
86 _title: null, 78 _title: null,
87 _fixedTitle: false, 79 _fixedTitle: false,
88 _disabled: false, 80 _disabled: false,
89 81
90 /** 82 /**
91 * Title of the filter subscription 83 * Title of the filter subscription
92 * @type {string} 84 * @type {string}
93 */ 85 */
94 get title() 86 get title()
95 { 87 {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 * @param {Filter} filter 178 * @param {Filter} filter
187 * @param {number} [fromIndex] The index from which to start the search. 179 * @param {number} [fromIndex] The index from which to start the search.
188 * @return {number} 180 * @return {number}
189 */ 181 */
190 searchFilter(filter, fromIndex = 0) 182 searchFilter(filter, fromIndex = 0)
191 { 183 {
192 return this._filterText.indexOf(filter.text, fromIndex); 184 return this._filterText.indexOf(filter.text, fromIndex);
193 }, 185 },
194 186
195 /** 187 /**
196 * Checks whether the subscription contains the given filter.
197 * @param {Filter} filter
198 * @return {boolean}
199 */
200 hasFilter(filter)
201 {
202 if (!this._filterTextLookup)
203 this._filterTextLookup = new Set([...this._filterText]);
204
205 return this._filterTextLookup.has(filter.text);
206 },
207
208 /**
209 * Removes all filters from the subscription. 188 * Removes all filters from the subscription.
210 */ 189 */
211 clearFilters() 190 clearFilters()
212 { 191 {
213 this._filterText = []; 192 this._filterText = [];
214 this._filters = []; 193 this._filters = [];
215
216 this._filterTextLookup = null;
217 }, 194 },
218 195
219 /** 196 /**
220 * Adds a filter to the subscription. 197 * Adds a filter to the subscription.
221 * @param {Filter} filter 198 * @param {Filter} filter
222 */ 199 */
223 addFilter(filter) 200 addFilter(filter)
224 { 201 {
225 this._filterText.push(filter.text); 202 this._filterText.push(filter.text);
226 this._filters.push(filter); 203 this._filters.push(filter);
227
228 // Invalidate filter text lookup.
229 this._filterTextLookup = null;
230 }, 204 },
231 205
232 /** 206 /**
233 * Inserts a filter into the subscription. 207 * Inserts a filter into the subscription.
234 * @param {Filter} filter 208 * @param {Filter} filter
235 * @param {number} index The index at which to insert the filter. 209 * @param {number} index The index at which to insert the filter.
236 */ 210 */
237 insertFilterAt(filter, index) 211 insertFilterAt(filter, index)
238 { 212 {
239 this._filterText.splice(index, 0, filter.text); 213 this._filterText.splice(index, 0, filter.text);
240 this._filters.splice(index, 0, filter); 214 this._filters.splice(index, 0, filter);
241
242 this._filterTextLookup = null;
243 }, 215 },
244 216
245 /** 217 /**
246 * Deletes a filter from the subscription. 218 * Deletes a filter from the subscription.
247 * @param {number} index The index at which to delete the filter. 219 * @param {number} index The index at which to delete the filter.
248 */ 220 */
249 deleteFilterAt(index) 221 deleteFilterAt(index)
250 { 222 {
251 // Ignore index if out of bounds on the negative side, for consistency. 223 // Ignore index if out of bounds on the negative side, for consistency.
252 if (index < 0) 224 if (index < 0)
253 return; 225 return;
254 226
255 this._filterText.splice(index, 1); 227 this._filterText.splice(index, 1);
256 this._filters.splice(index, 1); 228 this._filters.splice(index, 1);
257
258 this._filterTextLookup = null;
259 },
260
261 /**
262 * Clears any in-memory caches held by the object.
263 * @package
264 */
265 clearCaches()
266 {
267 this._filterTextLookup = null;
268 }, 229 },
269 230
270 /** 231 /**
271 * Serializes the subscription for writing out on disk. 232 * Serializes the subscription for writing out on disk.
272 * @yields {string} 233 * @yields {string}
273 */ 234 */
274 *serialize() 235 *serialize()
275 { 236 {
276 let {url, type, _title, _fixedTitle, _disabled} = this; 237 let {url, type, _title, _fixedTitle, _disabled} = this;
277 238
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 if (errors) 686 if (errors)
726 yield "errors=" + errors; 687 yield "errors=" + errors;
727 if (version) 688 if (version)
728 yield "version=" + version; 689 yield "version=" + version;
729 if (requiredVersion) 690 if (requiredVersion)
730 yield "requiredVersion=" + requiredVersion; 691 yield "requiredVersion=" + requiredVersion;
731 if (downloadCount) 692 if (downloadCount)
732 yield "downloadCount=" + downloadCount; 693 yield "downloadCount=" + downloadCount;
733 } 694 }
734 }); 695 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld