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

(Perf) Which is a right thing to do to set default values from localStorage ASAP? #317

Closed l2aelba closed 4 years ago

l2aelba commented 4 years ago

I want to get data from local storage to render the list ASAP and get real/updated data after.

Any trick I can do?

PS: Using local storage does not require. If something better please tell me

sync: {
    defaultValues: {}
}

Still does not fast enough.

l2aelba commented 4 years ago

I got a better solution, use state instead.

createEasyFirestore({
    firestorePath: 'items',
    firestoreRefType: 'collection',
    moduleName: 'items',
    state: state.storage.items // This is from JSON.parse(localStorage.getItem('myApp'))
})

But this is right way to do?

louisameline commented 4 years ago

Hi, I personnaly use vuex-persist to populate from localstorage, it works like a charm out of the box.

louisameline commented 4 years ago

And I think the state property that you mentioned should be reserved for the default blank state, and not used to populate with actual data retrieved from localstorage. Because when the whole store is reset (typically at logout), we need to know what the blank state is. So if you don't use vuex-persist, you should populate the state with regular vuex actions instead. @mesqueeb do you confirm?

mesqueeb commented 4 years ago

@l2aelba defaultValues is only for "collections" where the document are "loaded" async when you do openDBChannel or fetchAndAdd, then every incoming doc is merged onto the default values.

This feature is therefore something different from what you are looking for.

I see nothing wrong with defining the state like you do directly from local storage. Vuex Easy Firestore is able to work with that state just like regular docs that are fetched, it won't even know the difference. Which is OK if this is what you want. ; )

--
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. 🦜

l2aelba commented 4 years ago

Thank you guys :D

louisameline commented 4 years ago

Right, state is for doc mode! So my advice not to use it for that purpose applies in doc mode of course, not collections.