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

Always get "Error: [vuex] do not mutate vuex store state outside mutation handlers." #287

Closed findingorder closed 4 years ago

findingorder commented 4 years ago

Hello, I set up a store exactly as shown in the docs, yet whenever I try to dispatch any of the four actions, set, patch, insert or delete, it seems to perform the action, but I get the console error "Error: [vuex] do not mutate vuex store state outside mutation handlers."

Here's a code example. In the store module I have:

const state = {
    data: {}
}

const actions = {
    load({ dispatch }) {
        dispatch('openDBChannel')
    }
}

export default {
    namespaced: true,
    firestorePath: '/users/{userId}/foo',
    firestoreRefType: 'collection', // or 'doc'
    moduleName: 'foo',
    statePropName: 'data',

    actions
}

And then in a Vue component, I do

this.$store.dispatch('foo/set', doc)

and I always get the error, no matter which of the four actions I dispatch. Can anyone tell me what's causing this error and how I prevent it? Thanks, Phil

louisameline commented 4 years ago

Hi, you must have strict mode enabled on Vuex, disable it. Mutations will probably be deprecated in 6 months anyway.

findingorder commented 4 years ago

Thanks! That was indeed the case. Disabled strict mode and everything runs as expected. Issue resolved. Thanks for such a speedy response, you saved me what could have been many hours of flailing about.