Skip to content

Commit a1f8221

Browse files
fix(vue2): Vuex: trim namespace for getter's path if it is not namespaced (#2096)
Co-authored-by: Guillaume Chau <[email protected]>
1 parent 687d238 commit a1f8221

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

packages/app-backend-vue2/src/plugin.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export function setupPlugin (api: DevtoolsApi, app: App, Vue) {
116116
api.on.getInspectorState((payload) => {
117117
if (payload.inspectorId === VUEX_INSPECTOR_ID) {
118118
const modulePath = payload.nodeId
119-
const module = getStoreModule(store._modules, modulePath)
119+
const { module, getterPath } = getStoreModule(store._modules, modulePath)
120120
if (!module) {
121121
return
122122
}
@@ -126,7 +126,7 @@ export function setupPlugin (api: DevtoolsApi, app: App, Vue) {
126126
payload.state = formatStoreForInspectorState(
127127
module,
128128
store._makeLocalGettersCache,
129-
modulePath,
129+
getterPath,
130130
)
131131
}
132132
})
@@ -498,12 +498,20 @@ function transformPathsToObjectTree (getters) {
498498
function getStoreModule (moduleMap, path) {
499499
const names = path.split(VUEX_MODULE_PATH_SEPARATOR).filter((n) => n)
500500
return names.reduce(
501-
(module, moduleName, i) => {
502-
const child = module ? module[moduleName === VUEX_ROOT_PATH ? 'root' : moduleName] : null
501+
({ module, getterPath }, moduleName, i) => {
502+
const child = module[moduleName === VUEX_ROOT_PATH ? 'root' : moduleName]
503503
if (!child) return null
504-
return i === names.length - 1 ? child : child._children
504+
return {
505+
module: i === names.length - 1 ? child : child._children,
506+
getterPath: child._rawModule.namespaced
507+
? getterPath
508+
: getterPath.replace(`${moduleName}${VUEX_MODULE_PATH_SEPARATOR}`, ''),
509+
}
510+
},
511+
{
512+
module: path === VUEX_ROOT_PATH ? moduleMap : moduleMap.root._children,
513+
getterPath: path,
505514
},
506-
path === VUEX_ROOT_PATH ? moduleMap : moduleMap.root._children,
507515
)
508516
}
509517

0 commit comments

Comments
 (0)