Skip to content

Commit 107589b

Browse files
committed
fix(vue2): vuex getters undefined check, closes #1757
1 parent 9cb692b commit 107589b

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

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

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -431,32 +431,34 @@ function formatStoreForInspectorState (module, getters, path): CustomInspectorSt
431431
})),
432432
}
433433

434-
const pathWithSlashes = path.replace(VUEX_MODULE_PATH_SEPARATOR_REG, '/')
435-
getters = !module.namespaced || path === VUEX_ROOT_PATH ? module.context.getters : getters[pathWithSlashes]
436-
let gettersKeys = Object.keys(getters)
437-
const shouldPickGetters = !module.namespaced && path !== VUEX_ROOT_PATH
438-
if (shouldPickGetters) {
439-
// Only pick the getters defined in the non-namespaced module
440-
const definedGettersKeys = Object.keys(module._rawModule.getters ?? {})
441-
gettersKeys = gettersKeys.filter(key => definedGettersKeys.includes(key))
442-
}
443-
if (gettersKeys.length) {
444-
let moduleGetters: Record<string, any>
434+
if (getters) {
435+
const pathWithSlashes = path.replace(VUEX_MODULE_PATH_SEPARATOR_REG, '/')
436+
getters = !module.namespaced || path === VUEX_ROOT_PATH ? module.context.getters : getters[pathWithSlashes]
437+
let gettersKeys = Object.keys(getters)
438+
const shouldPickGetters = !module.namespaced && path !== VUEX_ROOT_PATH
445439
if (shouldPickGetters) {
446440
// Only pick the getters defined in the non-namespaced module
447-
moduleGetters = {}
448-
for (const key of gettersKeys) {
449-
moduleGetters[key] = canThrow(() => getters[key])
441+
const definedGettersKeys = Object.keys(module._rawModule.getters ?? {})
442+
gettersKeys = gettersKeys.filter(key => definedGettersKeys.includes(key))
443+
}
444+
if (gettersKeys.length) {
445+
let moduleGetters: Record<string, any>
446+
if (shouldPickGetters) {
447+
// Only pick the getters defined in the non-namespaced module
448+
moduleGetters = {}
449+
for (const key of gettersKeys) {
450+
moduleGetters[key] = canThrow(() => getters[key])
451+
}
452+
} else {
453+
moduleGetters = getters
450454
}
451-
} else {
452-
moduleGetters = getters
455+
const tree = transformPathsToObjectTree(moduleGetters)
456+
storeState.getters = Object.keys(tree).map((key) => ({
457+
key: key.endsWith('/') ? extractNameFromPath(key) : key,
458+
editable: false,
459+
value: canThrow(() => tree[key]),
460+
}))
453461
}
454-
const tree = transformPathsToObjectTree(moduleGetters)
455-
storeState.getters = Object.keys(tree).map((key) => ({
456-
key: key.endsWith('/') ? extractNameFromPath(key) : key,
457-
editable: false,
458-
value: canThrow(() => tree[key]),
459-
}))
460462
}
461463

462464
return storeState

0 commit comments

Comments
 (0)