mesqueeb / vuex-easy-firestore

Easy coupling of firestore and a vuex module. 2-way sync with 0 boilerplate!
https://mesqueeb.github.io/vuex-easy-firestore
MIT License
234 stars 28 forks source link

Matching closeDBChannel for each openDBChannel? #240

Open tedchwang opened 5 years ago

tedchwang commented 5 years ago

Hello Luca!

Thank you for this great tool. I'm reading the documentation and I am wondering if we openDBChannel multiple times on myModule but with different where() filters, will we be able to selectively closeDBChannel, or does closeDBChannel detach all listeners born from myModule?

mesqueeb commented 5 years ago

Hello. The current implementation needs to be improved, because a module will remember the last where filters and create an "identifier" based on that.

https://github.com/mesqueeb/vuex-easy-firestore/blob/master/src/module/actions.ts#L521

That means if you closeDBChannel it will only close the one with the latest filters....

I have to improve this behaviour. Thanks for noticing!

Work around

You can mutate this mutation before each closeDBChannel:

commit('SET_SYNCFILTERS', {where, orderBy})

You need to pass an object with an array for both where and orderBy. See the source code for SET_SYNCFILTERS here.

Improving the current behaviour

Feel free to make a PR helping me improve this behaviour or anything related to the way openDBChannel identifiers are saved to be closed later.

I plan to only re-write this part for version 2.0, unless if you make a good PR, I might keep that implementation in v2.0.

Until then please use this work around. 😉

--
Vuex Easy Firestore was made with ♥ by Luca Ban.
If this library helped you in any way you can support me by buying me a cup of coffee. ☕️
You can also reach out on twitter if you want a one-on-one coding review/lesson. 🦜

mesqueeb commented 4 years ago

After about two years of open source, I finally got accepted for Github Sponsors!

💜 github.com/sponsors/mesqueeb 💜

A little about me:

If anyone was helped with vuex-easy-firestore, I'd greatly appreciate any support!

BTW, donations get's paid DOUBLE by GitHub! (they're alchemists... 🦾)

Going forward 👨🏼‍💻

louisameline commented 4 years ago

Hi @tedchwang, version 1.35.2 will help you accomplish what you wish channel by channel, thanks to stop(). In the future, it is likely that we'll deprecate closeDBChannel in favor of some closeDBChannels action, which will close all channels of the module. I'll leave this issue open until we do.