From 13795ef05e042dc00495d3c3ed6601ec59478c68 Mon Sep 17 00:00:00 2001 From: tamaina Date: Fri, 11 Aug 2023 14:10:05 +0000 Subject: [PATCH] =?UTF-8?q?executeInterruptor=E5=91=A8=E3=82=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../frontend/src/scripts/entity-manager.ts | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/packages/frontend/src/scripts/entity-manager.ts b/packages/frontend/src/scripts/entity-manager.ts index e28e5c2264..9570c5ad54 100644 --- a/packages/frontend/src/scripts/entity-manager.ts +++ b/packages/frontend/src/scripts/entity-manager.ts @@ -208,34 +208,38 @@ export class NoteManager { interruptorUnwatch: () => void, executeInterruptor: () => Promise, } { - const note = this.get(id); - if (noteViewInterruptors.length === 0) { - // noteViewInterruptorがない場合はcomputed noteを直接渡す - return { - interruptedNote: note as InterruptedCachedNote, - interruptorUnwatch: () => { }, - executeInterruptor: () => Promise.resolve(), - }; - } + const firstNote = this.get(id); + const interruptedNote = ref(firstNote.value); - const interruptedNote = ref(deepClone(note.value)); + const executeInterruptor = async () => { + const note = this.get(id); + + if (this.isDebuggerEnabled) console.log('NoteManager: executeInterruptor', id, { note: note.value, interruptedNote, noteViewInterruptors }); - async function executeInterruptor() { if (note.value == null) { interruptedNote.value = null; return; } - let result = deepClone(note.value); + if (noteViewInterruptors.length === 0) { + interruptedNote.value = note.value; + return; + } + + let result = deepClone(firstNote.value); for (const interruptor of noteViewInterruptors) { result = await interruptor.handler(result) as Note; } interruptedNote.value = result; - } - const interruptorUnwatch = watch(note, executeInterruptor); + }; + + const interruptorUnwatch = () => { + if (this.isDebuggerEnabled) console.log('NoteManager: interruptorUnwatch', id, interruptedNote); + return watch(firstNote, executeInterruptor); + }; if (this.isDebuggerEnabled) { - console.log('NoteManager: get interrupted note (new)', id, { note, interruptedNote }); + console.log('NoteManager: get interrupted note (new)', id, { note: firstNote, interruptedNote }); } return {