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

Insert promise not resolving in offline mode. Is this expected? #344

Closed danmalone89 closed 4 years ago

danmalone89 commented 4 years ago
async saveDocument() {
 const id = await this.$store.dispatch('myModule/insert', doc)
 // document is added to Vuex store

 doSomethingWith(id) // unreachable while offline, despite document being successfully added to Vuex store.

}

Is this the expected behavior when offline? As soon as I go back online, the promise is resolved immediately. Firebase is constantly trying to write to server unsuccessfully while offline, throwing an error every second. I have offline persistence enabled.

mesqueeb commented 4 years ago

@danmalone89 yes this is the expected behaviour. The library immediately adds the document to the local state, so you don't really need to await that if that's good enough.

The await can be used to double check if the record is actually successfully written on the server side, which is therefore delayed when the client is offline.

In your case, you can either, retrieve the id from a hook like the insertHook, or you can create a random id yourself and pass it as prop to the doc you insert:

Let me know if you're stuck!

--
Vuex Easy Firestore was made with ♥ by Luca Ban.
If you use this library in your projects, you can support the maintenance of this library by a small contribution via Github 💜.
You can also reach out on twitter if you want a one-on-one coding review/lesson. 🦜

danmalone89 commented 4 years ago

Thanks @mesqueeb!