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

On snapshot fix #284

Closed louisameline closed 4 years ago

louisameline commented 4 years ago

Here we go, PR reworked. Still fixes #172 and #258, with no breaking changes. The transaction in insertInitialDoc should be removed now, but I haven't touched it yet.

You'll see that I rewrote the function with if/elses. I know you're not a fan but it was getting too complex to deal with all the possible cases without those. We can argue the pros and cons at some point ;) I also commented a lot, I like to be able to understand what a code does without actually reading the code, especially when there is a lot going on like here. You should be able to follow the logic super easily and see if I forgot something.

You'll see what I did with fromCache metadata instead of hasPendingWrites to ignore the irrelevant local calls, check out Firestore's documentation about it here: https://firebase.google.com/docs/firestore/query-data/listen

Beyond the fixes and restructuring, there's a minor improvement as I took into account the success of the initial document insert to fullfill the promise or not, which was previously ignored.

mesqueeb commented 4 years ago

@louisameline thanks so much for this. will check and merge soon.