bencodezen / vue-enterprise-boilerplate

An ever-evolving, very opinionated architecture and dev environment for new Vue SPA projects using Vue CLI.
7.77k stars 1.32k forks source link

Support `init` action for nested modules #140

Closed ghost closed 5 years ago

ghost commented 5 years ago

I've modify the store.js file for supporting the init inside the nested modules. I think we can do better and cleaner. Any advice?

// Automatically run the `init` action for every module,
// if one exists.
for (const moduleName of Object.keys(modules)) {
  const subModules = modules[moduleName].modules
  if (subModules) {
    for (const subModuleName of Object.keys(subModules)) {
      if (subModules[subModuleName].actions && subModules[subModuleName].actions.init) {
        store.dispatch(`${moduleName}/${subModuleName}/init`)
      }
    }
  } else {
    if (modules[moduleName].actions && modules[moduleName].actions.init) {
      store.dispatch(`${moduleName}/init`)
    }
  }
}
chrisvfritz commented 5 years ago

I just fixed this. 🙂 It should now work for both deeply nested and non-namespaced modules.