executeInterruptor周り

This commit is contained in:
tamaina 2023-08-11 14:10:05 +00:00
parent 74b1a5cdd9
commit 13795ef05e
1 changed files with 19 additions and 15 deletions

View File

@ -208,34 +208,38 @@ export class NoteManager {
interruptorUnwatch: () => void,
executeInterruptor: () => Promise<void>,
} {
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<Note | null>(firstNote.value);
const interruptedNote = ref<Note | null>(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 {