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

Side by Side Diff: lib/filterStorage.js

Issue 29900557: Issue 7016 - Convert serialization functions into generators (Closed)
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:
View unified diff | Download patch
« no previous file with comments | « lib/filterClasses.js ('k') | lib/subscriptionClasses.js » ('j') | 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-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 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 subscription.filters.length == 0)) 479 subscription.filters.length == 0))
480 { 480 {
481 subscriptions.push(subscription); 481 subscriptions.push(subscription);
482 } 482 }
483 } 483 }
484 484
485 yield "# Adblock Plus preferences"; 485 yield "# Adblock Plus preferences";
486 yield "version=" + this.formatVersion; 486 yield "version=" + this.formatVersion;
487 487
488 let saved = new Set(); 488 let saved = new Set();
489 let buf = [];
490 489
491 // Save subscriptions 490 // Save subscriptions
492 for (let subscription of subscriptions) 491 for (let subscription of subscriptions)
493 { 492 {
494 yield ""; 493 yield* subscription.serialize();
495 494 yield* subscription.serializeFilters();
496 subscription.serialize(buf);
497 if (subscription.filters.length)
498 {
499 buf.push("", "[Subscription filters]");
500 subscription.serializeFilters(buf);
501 }
502 for (let line of buf)
503 yield line;
504 buf.splice(0);
505 } 495 }
506 496
507 // Save filter data 497 // Save filter data
508 for (let subscription of subscriptions) 498 for (let subscription of subscriptions)
509 { 499 {
510 for (let filter of subscription.filters) 500 for (let filter of subscription.filters)
511 { 501 {
512 if (!saved.has(filter.text)) 502 if (!saved.has(filter.text))
513 { 503 {
514 filter.serialize(buf); 504 yield* filter.serialize();
515 saved.add(filter.text); 505 saved.add(filter.text);
516 for (let line of buf)
517 yield line;
518 buf.splice(0);
519 } 506 }
520 } 507 }
521 } 508 }
522 } 509 }
523 510
524 /** 511 /**
525 * Saves all subscriptions back to disk. 512 * Saves all subscriptions back to disk.
526 * @returns {Promise} A promise resolved or rejected when saving is complete. 513 * @returns {Promise} A promise resolved or rejected when saving is complete.
527 */ 514 */
528 saveToDisk() 515 saveToDisk()
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 * disconnected from its filters. 663 * disconnected from its filters.
677 */ 664 */
678 function disconnectSubscriptionFilters(subscription) 665 function disconnectSubscriptionFilters(subscription)
679 { 666 {
680 if (!filterStorage.knownSubscriptions.has(subscription.url)) 667 if (!filterStorage.knownSubscriptions.has(subscription.url))
681 return; 668 return;
682 669
683 for (let filter of subscription.filters) 670 for (let filter of subscription.filters)
684 filter.removeSubscription(subscription); 671 filter.removeSubscription(subscription);
685 } 672 }
OLDNEW
« no previous file with comments | « lib/filterClasses.js ('k') | lib/subscriptionClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld