Skip to content

Commit

Permalink
fix(vue2): only display getters from non-namespaced vuex module
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Feb 11, 2022
1 parent 985d0c8 commit a3cc310
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
22 changes: 19 additions & 3 deletions packages/app-backend-vue2/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,6 @@ function extractNameFromPath (path: string) {
}

function formatStoreForInspectorState (module, getters, path): CustomInspectorState {
getters = !module.namespaced || path === 'root' ? module.context.getters : getters[path]
const gettersKeys = Object.keys(getters)
const storeState: CustomInspectorState = {
state: Object.keys(module.context.state).map((key) => ({
key,
Expand All @@ -425,8 +423,26 @@ function formatStoreForInspectorState (module, getters, path): CustomInspectorSt
})),
}

getters = !module.namespaced || path === 'root' ? module.context.getters : getters[path]
let gettersKeys = Object.keys(getters)
const shouldPickGetters = !module.namespaced && path !== 'root'
if (shouldPickGetters) {
// Only pick the getters defined in the non-namespaced module
const definedGettersKeys = Object.keys(module._rawModule.getters ?? {})
gettersKeys = gettersKeys.filter(key => definedGettersKeys.includes(key))
}
if (gettersKeys.length) {
const tree = transformPathsToObjectTree(getters)
let moduleGetters: Record<string, any>
if (shouldPickGetters) {
// Only pick the getters defined in the non-namespaced module
moduleGetters = {}
for (const key of gettersKeys) {
moduleGetters[key] = getters[key]
}
} else {
moduleGetters = getters
}
const tree = transformPathsToObjectTree(moduleGetters)
storeState.getters = Object.keys(tree).map((key) => ({
key: key.endsWith('/') ? extractNameFromPath(key) : key,
editable: false,
Expand Down
3 changes: 3 additions & 0 deletions packages/shell-dev-vue2/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ export default new Vuex.Store({
answer: 42,
}
},
getters: {
doubleAnswer: state => state.answer * 2,
},
},
},
},
Expand Down

0 comments on commit a3cc310

Please sign in to comment.