Skip to content

Commit f6ab02c

Browse files
committed
fix(vue2): vuex getters state grouped by module, fixes #1413
1 parent b4b98ec commit f6ab02c

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,16 +357,45 @@ function formatStoreForInspectorState (module, getters, path): CustomInspectorSt
357357
}
358358

359359
if (gettersKeys.length) {
360-
storeState.getters = gettersKeys.map((key) => ({
360+
const tree = transformPathsToObjectTree(getters)
361+
storeState.getters = Object.keys(tree).map((key) => ({
361362
key: key.endsWith('/') ? extractNameFromPath(key) : key,
362363
editable: false,
363-
value: canThrow(() => getters[key])
364+
value: canThrow(() => tree[key])
364365
}))
365366
}
366367

367368
return storeState
368369
}
369370

371+
function transformPathsToObjectTree (getters) {
372+
const result = {}
373+
Object.keys(getters).forEach(key => {
374+
const path = key.split('/')
375+
if (path.length > 1) {
376+
let target = result
377+
const leafKey = path.pop()
378+
for (const p of path) {
379+
if (!target[p]) {
380+
target[p] = {
381+
_custom: {
382+
value: {},
383+
display: p,
384+
tooltip: 'Module',
385+
abstract: true
386+
}
387+
}
388+
}
389+
target = target[p]._custom.value
390+
}
391+
target[leafKey] = canThrow(() => getters[key])
392+
} else {
393+
result[key] = canThrow(() => getters[key])
394+
}
395+
})
396+
return result
397+
}
398+
370399
function getStoreModule (moduleMap, path) {
371400
const names = path.split('/').filter((n) => n)
372401
return names.reduce(

0 commit comments

Comments
 (0)