(stacked note) cache visited note

This commit is contained in:
2021-03-20 12:24:27 +01:00
parent befbd7652b
commit 71f1642c45
12 changed files with 80 additions and 9 deletions

View File

@@ -0,0 +1,31 @@
import { data } from '@/data/data'
import { DataType } from '@/data/DataType.enum'
import { Note } from '@/modules/note/models/Note'
import { useAsyncState } from '@vueuse/core'
import { computed } from 'vue'
export const useNoteCache = (sha: string) => {
const noteId = computed(() => data.generateId(DataType.Note, sha))
const getCachedNote = async () => data.get<DataType.Note, Note>(noteId.value)
const cachedNote = useAsyncState(getCachedNote, null)
const saveCacheNote = async (content: string) => {
const newNote: Note = {
_id: noteId.value,
$type: DataType.Note,
content
}
await data.update(newNote)
await cachedNote.execute()
}
return {
cachedNote: cachedNote.state,
isReady: cachedNote.isReady,
getCachedNote,
saveCacheNote
}
}