vuejs / vuefire

🔥 Firebase bindings for Vue.js
https://vuefire.vuejs.org
MIT License
3.82k stars 323 forks source link

Await support #1367

Closed szulcus closed 1 year ago

szulcus commented 1 year ago

What problem is this solving

It would be great if the module supports await like useAxios from VueUse does: https://vueuse.org/integrations/useAxios/.

Proposed solution

It would be easier to write:

const { data: bookData } = await useDocument<ApiVocabulary>(doc(collection(firestore, 'books'), route.params.bookSlug));
// Operations on `bookData`

than:

const { promise: bookPromise } = useDocument<ApiVocabulary>(doc(collection(firestore, 'books'), route.params.bookSlug));
const bookData = await bookPromise.value;
// Operations on `bookData`

Describe alternatives you've considered

https://github.com/vueuse/vueuse/tree/main/packages/integrations/useAxios

posva commented 1 year ago

It’s already possible with the promise: https://vuefire.vuejs.org/guide/realtime-data.html#subscription-state

szulcus commented 1 year ago

@posva It is possible, but very unintuitive, as I wrote above 😕

mrleblanc101 commented 9 months ago

@posva It is not documented anywhere that you need to destructure a promise from the collection and wait the promise.value with useCollection anywhere in the doc. I've had to dig deep into the type definition to understand. I also tried

await useCollection(..., { wait: true, once: true, ssrKey: 'something' })

instead of

const {promise} = useCollection(..., { wait: true, once: true, ssrKey: 'something' })
await promise.value;