Modified store to accept alternate folder structure

This commit is contained in:
airjp73 2018-01-31 13:07:26 -05:00
parent e2b0ccc74a
commit 39a4cc0b70

View File

@ -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
}