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

Delta Between Two Patch Sets: lib/init.js

Issue 10802049: Functional prefs implementation (Closed)
Left Patch Set: Created June 5, 2013, 9:03 a.m.
Right Patch Set: Cleaned up init.js a bit Created June 5, 2013, 9:44 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/api.js ('k') | lib/prefs.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 var _prefsInitDone = false; 1 let {Prefs} = require("prefs");
2 var _filtersInitDone = false; 2 let {FilterNotifier} = require("filterNotifier");
3 3
4 require("prefs").Prefs._initListener = function() 4 let prefsInitDone = false;
5 let filtersInitDone = false;
6
7 function checkInitialized()
5 { 8 {
6 _prefsInitDone = true; 9 if (prefsInitDone && filtersInitDone)
7 _checkInitialized();
8 };
9
10 function _checkInitialized()
11 {
12 if (_prefsInitDone && _filtersInitDone)
13 { 10 {
14 _checkInitialized = function() {}; 11 checkInitialized = function() {};
15 _triggerEvent("init"); 12 _triggerEvent("init");
16 } 13 }
17 } 14 }
18 15
19 require("filterNotifier").FilterNotifier.addListener(function(action) 16 Prefs._initListener = function()
17 {
18 prefsInitDone = true;
19 checkInitialized();
20 };
21
22 FilterNotifier.addListener(function(action)
20 { 23 {
21 if (action === "load") 24 if (action === "load")
22 { 25 {
23 let {FilterStorage} = require("filterStorage"); 26 let {FilterStorage} = require("filterStorage");
24 if (FilterStorage.subscriptions.length == 0) 27 if (FilterStorage.subscriptions.length == 0)
25 { 28 {
26 // No data, must be a new user or someone with corrupted data - initialize 29 // No data, must be a new user or someone with corrupted data - initialize
27 // with default settings 30 // with default settings
28 let {Subscription, DownloadableSubscription} = require("subscriptionClasse s"); 31 let {Subscription, DownloadableSubscription} = require("subscriptionClasse s");
29 let {Synchronizer} = require("synchronizer"); 32 let {Synchronizer} = require("synchronizer");
30 let {Prefs} = require("prefs"); 33 let {Prefs} = require("prefs");
31 let {Utils} = require("utils"); 34 let {Utils} = require("utils");
32 35
33 // Choose default subscription and add it 36 // Choose default subscription and add it
34 let subscriptions = require("subscriptions.xml"); 37 let subscriptions = require("subscriptions.xml");
35 let node = Utils.chooseFilterSubscription(subscriptions); 38 let node = Utils.chooseFilterSubscription(subscriptions);
36 if (node) 39 if (node)
37 { 40 {
38 let subscription = Subscription.fromURL(node.url); 41 let subscription = Subscription.fromURL(node.url);
39 FilterStorage.addSubscription(subscription); 42 FilterStorage.addSubscription(subscription);
40 subscription.disabled = false; 43 subscription.disabled = false;
41 subscription.title = node.title; 44 subscription.title = node.title;
42 subscription.homepage = node.homepage; 45 subscription.homepage = node.homepage;
43 if (subscription instanceof DownloadableSubscription && !subscription.la stDownload) 46 if (subscription instanceof DownloadableSubscription && !subscription.la stDownload)
44 Synchronizer.execute(subscription); 47 Synchronizer.execute(subscription);
45 } 48 }
46 } 49 }
47 50
48 _filtersInitDone = true; 51 filtersInitDone = true;
49 _checkInitialized(); 52 checkInitialized();
50 } 53 }
51 }); 54 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld