Singleton manager uuid change observer

This commit is contained in:
Mo Bitar
2018-12-14 22:09:41 -06:00
parent dde857c4e1
commit f7dfec36f8
5 changed files with 18 additions and 10 deletions

View File

@@ -15,10 +15,6 @@ class AccountMenu {
$scope.formData = {mergeLocal: true, ephemeral: false};
// testing:
// $scope.formData.status = "Generating Login Keys...";
// $scope.formData.authenticating = true;
$scope.user = authManager.user;
syncManager.getServerURL().then((url) => {

View File

@@ -124,7 +124,6 @@ class PrivilegesManager {
if(!this.privileges.content.desktopPrivileges) {
this.privileges.content.desktopPrivileges = {};
}
console.log("Resolved existing privs", resolvedSingleton.uuid);
resolve(resolvedSingleton);
}, (valueCallback) => {
// Safe to create. Create and return object.
@@ -133,7 +132,6 @@ class PrivilegesManager {
privs.setDirty(true);
this.$rootScope.sync();
valueCallback(privs);
console.log("Creating new privs", privs.uuid);
resolve(privs);
});
});

View File

@@ -26,6 +26,20 @@ class SingletonManager {
this.resolveSingletons(modelManager.allItems, null, true);
})
/*
If an item alternates its uuid on registration, singletonHandlers might need to update
their local refernece to the object, since the object reference will change on uuid alternation
*/
modelManager.addModelUuidChangeObserver("singleton-manager", (oldModel, newModel) => {
for(var handler of this.singletonHandlers) {
if(handler.singleton && SFPredicate.ItemSatisfiesPredicates(newModel, handler.predicates)) {
// Reference is now invalid, calling resolveSingleton should update it
handler.singleton = null;
this.resolveSingletons([newModel]);
}
}
})
$rootScope.$on("sync:completed", (event, data) => {
// 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.