Store: Add Dynamic Module Registration support

HapLifeMan
0
HapLifeMan
commented 9 months ago

Hi, do you have any plan to support Dynamic Module Registration as said in a previous issue? #3162

0
aldarund
803
aldarund
commented 9 months ago

As said in previous issue you can do it already. What kind of support do u expect?

0
HapLifeMan
0
HapLifeMan
commented 9 months ago

I tried to register a module when a component is created, it works well but I the state of the module is undefined when I try to commit some modifications from actions/mutations…

It throws an error Cannot set property 'config' of undefined, what I'm doing:

In my component:

import myModule from '../../store/modules/myModule'

export default {
  // Some code...
  async created() {
    this.$store.registerModule('myModule', myModule)
    this.$store.dispatch('myModule/init', config)
  }
  // Some code...
}

Then in my module's store:

const state = {
  config: null
}

const actions = {
  init({ commit }, config) {
    commit('initConfig', config)
  }
}

const mutations = {
  initConfig(state, config) {
    state.config = config
  }
}

export default { state, actions, mutations }

As said previously, state is undefined when trying to update the state from mutation…

0
begueradj
30
begueradj
commented 9 months ago

@HapLifeMan
Welcome.
This is a bug tracker, if you have a question, this is not the right place.
You can for instance ask on StackOverflow
Thanks.

0
manniL
5.7k
manniL
commented 9 months ago

Duplicate of #4370

0
Informations
QuestionUnresolved
#c8260 - Created 9 months ago