Enforce the validity of set point specifications

Make a regulator's set point specification private, and split the set
point into a private writable signal and a public read-only signal. The
set point can now be initialized only through the factory method
`insert_new_regulator` and changed only through the setter method
`try_specify_set_point`, which both ensure that the set point
specification is valid and consistent with the set point.
This commit is contained in:
Aaron Fenyes 2025-02-18 13:29:10 -08:00
parent bbd0835a8f
commit f2e84fb64a
3 changed files with 74 additions and 52 deletions

View file

@ -20,14 +20,14 @@ use crate::{
#[component(inline_props)]
fn RegulatorInput(regulator: Regulator) -> View {
let valid = create_signal(true);
let value = create_signal(regulator.set_point_spec.get_clone_untracked());
let value = create_signal(regulator.get_set_point_spec_clone_untracked());
// this closure resets the input value to the regulator's set point
// specification, which is always a valid specification
let reset_value = move || {
batch(|| {
valid.set(true);
value.set(regulator.set_point_spec.get_clone());
value.set(regulator.get_set_point_spec_clone());
})
};