From 635f5fdc5b34aebd38dafffcfbbc8c19850466aa Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 26 Aug 2021 22:10:59 +0200 Subject: [PATCH] small refactoring --- src/becca/becca_loader.js | 10 +++++----- src/services/sync_update.js | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/becca/becca_loader.js b/src/becca/becca_loader.js index c7281e41a..4f2b248f5 100644 --- a/src/becca/becca_loader.js +++ b/src/becca/becca_loader.js @@ -60,7 +60,7 @@ function postProcessEntityUpdate(entityName, entity) { } } -eventService.subscribe([eventService.ENTITY_CHANGE_SYNCED], ({entityName, entity}) => { +eventService.subscribe([eventService.ENTITY_CHANGE_SYNCED], ({entityName, entityRow}) => { if (!becca.loaded) { return; } @@ -69,18 +69,18 @@ eventService.subscribe([eventService.ENTITY_CHANGE_SYNCED], ({entityName, entit const EntityClass = entityConstructor.getEntityFromEntityName(entityName); const primaryKeyName = EntityClass.primaryKeyName; - let beccaEntity = becca.getEntity(entityName, entity[primaryKeyName]); + let beccaEntity = becca.getEntity(entityName, entityRow[primaryKeyName]); if (beccaEntity) { - beccaEntity.updateFromRow(entity); + beccaEntity.updateFromRow(entityRow); } else { beccaEntity = new EntityClass(); - beccaEntity.updateFromRow(entity); + beccaEntity.updateFromRow(entityRow); beccaEntity.init(); } } - postProcessEntityUpdate(entityName, entity); + postProcessEntityUpdate(entityName, entityRow); }); eventService.subscribe(eventService.ENTITY_CHANGED, ({entityName, entity}) => { diff --git a/src/services/sync_update.js b/src/services/sync_update.js index 6c48ab913..bf181bf43 100644 --- a/src/services/sync_update.js +++ b/src/services/sync_update.js @@ -4,9 +4,9 @@ const entityChangesService = require('./entity_changes'); const eventService = require('./events'); const entityConstructor = require("../becca/entity_constructor"); -function updateEntity(entityChange, entity) { +function updateEntity(entityChange, entityRow) { // can be undefined for options with isSynced=false - if (!entity) { + if (!entityRow) { if (entityChange.isSynced) { if (entityChange.isErased) { entityChangesService.addEntityChange(entityChange); @@ -23,11 +23,11 @@ function updateEntity(entityChange, entity) { } const updated = entityChange.entityName === 'note_reordering' - ? updateNoteReordering(entityChange, entity) - : updateNormalEntity(entityChange, entity); + ? updateNoteReordering(entityChange, entityRow) + : updateNormalEntity(entityChange, entityRow); if (updated) { - if (entity.isDeleted) { + if (entityRow.isDeleted) { eventService.emit(eventService.ENTITY_DELETE_SYNCED, { entityName: entityChange.entityName, entityId: entityChange.entityId @@ -36,7 +36,7 @@ function updateEntity(entityChange, entity) { else if (!entityChange.isErased) { eventService.emit(eventService.ENTITY_CHANGE_SYNCED, { entityName: entityChange.entityName, - entity + entityRow }); } }