The KosConfigProperty
attributes (value and display value) are observable like any model property. This means that not only UI consumers but other models can observe the properties for changes and respond accordingly.
One of the most common way to handle these reaction is through the use of computed values.
For example, if you create a new attribute in the Configuration Model (interface and model) called computedValue
as a number:
src/models/configuration/types/index.d.ts
export interface ConfigurationModel
extends ConfigurationOptions,
IKosDataModel {
...
computedValue: number;
}
If you add a getter to the model for the computed value then you can use configuration property values as part of a computed value or calculation:
src/models/configuration/configuration-model.ts
get computedValue() {
return this.resolveDelayMs.value + this.disablePumpTempC.value;
}
Because of the reactive nature of the models and their properties, this convention will mean that any changes to the resolveDelayMs
or disablePumpTempC
values will result in the computedValue
property recalculating with any interested observers subsequently being updated with the sum total of the two values combined.
This is one of the most powerful aspects of the model framework and one of the primary ways that configuration properties can be used to not only enable data update but also triggering reactive behavior in the UI and model layers.
The reactive behavior can be observed by putting the following into the ConfigurationProperties
component.
src/components/configuration/config-properties.tsx
<div>
<h1>{model?.computedValue}</h1>
</div>
Any changes made to the resolve delay or temperature will either in the UI or via backend processes, will result in the computed value at the bottom being recalculated and rerendered.