diff --git a/src/services/events.js b/src/services/events.js index 91dda3e23..d8e7b9fcf 100644 --- a/src/services/events.js +++ b/src/services/events.js @@ -9,6 +9,7 @@ const ENTITY_DELETED = "ENTITY_DELETED"; const ENTITY_CHANGE_SYNCED = "ENTITY_CHANGE_SYNCED"; const ENTITY_DELETE_SYNCED = "ENTITY_DELETE_SYNCED"; const CHILD_NOTE_CREATED = "CHILD_NOTE_CREATED"; +const NOTE_CONTENT_CHANGE = "NOTE_CONTENT_CHANGED"; const eventListeners = {}; @@ -69,5 +70,6 @@ module.exports = { ENTITY_DELETED, ENTITY_CHANGE_SYNCED, ENTITY_DELETE_SYNCED, - CHILD_NOTE_CREATED + CHILD_NOTE_CREATED, + NOTE_CONTENT_CHANGE }; diff --git a/src/services/handlers.js b/src/services/handlers.js index 1cdaa2cb7..6ae306cfc 100644 --- a/src/services/handlers.js +++ b/src/services/handlers.js @@ -59,9 +59,7 @@ eventService.subscribe([ eventService.ENTITY_CHANGED, eventService.ENTITY_DELETE }); eventService.subscribe(eventService.ENTITY_CHANGED, ({entityName, entity}) => { - if (entityName === 'note_contents') { // FIXME - runAttachedRelations(entity, 'runOnNoteContentChange', entity); - } else if (entityName === 'branches') { + if (entityName === 'branches') { const parentNote = becca.getNote(entity.parentNoteId); if (parentNote?.hasLabel("sorted")) { @@ -70,6 +68,10 @@ eventService.subscribe(eventService.ENTITY_CHANGED, ({entityName, entity}) => { } }); +eventService.subscribe(eventService.NOTE_CONTENT_CHANGE, ({entity}) => { + runAttachedRelations(entity, 'runOnNoteContentChange', entity); +}); + eventService.subscribe(eventService.ENTITY_CREATED, ({ entityName, entity }) => { if (entityName === 'attributes') { runAttachedRelations(entity.getNote(), 'runOnAttributeCreation', entity); diff --git a/src/services/notes.js b/src/services/notes.js index d0902161a..c5f0fbb70 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -229,8 +229,7 @@ function createNewNote(params) { entity: note }); - eventService.emit(eventService.ENTITY_CREATED, { // FIXME - entityName: 'note_contents', + eventService.emit(eventService.NOTE_CONTENT_CHANGE, { entity: note }); @@ -571,10 +570,7 @@ function downloadImages(noteId, content) { asyncPostProcessContent(origNote, updatedContent); - eventService.emit(eventService.ENTITY_CHANGED, { - entityName: 'note_contents', // FIXME - entity: origNote - }); + eventService.emit(eventService.NOTE_CONTENT_CHANGE, { entity: origNote }); console.log(`Fixed the image links for note '${noteId}' to the offline saved.`); }