robinvdvleuten / vuex-persistedstate

💾 Persist and rehydrate your Vuex state between page reloads.
https://npm.im/vuex-persistedstate
MIT License
5.77k stars 378 forks source link

[docs needed ?] - vuex-persistedstate with vuexfire bindings #325

Closed malomarrec closed 4 years ago

malomarrec commented 4 years ago

This issue sits in-between a feature request and a request for more documentation. It is not as well-defined as I'd like for an issue, but this felt like the best place to post it. If this is not the place, please indicate where it would make sense.

Are there best practices on how to setup vuex-persistedstate with vuexfire? I am encountering weird side effects when using vuex-persistedstate to persist a state defined by a vuexfire binding. Namely, the bindings and/or store are refreshing erratically, resulting in old data and up to data data being blended together.

Are there any tips / best-practices? Is this discouraged? Is this a use case common enough to grant a docs section?

Use case Persist a vuexfire data and binding across page navigation and reload.

Context

In store/modules/project.js

  namespaced: true,
  state: {
    projected,
    project: {}
  },
  actions: {
    bindProject: firestoreAction(({ state, bindFirestoreRef }) => {
      return bindFirestoreRef('project', fb.katasCollection.doc(state.projectId))
      }),
  },

In store/index.js

Vue.use(Vuex)
// import createPersistedState from "vuex-persistedstate";

export const store = new Vuex.Store({
  plugins: [
    createPersistedState({
      paths: ['project'],
    }),
  ],
  mutations: {
    ...vuexfireMutations,
  },
  modules: {
    project: project
  }
})
robinvdvleuten commented 4 years ago

I am not a Vuexfire user so I can't help you with this. Please ask your question on either Stackoverflow or the Vuejs forum.