Ensure component settings is always an array and improve performance by minimizing store retrievals
This commit is contained in:
parent
1d9a03e13c
commit
69dae35e2a
|
@ -1080,11 +1080,11 @@ export class ComponentStore extends BudiStore {
|
||||||
* @param {object} definition
|
* @param {object} definition
|
||||||
* @example
|
* @example
|
||||||
* '@budibase/standard-components/container'
|
* '@budibase/standard-components/container'
|
||||||
* @returns {boolean}
|
* @returns {array} the settings
|
||||||
*/
|
*/
|
||||||
cacheSettings(componentType, definition) {
|
cacheSettings(componentType, definition) {
|
||||||
let settings = []
|
let settings = []
|
||||||
if (definition && componentType) {
|
if (definition) {
|
||||||
settings = definition.settings?.filter(setting => !setting.section) ?? []
|
settings = definition.settings?.filter(setting => !setting.section) ?? []
|
||||||
definition.settings
|
definition.settings
|
||||||
?.filter(setting => setting.section)
|
?.filter(setting => setting.section)
|
||||||
|
@ -1096,14 +1096,15 @@ export class ComponentStore extends BudiStore {
|
||||||
}))
|
}))
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
this.update(state => ({
|
|
||||||
...state,
|
|
||||||
settingsCache: {
|
|
||||||
...state.settingsCache,
|
|
||||||
[componentType]: settings,
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
this.update(state => ({
|
||||||
|
...state,
|
||||||
|
settingsCache: {
|
||||||
|
...state.settingsCache,
|
||||||
|
[componentType]: settings,
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
return settings
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1129,13 +1130,15 @@ export class ComponentStore extends BudiStore {
|
||||||
componentType = `@budibase/standard-components/${componentType}`
|
componentType = `@budibase/standard-components/${componentType}`
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isCached(componentType)) {
|
// Use cached value if possible
|
||||||
return get(this.store).settingsCache[componentType]
|
const cachedValue = get(this.store).settingsCache[componentType]
|
||||||
} else {
|
if (cachedValue) {
|
||||||
const def = this.getDefinition(componentType)
|
return cachedValue
|
||||||
this.cacheSettings(componentType, def)
|
|
||||||
return get(this.store).settingsCache[componentType]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Otherwise cache and return new value
|
||||||
|
const def = this.getDefinition(componentType)
|
||||||
|
return this.cacheSettings(componentType, def)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue