From 711fdc061c14e6399018baa03f39eee0e16019ad Mon Sep 17 00:00:00 2001 From: Mo Bitar Date: Thu, 20 Dec 2018 10:17:34 -0600 Subject: [PATCH] Wait for initial data load before resolving singletons --- app/assets/javascripts/app/services/singletonManager.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/assets/javascripts/app/services/singletonManager.js b/app/assets/javascripts/app/services/singletonManager.js index ddee5b64a..6c4ce588b 100644 --- a/app/assets/javascripts/app/services/singletonManager.js +++ b/app/assets/javascripts/app/services/singletonManager.js @@ -24,6 +24,7 @@ class SingletonManager { $rootScope.$on("initial-data-loaded", (event, data) => { this.resolveSingletons(modelManager.allItems, null, true); + this.initialDataLoaded = true; }) /* @@ -41,6 +42,11 @@ class SingletonManager { }) $rootScope.$on("sync:completed", (event, data) => { + // Wait for initial data load before handling any sync. If we don't want for initial data load, + // then the singleton resolver won't have the proper items to work with to determine whether to resolve or create. + if(!this.initialDataLoaded) { + return; + } // The reason we also need to consider savedItems in consolidating singletons is in case of sync conflicts, // a new item can be created, but is never processed through "retrievedItems" since it is only created locally then saved.