Skip to content

Commit

Permalink
fix(vue2): Vuex: trim namespace for getter's path if it is not namesp…
Browse files Browse the repository at this point in the history
…aced (#2096)

Co-authored-by: Guillaume Chau <guillaume.b.chau@gmail.com>
  • Loading branch information
Azurewarth0920 and Akryum authored Feb 4, 2024
1 parent 687d238 commit a1f8221
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/app-backend-vue2/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export function setupPlugin (api: DevtoolsApi, app: App, Vue) {
api.on.getInspectorState((payload) => {
if (payload.inspectorId === VUEX_INSPECTOR_ID) {
const modulePath = payload.nodeId
const module = getStoreModule(store._modules, modulePath)
const { module, getterPath } = getStoreModule(store._modules, modulePath)
if (!module) {
return
}
Expand All @@ -126,7 +126,7 @@ export function setupPlugin (api: DevtoolsApi, app: App, Vue) {
payload.state = formatStoreForInspectorState(
module,
store._makeLocalGettersCache,
modulePath,
getterPath,
)
}
})
Expand Down Expand Up @@ -498,12 +498,20 @@ function transformPathsToObjectTree (getters) {
function getStoreModule (moduleMap, path) {
const names = path.split(VUEX_MODULE_PATH_SEPARATOR).filter((n) => n)
return names.reduce(
(module, moduleName, i) => {
const child = module ? module[moduleName === VUEX_ROOT_PATH ? 'root' : moduleName] : null
({ module, getterPath }, moduleName, i) => {
const child = module[moduleName === VUEX_ROOT_PATH ? 'root' : moduleName]
if (!child) return null
return i === names.length - 1 ? child : child._children
return {
module: i === names.length - 1 ? child : child._children,
getterPath: child._rawModule.namespaced
? getterPath
: getterPath.replace(`${moduleName}${VUEX_MODULE_PATH_SEPARATOR}`, ''),
}
},
{
module: path === VUEX_ROOT_PATH ? moduleMap : moduleMap.root._children,
getterPath: path,
},
path === VUEX_ROOT_PATH ? moduleMap : moduleMap.root._children,
)
}

Expand Down

0 comments on commit a1f8221

Please sign in to comment.