Skip to content

Commit a3cc310

Browse files
committed
fix(vue2): only display getters from non-namespaced vuex module
1 parent 985d0c8 commit a3cc310

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,6 @@ function extractNameFromPath (path: string) {
415415
}
416416

417417
function formatStoreForInspectorState (module, getters, path): CustomInspectorState {
418-
getters = !module.namespaced || path === 'root' ? module.context.getters : getters[path]
419-
const gettersKeys = Object.keys(getters)
420418
const storeState: CustomInspectorState = {
421419
state: Object.keys(module.context.state).map((key) => ({
422420
key,
@@ -425,8 +423,26 @@ function formatStoreForInspectorState (module, getters, path): CustomInspectorSt
425423
})),
426424
}
427425

426+
getters = !module.namespaced || path === 'root' ? module.context.getters : getters[path]
427+
let gettersKeys = Object.keys(getters)
428+
const shouldPickGetters = !module.namespaced && path !== 'root'
429+
if (shouldPickGetters) {
430+
// Only pick the getters defined in the non-namespaced module
431+
const definedGettersKeys = Object.keys(module._rawModule.getters ?? {})
432+
gettersKeys = gettersKeys.filter(key => definedGettersKeys.includes(key))
433+
}
428434
if (gettersKeys.length) {
429-
const tree = transformPathsToObjectTree(getters)
435+
let moduleGetters: Record<string, any>
436+
if (shouldPickGetters) {
437+
// Only pick the getters defined in the non-namespaced module
438+
moduleGetters = {}
439+
for (const key of gettersKeys) {
440+
moduleGetters[key] = getters[key]
441+
}
442+
} else {
443+
moduleGetters = getters
444+
}
445+
const tree = transformPathsToObjectTree(moduleGetters)
430446
storeState.getters = Object.keys(tree).map((key) => ({
431447
key: key.endsWith('/') ? extractNameFromPath(key) : key,
432448
editable: false,

packages/shell-dev-vue2/src/store.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ export default new Vuex.Store({
8888
answer: 42,
8989
}
9090
},
91+
getters: {
92+
doubleAnswer: state => state.answer * 2,
93+
},
9194
},
9295
},
9396
},

0 commit comments

Comments
 (0)