created mergedConfig getter to avoid obnoxious checks for undefined everywhere

This commit is contained in:
Henry Jameson 2019-09-29 22:33:15 +03:00
parent aadd36f3ec
commit 979e170bd6
9 changed files with 64 additions and 64 deletions

View file

@ -40,8 +40,27 @@ const defaultState = {
minimalScopesMode: undefined // instance default
}
// caching the instance default properties
export const instanceDefaultProperties = Object.entries(defaultState)
.filter(([key, value]) => value === undefined)
.map(([key, value]) => key)
const config = {
state: defaultState,
getters: {
mergedConfig (state, getters, rootState, rootGetters) {
const { instance } = rootState
return {
...state,
...instanceDefaultProperties
.map(key => [key, state[key] === undefined
? instance[key]
: state[key]
])
.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {})
}
}
},
mutations: {
setOption (state, { name, value }) {
set(state, name, value)