diff --git a/lib/app/store.js b/lib/app/store.js index 94c398254e..8a98b3171f 100644 --- a/lib/app/store.js +++ b/lib/app/store.js @@ -34,10 +34,21 @@ if (typeof storeData !== 'function') { if (name === 'index') continue let namePath = name.split(/\//) + + name = namePath[namePath.length-1] + console.log(namePath) + if (name === 'state' || name === 'getters' || name === 'actions' || name === 'mutations') { + + let module = getModuleNamespace(storeData, namePath, true) + appendModule(module, filename, name) + continue + } + let module = getModuleNamespace(storeData, namePath) name = namePath.pop() - module[name] = getModule(filename) + module[name] = module[name] || {} + module[name] = Object.assign(module[name], getModule(filename)) module[name].namespaced = true } @@ -65,13 +76,20 @@ function getModule (filename) { return module } -function getModuleNamespace (storeData, namePath) { +function getModuleNamespace (storeData, namePath, forAppend = false) { if (namePath.length === 1) { + if (forAppend) + return storeData return storeData.modules } let namespace = namePath.shift() storeData.modules[namespace] = storeData.modules[namespace] || {} storeData.modules[namespace].namespaced = true storeData.modules[namespace].modules = storeData.modules[namespace].modules || {} - return getModuleNamespace(storeData.modules[namespace], namePath) + return getModuleNamespace(storeData.modules[namespace], namePath, forAppend) +} + +function appendModule(module, filename, name) { + const file = files(filename) + module[name] = file.default || file }