mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-19 23:21:09 +00:00
Modified store to accept alternate folder structure
This commit is contained in:
parent
e2b0ccc74a
commit
39a4cc0b70
@ -34,10 +34,21 @@ if (typeof storeData !== 'function') {
|
|||||||
if (name === 'index') continue
|
if (name === 'index') continue
|
||||||
|
|
||||||
let namePath = name.split(/\//)
|
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)
|
let module = getModuleNamespace(storeData, namePath)
|
||||||
|
|
||||||
name = namePath.pop()
|
name = namePath.pop()
|
||||||
module[name] = getModule(filename)
|
module[name] = module[name] || {}
|
||||||
|
module[name] = Object.assign(module[name], getModule(filename))
|
||||||
module[name].namespaced = true
|
module[name].namespaced = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,13 +76,20 @@ function getModule (filename) {
|
|||||||
return module
|
return module
|
||||||
}
|
}
|
||||||
|
|
||||||
function getModuleNamespace (storeData, namePath) {
|
function getModuleNamespace (storeData, namePath, forAppend = false) {
|
||||||
if (namePath.length === 1) {
|
if (namePath.length === 1) {
|
||||||
|
if (forAppend)
|
||||||
|
return storeData
|
||||||
return storeData.modules
|
return storeData.modules
|
||||||
}
|
}
|
||||||
let namespace = namePath.shift()
|
let namespace = namePath.shift()
|
||||||
storeData.modules[namespace] = storeData.modules[namespace] || {}
|
storeData.modules[namespace] = storeData.modules[namespace] || {}
|
||||||
storeData.modules[namespace].namespaced = true
|
storeData.modules[namespace].namespaced = true
|
||||||
storeData.modules[namespace].modules = storeData.modules[namespace].modules || {}
|
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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user