Skip to content

Commit

Permalink
chore: initialize users
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin committed Sep 23, 2024
1 parent b041293 commit 8793678
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions composables/idb/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MaybeRefOrGetter, RemovableRef } from '@vueuse/core'
import type { MaybeRefOrGetter } from '@vueuse/core'
import type { Ref } from 'vue'
import type { UseIDBOptions } from '@vueuse/integrations/useIDBKeyval'
import { del, get, set, update } from '~/utils/elk-idb'
Expand All @@ -10,11 +10,12 @@ export async function useAsyncIDBKeyval<T>(
initialValue: MaybeRefOrGetter<T>,
options: UseIDBOptions = {},
source?: Ref<T>,
): Promise<RemovableRef<T>> {
): Promise<void> {
const {
flush = 'pre',
deep = true,
shallow,
writeDefaults = true,
onError = (e: unknown) => {
console.error(e)
},
Expand All @@ -30,8 +31,10 @@ export async function useAsyncIDBKeyval<T>(
try {
const rawValue = await get<T>(key)
if (rawValue === undefined) {
if (rawInit !== undefined && rawInit !== null)
if (rawInit !== undefined && rawInit !== null && writeDefaults) {
await set(key, rawInit)
data.value = rawInit
}
}
else {
data.value = rawValue
Expand Down Expand Up @@ -67,6 +70,4 @@ export async function useAsyncIDBKeyval<T>(
}

watch(data, () => write(), { flush, deep })

return data as RemovableRef<T>
}

0 comments on commit 8793678

Please sign in to comment.