From 39a4cc0b706d5f8d38bc842de27cee6ad1edb7f6 Mon Sep 17 00:00:00 2001 From: airjp73 Date: Wed, 31 Jan 2018 13:07:26 -0500 Subject: [PATCH] Modified store to accept alternate folder structure --- lib/app/store.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) 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 }