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

Unified Diff: background.js

Issue 29333533: Issue 3515 - Replace Prefs.onLoaded event by Prefs.isLoaded promise (Closed)
Patch Set: Created Jan. 14, 2016, 5:29 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/prefs.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: background.js
===================================================================
--- a/background.js
+++ b/background.js
@@ -59,14 +59,21 @@
function init()
{
- var filtersLoaded = false;
- var prefsLoaded = false;
+ var filtersLoaded = new Promise(function(resolve)
+ {
+ function onFilterAction(action)
+ {
+ if (action == "load")
+ {
+ FilterNotifier.removeListener(onFilterAction);
+ resolve();
+ }
+ }
+ FilterNotifier.addListener(onFilterAction);
+ });
- var checkLoaded = function()
+ function onLoaded()
{
- if (!filtersLoaded || !prefsLoaded)
- return;
-
var info = require("info");
var previousVersion = Prefs.currentVersion;
@@ -95,27 +102,9 @@
refreshIconAndContextMenuForAllPages();
});
refreshIconAndContextMenuForAllPages();
- };
+ }
- var onFilterAction = function(action)
- {
- if (action == "load")
- {
- FilterNotifier.removeListener(onFilterAction);
- filtersLoaded = true;
- checkLoaded();
- }
- };
-
- var onPrefsLoaded = function()
- {
- Prefs.onLoaded.removeListener(onPrefsLoaded);
- prefsLoaded = true;
- checkLoaded();
- };
-
- FilterNotifier.addListener(onFilterAction);
- Prefs.onLoaded.addListener(onPrefsLoaded);
+ Promise.all([filtersLoaded, Prefs.isLoaded]).then(onLoaded);
}
init();
« no previous file with comments | « no previous file | lib/prefs.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld