More explicit variable names and comments for synced items
This commit is contained in:
@@ -28,12 +28,12 @@ class ComponentManager {
|
|||||||
this.handleMessage(this.componentForSessionKey(event.data.sessionKey), event.data);
|
this.handleMessage(this.componentForSessionKey(event.data.sessionKey), event.data);
|
||||||
}.bind(this), false);
|
}.bind(this), false);
|
||||||
|
|
||||||
this.modelManager.addItemSyncObserver("component-manager", "*", function(items) {
|
this.modelManager.addItemSyncObserver("component-manager", "*", function(allItems, validItems, deletedItems) {
|
||||||
|
|
||||||
var syncedComponents = items.filter(function(item){return item.content_type === "SN|Component" });
|
var syncedComponents = allItems.filter(function(item){return item.content_type === "SN|Component" });
|
||||||
for(var component of syncedComponents) {
|
for(var component of syncedComponents) {
|
||||||
var activeComponent = _.find(this.activeComponents, {uuid: component.uuid});
|
var activeComponent = _.find(this.activeComponents, {uuid: component.uuid});
|
||||||
if(component.active && !activeComponent) {
|
if(component.active && !component.deleted && !activeComponent) {
|
||||||
this.activateComponent(component);
|
this.activateComponent(component);
|
||||||
} else if(!component.active && activeComponent) {
|
} else if(!component.active && activeComponent) {
|
||||||
this.deactivateComponent(component);
|
this.deactivateComponent(component);
|
||||||
@@ -41,7 +41,7 @@ class ComponentManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(let observer of this.streamObservers) {
|
for(let observer of this.streamObservers) {
|
||||||
var relevantItems = items.filter(function(item){
|
var relevantItems = allItems.filter(function(item){
|
||||||
return observer.contentTypes.indexOf(item.content_type) !== -1;
|
return observer.contentTypes.indexOf(item.content_type) !== -1;
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ class ComponentManager {
|
|||||||
}
|
}
|
||||||
var itemInContext = handler.contextRequestHandler(observer.component);
|
var itemInContext = handler.contextRequestHandler(observer.component);
|
||||||
if(itemInContext) {
|
if(itemInContext) {
|
||||||
var matchingItem = _.find(items, {uuid: itemInContext.uuid});
|
var matchingItem = _.find(allItems, {uuid: itemInContext.uuid});
|
||||||
if(matchingItem) {
|
if(matchingItem) {
|
||||||
this.sendContextItemInReply(observer.component, matchingItem, observer.originalMessage);
|
this.sendContextItemInReply(observer.component, matchingItem, observer.originalMessage);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ class ExtensionManager {
|
|||||||
this.syncManager = syncManager;
|
this.syncManager = syncManager;
|
||||||
this.storageManager = storageManager;
|
this.storageManager = storageManager;
|
||||||
|
|
||||||
modelManager.addItemSyncObserver("extensionManager", "Extension", function(items){
|
modelManager.addItemSyncObserver("extensionManager", "Extension", function(allItems, validItems, deletedItems){
|
||||||
for (var ext of items) {
|
for (var ext of validItems) {
|
||||||
for (var action of ext.actions) {
|
for (var action of ext.actions) {
|
||||||
if(_.includes(this.enabledRepeatActionUrls, action.url)) {
|
if(_.includes(this.enabledRepeatActionUrls, action.url)) {
|
||||||
this.enableRepeatAction(action, ext);
|
this.enableRepeatAction(action, ext);
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ class ModelManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mapResponseItemsToLocalModelsOmittingFields(items, omitFields) {
|
mapResponseItemsToLocalModelsOmittingFields(items, omitFields) {
|
||||||
var models = [], processedObjects = [], allModels = [];
|
var models = [], processedObjects = [], modelsToNotifyObserversOf = [];
|
||||||
|
|
||||||
// first loop should add and process items
|
// first loop should add and process items
|
||||||
for (var json_obj of items) {
|
for (var json_obj of items) {
|
||||||
@@ -125,10 +125,11 @@ class ModelManager {
|
|||||||
console.error("Content is missing for new item.", json_obj);
|
console.error("Content is missing for new item.", json_obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(json_obj.deleted == true || !_.includes(this.acceptableContentTypes, json_obj["content_type"])) {
|
var unknownContentType = !_.includes(this.acceptableContentTypes, json_obj["content_type"]);
|
||||||
if(item) {
|
if(json_obj.deleted == true || unknownContentType) {
|
||||||
allModels.push(item);
|
if(item && !unknownContentType) {
|
||||||
this.removeItemLocally(item)
|
modelsToNotifyObserversOf.push(item);
|
||||||
|
this.removeItemLocally(item);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -139,7 +140,7 @@ class ModelManager {
|
|||||||
|
|
||||||
this.addItem(item);
|
this.addItem(item);
|
||||||
|
|
||||||
allModels.push(item);
|
modelsToNotifyObserversOf.push(item);
|
||||||
models.push(item);
|
models.push(item);
|
||||||
processedObjects.push(json_obj);
|
processedObjects.push(json_obj);
|
||||||
}
|
}
|
||||||
@@ -152,16 +153,25 @@ class ModelManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.notifySyncObserversOfModels(allModels);
|
this.notifySyncObserversOfModels(modelsToNotifyObserversOf);
|
||||||
|
|
||||||
return models;
|
return models;
|
||||||
}
|
}
|
||||||
|
|
||||||
notifySyncObserversOfModels(models) {
|
notifySyncObserversOfModels(models) {
|
||||||
for(var observer of this.itemSyncObservers) {
|
for(var observer of this.itemSyncObservers) {
|
||||||
var relevantItems = models.filter(function(item){return item.content_type == observer.type || observer.type == "*"});
|
var allRelevantItems = models.filter(function(item){return item.content_type == observer.type || observer.type == "*"});
|
||||||
if(relevantItems.length > 0) {
|
var validItems = [], deletedItems = [];
|
||||||
observer.callback(relevantItems);
|
for(var item of allRelevantItems) {
|
||||||
|
if(item.deleted) {
|
||||||
|
deletedItems.push(item);
|
||||||
|
} else {
|
||||||
|
validItems.push(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(allRelevantItems.length > 0) {
|
||||||
|
observer.callback(allRelevantItems, validItems, deletedItems);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -265,16 +265,25 @@ class SyncManager {
|
|||||||
|
|
||||||
this.$rootScope.$broadcast("sync:updated_token", this.syncToken);
|
this.$rootScope.$broadcast("sync:updated_token", this.syncToken);
|
||||||
|
|
||||||
var retrieved = this.handleItemsResponse(response.retrieved_items, null);
|
// Map retrieved items to local data
|
||||||
|
var retrieved
|
||||||
|
= this.handleItemsResponse(response.retrieved_items, null);
|
||||||
|
|
||||||
|
// Append items to master list of retrieved items for this ongoing sync operation
|
||||||
this.allRetreivedItems = this.allRetreivedItems.concat(retrieved);
|
this.allRetreivedItems = this.allRetreivedItems.concat(retrieved);
|
||||||
|
|
||||||
// merge only metadata for saved items
|
// Merge only metadata for saved items
|
||||||
// we write saved items to disk now because it clears their dirty status then saves
|
// we write saved items to disk now because it clears their dirty status then saves
|
||||||
// if we saved items before completion, we had have to save them as dirty and save them again on success as clean
|
// if we saved items before completion, we had have to save them as dirty and save them again on success as clean
|
||||||
var omitFields = ["content", "auth_hash"];
|
var omitFields = ["content", "auth_hash"];
|
||||||
var saved = this.handleItemsResponse(response.saved_items, omitFields);
|
|
||||||
|
|
||||||
|
// Map saved items to local data
|
||||||
|
var saved =
|
||||||
|
this.handleItemsResponse(response.saved_items, omitFields);
|
||||||
|
|
||||||
|
// Create copies of items or alternate their uuids if neccessary
|
||||||
this.handleUnsavedItemsResponse(response.unsaved)
|
this.handleUnsavedItemsResponse(response.unsaved)
|
||||||
|
|
||||||
this.writeItemsToLocalStorage(saved, false, null);
|
this.writeItemsToLocalStorage(saved, false, null);
|
||||||
|
|
||||||
this.syncStatus.syncOpInProgress = false;
|
this.syncStatus.syncOpInProgress = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user