fixed corner cases in becca updates from sync

This commit is contained in:
zadam 2021-07-22 20:19:44 +02:00
parent 89d28ef27c
commit f9cfd134b7
3 changed files with 23 additions and 11 deletions

View File

@ -60,25 +60,31 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_CHANGE_
} }
}); });
eventService.subscribe([eventService.ENTITY_DELETED, eventService.ENTITY_DELETE_SYNCED], ({entityName, entity}) => { eventService.subscribe([eventService.ENTITY_DELETED, eventService.ENTITY_DELETE_SYNCED], ({entityName, entityId}) => {
if (!becca.loaded) { if (!becca.loaded) {
return; return;
} }
if (entityName === 'notes') { if (entityName === 'notes') {
noteDeleted(entity); noteDeleted(entityId);
} else if (entityName === 'branches') { } else if (entityName === 'branches') {
branchDeleted(entity); branchDeleted(entityId);
} else if (entityName === 'attributes') { } else if (entityName === 'attributes') {
attributeDeleted(entity); attributeDeleted(entityId);
} }
}); });
function noteDeleted(note) { function noteDeleted(noteId) {
delete becca.notes[note.noteId]; delete becca.notes[noteId];
}
function branchDeleted(branchId) {
const branch = becca.branches[branchId];
if (!branch) {
return;
} }
function branchDeleted(branch) {
const childNote = becca.notes[branch.noteId]; const childNote = becca.notes[branch.noteId];
if (childNote) { if (childNote) {
@ -110,7 +116,13 @@ function branchUpdated(branch) {
} }
} }
function attributeDeleted(attribute) { function attributeDeleted(attributeId) {
const attribute = becca.attributes[attributeId];
if (!attribute) {
return;
}
const note = becca.notes[attribute.noteId]; const note = becca.notes[attribute.noteId];
if (note) { if (note) {

View File

@ -110,7 +110,7 @@ class AbstractEntity {
this.addEntityChange(true); this.addEntityChange(true);
eventService.emit(eventService.ENTITY_DELETED, { entityName, entity: this }); eventService.emit(eventService.ENTITY_DELETED, { entityName, entityId, entity: this });
} }
} }

View File

@ -26,14 +26,14 @@ function updateEntity(entityChange, entity) {
? updateNoteReordering(entityChange, entity) ? updateNoteReordering(entityChange, entity)
: updateNormalEntity(entityChange, entity); : updateNormalEntity(entityChange, entity);
if (updated && !entityChange.isErased) { if (updated) {
if (entity.isDeleted) { if (entity.isDeleted) {
eventService.emit(eventService.ENTITY_DELETE_SYNCED, { eventService.emit(eventService.ENTITY_DELETE_SYNCED, {
entityName: entityChange.entityName, entityName: entityChange.entityName,
entityId: entityChange.entityId entityId: entityChange.entityId
}); });
} }
else { else if (!entityChange.isErased) {
eventService.emit(eventService.ENTITY_CHANGE_SYNCED, { eventService.emit(eventService.ENTITY_CHANGE_SYNCED, {
entityName: entityChange.entityName, entityName: entityChange.entityName,
entity entity