store has a first copy of readme from cache is no waiting

This commit is contained in:
Julien Calixte
2023-08-13 21:07:17 +02:00
parent a741c7e1eb
commit 656e4b14a9
4 changed files with 33 additions and 17 deletions

View File

@@ -1,30 +1,22 @@
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 noteId = data.generateId(DataType.Note, sha)
const getCachedNote = async () => data.get<DataType.Note, Note>(noteId)
const saveCacheNote = async (content: string) => {
const newNote: Note = {
_id: noteId.value,
_id: noteId,
$type: DataType.Note,
content
}
await data.update(newNote)
await cachedNote.execute()
}
return {
cachedNote: cachedNote.state,
isReady: cachedNote.isReady,
getCachedNote,
saveCacheNote
}