Sync duplication ability to ignore keys

This commit is contained in:
Mo Bitar
2018-01-23 11:57:57 -06:00
parent e330c273a8
commit 87b178199a
3 changed files with 25 additions and 1 deletions

View File

@@ -185,7 +185,27 @@ class Item {
return this.getAppDataItem("archived");
}
/*
During sync conflicts, when determing whether to create a duplicate for an item, we can omit keys that have no
meaningful weight and can be ignored. For example, if one component has active = true and another component has active = false,
it would be silly to duplicate them, so instead we ignore this.
*/
keysToIgnoreWhenCheckingContentEquality() {
return [];
}
isItemContentEqualWith(otherItem) {
let omit = (obj, keys) => {
for(var key of keys) {
delete obj[key];
}
return obj;
}
var left = omit(this.structureParams(), this.keysToIgnoreWhenCheckingContentEquality());
var right = omit(otherItem.structureParams(), otherItem.keysToIgnoreWhenCheckingContentEquality());
return JSON.stringify(left) === JSON.stringify(right)
}
/*
Dates

View File

@@ -96,6 +96,10 @@ class Component extends Item {
return this.getAppDataItem("lastSize");
}
keysToIgnoreWhenCheckingContentEquality() {
return ["active"].concat(super.keysToIgnoreWhenCheckingContentEquality());
}
/*
An associative component depends on being explicitly activated for a given item, compared to a dissaciative component,

View File

@@ -434,7 +434,7 @@ class SyncManager {
itemResponse.uuid = null;
var dup = this.modelManager.createDuplicateItem(itemResponse, item);
if(!itemResponse.deleted && JSON.stringify(item.structureParams()) !== JSON.stringify(dup.structureParams())) {
if(!itemResponse.deleted && !item.isItemContentEqualWith(dup)) {
this.modelManager.addItem(dup);
dup.conflict_of = item.uuid;
dup.setDirty(true);