Bug 920337 - Use promise to ensure we don't miss project load. r=paul a=lsblakk
authorJ. Ryan Stinnett <jryans@gmail.com>
Tue, 24 Sep 2013 21:22:08 -0500
changeset 155549 8551e8776edee061011ade05b11d61419056af01
parent 155548 446c4bbfa38fadb29be5f862dec72a281207d4cc
child 155550 a02ef3b1129fc75d050a4e90a992fe7ee64bef35
push id4324
push userprouget@mozilla.com
push dateSat, 28 Sep 2013 16:05:55 +0000
treeherdermozilla-aurora@e3ca1451d061 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspaul, lsblakk
bugs920337
milestone26.0a2
Bug 920337 - Use promise to ensure we don't miss project load. r=paul a=lsblakk
browser/devtools/app-manager/app-projects.js
browser/devtools/app-manager/content/projects.js
--- a/browser/devtools/app-manager/app-projects.js
+++ b/browser/devtools/app-manager/app-projects.js
@@ -83,22 +83,29 @@ const IDB = {
     };
 
     return deferred.promise;
   }
 };
 
 const store = new ObservableObject({ projects:[] });
 
+let loadDeferred = promise.defer();
+
 IDB.open().then(function (projects) {
   store.object.projects = projects;
   AppProjects.emit("ready", store.object.projects);
+  loadDeferred.resolve();
 });
 
 const AppProjects = {
+  load: function() {
+    return loadDeferred.promise;
+  },
+
   addPackaged: function(folder) {
     let project = {
       type: "packaged",
       location: folder.path,
       // We need a unique id, that is the app origin,
       // in order to identify the app when being installed on the device.
       // The packaged app local path is a valid id, but only on the client.
       // This origin will be used to generate the true id of an app:
--- a/browser/devtools/app-manager/content/projects.js
+++ b/browser/devtools/app-manager/content/projects.js
@@ -34,20 +34,18 @@ window.addEventListener("message", funct
   } catch(e) {}
 }, false);
 
 let UI = {
   onload: function() {
     this.template = new Template(document.body, AppProjects.store, Utils.l10n);
     this.template.start();
 
-    AppProjects.store.on("set", (event,path,value) => {
-      if (path == "projects") {
-        AppProjects.store.object.projects.forEach(UI.validate);
-      }
+    AppProjects.load().then(() => {
+      AppProjects.store.object.projects.forEach(UI.validate);
     });
   },
 
   onNewConnection: function() {
     this.connection.on(Connection.Events.STATUS_CHANGED, () => this._onConnectionStatusChange());
     this._onConnectionStatusChange();
   },