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

Side by Side Diff: lib/filterStorage.js

Issue 29339666: Issue 3915 - Dispatch filters.added consistently (Closed)
Patch Set: Created April 13, 2016, 7:44 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 * @param {Boolean} silent if true, no listeners will be triggered (to be use d when filter list is reloaded) 225 * @param {Boolean} silent if true, no listeners will be triggered (to be use d when filter list is reloaded)
226 */ 226 */
227 addFilter: function(filter, subscription, position, silent) 227 addFilter: function(filter, subscription, position, silent)
228 { 228 {
229 if (!subscription) 229 if (!subscription)
230 { 230 {
231 if (filter.subscriptions.some(s => s instanceof SpecialSubscription && !s. disabled)) 231 if (filter.subscriptions.some(s => s instanceof SpecialSubscription && !s. disabled))
232 return; // No need to add 232 return; // No need to add
233 subscription = FilterStorage.getGroupForFilter(filter); 233 subscription = FilterStorage.getGroupForFilter(filter);
234 } 234 }
235
235 if (!subscription) 236 if (!subscription)
236 { 237 {
237 // No group for this filter exists, create one 238 // No group for this filter exists, create one
238 subscription = SpecialSubscription.createForFilter(filter); 239 subscription = SpecialSubscription.createForFilter(filter);
239 this.addSubscription(subscription); 240 this.addSubscription(subscription);
240 return;
241 } 241 }
242 else
243 {
244 if (typeof position == "undefined")
245 position = subscription.filters.length;
242 246
243 if (typeof position == "undefined") 247 if (filter.subscriptions.indexOf(subscription) < 0)
244 position = subscription.filters.length; 248 filter.subscriptions.push(subscription);
245 249 subscription.filters.splice(position, 0, filter);
246 if (filter.subscriptions.indexOf(subscription) < 0) 250 }
247 filter.subscriptions.push(subscription);
248 subscription.filters.splice(position, 0, filter);
249 if (!silent) 251 if (!silent)
250 FilterNotifier.triggerListeners("filter.added", filter, subscription, posi tion); 252 FilterNotifier.triggerListeners("filter.added", filter, subscription, posi tion);
251 }, 253 },
252 254
253 /** 255 /**
254 * Removes a user-defined filter from the list 256 * Removes a user-defined filter from the list
255 * @param {Filter} filter 257 * @param {Filter} filter
256 * @param {SpecialSubscription} [subscription] a particular filter group that 258 * @param {SpecialSubscription} [subscription] a particular filter group that
257 * the filter should be removed from (if ommited will be removed from all subscriptions) 259 * the filter should be removed from (if ommited will be removed from all subscriptions)
258 * @param {Integer} [position] position inside the filter group at which the 260 * @param {Integer} [position] position inside the filter group at which the
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 Subscription.knownSubscriptions = origKnownSubscriptions; 793 Subscription.knownSubscriptions = origKnownSubscriptions;
792 } 794 }
793 795
794 // Allow events to be processed every now and then. 796 // Allow events to be processed every now and then.
795 // Note: IO.readFromFile() will deal with the potential reentrance here. 797 // Note: IO.readFromFile() will deal with the potential reentrance here.
796 this.linesProcessed++; 798 this.linesProcessed++;
797 if (this.linesProcessed % 1000 == 0) 799 if (this.linesProcessed % 1000 == 0)
798 Utils.yield(); 800 Utils.yield();
799 } 801 }
800 }; 802 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld