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: Address PS4 Comments Created Oct. 22, 2018, 7:28 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
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
496 subscription.serialize(buf);
497 if (subscription.filters.length) 495 if (subscription.filters.length)
Manish Jethani 2018/10/22 20:18:01 We don't really need this check, as I said in my p
Jon Sonesen 2018/10/22 22:59:36 My bad, I'll fix it
498 { 496 {
499 buf.push("", "[Subscription filters]"); 497 yield* subscription.serializeFilters();
500 subscription.serializeFilters(buf);
501 } 498 }
502 for (let line of buf)
503 yield line;
504 buf.splice(0);
505 } 499 }
506 500
507 // Save filter data 501 // Save filter data
508 for (let subscription of subscriptions) 502 for (let subscription of subscriptions)
509 { 503 {
510 for (let filter of subscription.filters) 504 for (let filter of subscription.filters)
511 { 505 {
512 if (!saved.has(filter.text)) 506 if (!saved.has(filter.text))
513 { 507 {
514 filter.serialize(buf); 508 yield* filter.serialize();
515 saved.add(filter.text); 509 saved.add(filter.text);
516 for (let line of buf)
517 yield line;
518 buf.splice(0);
519 } 510 }
520 } 511 }
521 } 512 }
522 } 513 }
523 514
524 /** 515 /**
525 * Saves all subscriptions back to disk. 516 * Saves all subscriptions back to disk.
526 * @returns {Promise} A promise resolved or rejected when saving is complete. 517 * @returns {Promise} A promise resolved or rejected when saving is complete.
527 */ 518 */
528 saveToDisk() 519 saveToDisk()
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 * disconnected from its filters. 667 * disconnected from its filters.
677 */ 668 */
678 function disconnectSubscriptionFilters(subscription) 669 function disconnectSubscriptionFilters(subscription)
679 { 670 {
680 if (!filterStorage.knownSubscriptions.has(subscription.url)) 671 if (!filterStorage.knownSubscriptions.has(subscription.url))
681 return; 672 return;
682 673
683 for (let filter of subscription.filters) 674 for (let filter of subscription.filters)
684 filter.removeSubscription(subscription); 675 filter.removeSubscription(subscription);
685 } 676 }
OLDNEW
« no previous file with comments | « lib/filterClasses.js ('k') | lib/subscriptionClasses.js » ('j') | lib/subscriptionClasses.js » ('J')

Powered by Google App Engine
This is Rietveld