-
Notifications
You must be signed in to change notification settings - Fork 336
Closed
Description
Long story short: the current main classes for PGlite use a number of private methods, but since Vue's reactivity is based on proxying this effectively breaks its usability (official comment).
This becomes quite important when working with composables instead of components.
An example of an ideal DX composable would be:
import { computed, ref, onMounted, onBeforeUnmount } from 'vue'
import type { PGliteOptions } from '@electric-sql/pglite'
import { PGlite } from '@electric-sql/pglite'
export function usePGlite(options?: PGliteOptions) {
// initialize an empty ref, so that Vue can start tracking it
const pg = ref<PGlite>()
// onMounted required in SSR (for Nuxt you can use onNuxtReady)
onMounted(async () => {
pg.value = await PGlite.create(options)
})
// safely closing the connection
onBeforeUnmount(() => {
if (!isClosed.value || pg.value === undefined) return
pg.value.close()
})
const isReady = computed(() => !!pg.value?.ready)
const isClosed = computed(() => !!pg.value?.closed)
return {
pg,
isReady,
isClosed,
}
}Same applies for workers and in a Nuxt context.
Metadata
Metadata
Assignees
Labels
No labels