MartinMalinda / vue-concurrency

A library for encapsulating asynchronous operations and managing concurrency for Vue and Composition API.

Home Page:https://vue-concurrency.netlify.app/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does this play nice with Firebase streams?

BenJackGill opened this issue · comments

Have been reading your docs, and I really like vue-concurrency.

Was thinking of using it for my Firebase composables.

That would mean wrapping Firebase streams like onAuthStateChanged and onSnapshot in a Task.

The Task would have to listen and update the value, error, isError etc states.

Would that work?

I'm afraid tasks are not the best fit for streams. Task is triggered explicitly with perform() and once task instance is finished the code does not really expect the value or any other field to change. Also Task builds on top of Promise behavior and Promise also once it is resolved does not yield new values. Promise resolves or rejects just once.

You can promisify onSnapshot but that would mean the Promise would resolve on first value. And that can be useful for showing the initial spinner or even some error.

I would either choose something like RxJS https://vueuse.org/rxjs/readme.html#example or I would write my own reactivity abstraction. You could use a task on the side for the initial loading state but it will still require custom reacitivity wiring.