Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change page reload and account switch logic #2975

Merged
merged 14 commits into from
Sep 25, 2024
Prev Previous commit
Next Next commit
chore: initialize users
  • Loading branch information
userquin committed Sep 23, 2024
commit 879367864789f2faeaf0515d8a995e1842d669dc
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>
}