From 64e38062388e533048507ac34bbeb0ba50e9c5f5 Mon Sep 17 00:00:00 2001 From: kjimlau Date: Tue, 16 Nov 2021 11:04:59 +0800 Subject: [PATCH] fix: wait to run storage oper until prev one finished --- src/content-scripts/renderer/popup/note-book/note-list.vue | 2 ++ src/content-scripts/renderer/popup/tag-book/index.vue | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/content-scripts/renderer/popup/note-book/note-list.vue b/src/content-scripts/renderer/popup/note-book/note-list.vue index a0f6431..58fd3ee 100644 --- a/src/content-scripts/renderer/popup/note-book/note-list.vue +++ b/src/content-scripts/renderer/popup/note-book/note-list.vue @@ -138,6 +138,8 @@ export default defineComponent({ const { noteId = "", tag = "", isAddOrDelete = false } = data as any; const fn = isAddOrDelete ? addItemToArrProperty : delItemFromArrProperty; storage.notes = await fn(StorageKeys.notes, "id", noteId, "tags", tag); + + mitt.emit("update-note-tag-cb"); }); /// update note of note diff --git a/src/content-scripts/renderer/popup/tag-book/index.vue b/src/content-scripts/renderer/popup/tag-book/index.vue index 15a8a5f..b89af72 100644 --- a/src/content-scripts/renderer/popup/tag-book/index.vue +++ b/src/content-scripts/renderer/popup/tag-book/index.vue @@ -22,7 +22,7 @@ import randomColor from "randomcolor"; import { Coor } from "@/types/common"; import { Tag } from "@/types/tag"; import { Storage } from "@/types/storage"; -import mitt from "@/utils/mitt"; +import mitt, { sendEmitAndWait } from "@/utils/mitt"; import { addItemToArr, addItemToArrProperty, @@ -149,7 +149,7 @@ export default { } else { tag.isSelect = !tag.isSelect; if (tag.isSelect) { - mitt.emit("update-note-tag", { + await sendEmitAndWait("update-note-tag", { noteId: props.noteId, tag: tag.name, isAddOrDelete: true, @@ -162,7 +162,7 @@ export default { props.noteId ); } else { - mitt.emit("update-note-tag", { + await sendEmitAndWait("update-note-tag", { noteId: props.noteId, tag: tag.name, isAddOrDelete: false,