mirror of
https://github.com/zadam/trilium.git
synced 2025-01-22 23:20:23 +08:00
small refactoring
This commit is contained in:
parent
d0747b125c
commit
635f5fdc5b
2 changed files with 11 additions and 11 deletions
|
@ -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}) => {
|
||||
|
|
|
@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue