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

Side by Side Diff: lib/init.js

Issue 10802049: Functional prefs implementation (Closed)
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:
View unified diff | Download patch
OLDNEW
1 require("filterNotifier").FilterNotifier.addListener(function(action) 1 let {Prefs} = require("prefs");
2 let {FilterNotifier} = require("filterNotifier");
3
4 let prefsInitDone = false;
5 let filtersInitDone = false;
6
7 function checkInitialized()
8 {
9 if (prefsInitDone && filtersInitDone)
10 {
11 checkInitialized = function() {};
12 _triggerEvent("init");
13 }
14 }
15
16 Prefs._initListener = function()
17 {
18 prefsInitDone = true;
19 checkInitialized();
20 };
21
22 FilterNotifier.addListener(function(action)
2 { 23 {
3 if (action === "load") 24 if (action === "load")
4 { 25 {
5 let {FilterStorage} = require("filterStorage"); 26 let {FilterStorage} = require("filterStorage");
6 if (FilterStorage.subscriptions.length == 0) 27 if (FilterStorage.subscriptions.length == 0)
7 { 28 {
8 // 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
9 // with default settings 30 // with default settings
10 let {Subscription, DownloadableSubscription} = require("subscriptionClasse s"); 31 let {Subscription, DownloadableSubscription} = require("subscriptionClasse s");
11 let {Synchronizer} = require("synchronizer"); 32 let {Synchronizer} = require("synchronizer");
12 let {Prefs} = require("prefs"); 33 let {Prefs} = require("prefs");
13 let {Utils} = require("utils"); 34 let {Utils} = require("utils");
14 35
15 // Choose default subscription and add it 36 // Choose default subscription and add it
16 let subscriptions = require("subscriptions.xml"); 37 let subscriptions = require("subscriptions.xml");
17 let node = Utils.chooseFilterSubscription(subscriptions); 38 let node = Utils.chooseFilterSubscription(subscriptions);
18 if (node) 39 if (node)
19 { 40 {
20 let subscription = Subscription.fromURL(node.url); 41 let subscription = Subscription.fromURL(node.url);
21 FilterStorage.addSubscription(subscription); 42 FilterStorage.addSubscription(subscription);
22 subscription.disabled = false; 43 subscription.disabled = false;
23 subscription.title = node.title; 44 subscription.title = node.title;
24 subscription.homepage = node.homepage; 45 subscription.homepage = node.homepage;
25 if (subscription instanceof DownloadableSubscription && !subscription.la stDownload) 46 if (subscription instanceof DownloadableSubscription && !subscription.la stDownload)
26 Synchronizer.execute(subscription); 47 Synchronizer.execute(subscription);
27 } 48 }
28 } 49 }
29 50
30 _triggerEvent("init"); 51 filtersInitDone = true;
52 checkInitialized();
31 } 53 }
32 }); 54 });
OLDNEW

Powered by Google App Engine
This is Rietveld