Is it possible to mutate a state prop in a module using another’s module mutator in vuejs2?

Viewed 400

Lets say we have something like this:

const moduleA = {
  state: { name: 'Cristian' },
  namespaced: true,
}

const moduleB = {
  state: { color: 'red' },
  namespaced: true,
}

const store = new Vuex.Store({
  state: { user: null, },
  modules: {
    a: moduleA,
    b: moduleB
  },
  mutations: {
    setPropValue(state, payload) {
      for (let [key, value] of Object.entries(payload)) {
        state[key] = value;
      }
    },
  },
})

On my vue instance I have a firebase observer to get when the user logs in/out and change state accordingly. So what I want to achieve is something like this:

const payload = {
  module: 'root',
  payload: { user, },
}

this.$store.commit('setPropValue', {payload});

then for another module:

const payload = {
  module: 'a',
  payload: { name: 'Alexander', },
}

and run the same logic, but with different load and change the props from module a:

this.$store.commit('setPropValue', {payload});
1 Answers
Related