Skip to content

Commit

Permalink
feat(vuex): group getters by module
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Oct 28, 2019
1 parent 7d671b2 commit 007b788
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/app-frontend/src/views/settings/GlobalPreferences.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@
May impact performance or cause crashes
</template>
</VueFormField>

<VueFormField>
<template #title>
Group getters by module
<NewTag :version="2" />
</template>
<VueSwitch v-model="$shared.vuexGroupGettersByModule">
Enable
</VueSwitch>
</VueFormField>
</div>
</template>

Expand Down
2 changes: 1 addition & 1 deletion packages/app-frontend/src/views/settings/SettingsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import GlobalPreferences from './GlobalPreferences.vue'
import { mapState } from 'vuex'
export const SETTINGS_VERSION = 2
export const SETTINGS_VERSION = 3
export const SETTINGS_VERSION_ID = 'vue-devtools-settings-version'
export default {
Expand Down
21 changes: 21 additions & 0 deletions packages/app-frontend/src/views/vuex/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,27 @@ const getters = {
res.getters = data.getters
}

if (SharedData.vuexGroupGettersByModule && res.getters) {
const getterGroups = {}
const keys = Object.keys(res.getters)
keys.forEach(key => {
const parts = key.split('/')
let parent = getterGroups
for (let p = 0; p < parts.length - 1; p++) {
const part = parts[p]
parent = parent[part] = parent[part] || {
_custom: {
value: {},
abstract: true
}
}
parent = parent._custom.value
}
parent[parts.pop()] = res.getters[key]
})
res.getters = getterGroups
}

return res
},

Expand Down
4 changes: 3 additions & 1 deletion packages/shared-utils/src/shared-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const internalSharedData = {
editableProps: false,
logDetected: true,
vuexNewBackend: false,
vuexAutoload: false
vuexAutoload: false,
vuexGroupGettersByModule: true
}

const persisted = [
Expand All @@ -27,6 +28,7 @@ const persisted = [
'logDetected',
'vuexNewBackend',
'vuexAutoload',
'vuexGroupGettersByModule',
'timeFormat'
]

Expand Down

0 comments on commit 007b788

Please sign in to comment.