Generalize constraints to observables #48
2 changed files with 9 additions and 13 deletions
|
@ -124,16 +124,6 @@ pub struct Regulator {
|
|||
pub set_point: Signal<SpecifiedValue>
|
||||
}
|
||||
|
||||
impl Regulator {
|
||||
/* TO DO */
|
||||
// if it's called for, add a `set` method that takes a bare SpecifiedValue
|
||||
pub fn set_if_ok<E>(&self, set_pt_result: Result<SpecifiedValue, E>) {
|
||||
if let Ok(set_pt) = set_pt_result {
|
||||
self.set_point.set(set_pt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// the velocity is expressed in uniform coordinates
|
||||
pub struct ElementMotion<'a> {
|
||||
pub key: ElementKey,
|
||||
|
|
|
@ -57,9 +57,15 @@ fn RegulatorInput(regulator: Regulator) -> View {
|
|||
placeholder=regulator.measurement.with(|result| result.to_string()),
|
||||
bind:value=value,
|
||||
on:change=move |_| {
|
||||
let set_pt_result = SpecifiedValue::try_from(value.get_clone_untracked());
|
||||
valid.set(set_pt_result.is_ok());
|
||||
regulator.set_if_ok(set_pt_result);
|
||||
valid.set(
|
||||
match SpecifiedValue::try_from(value.get_clone_untracked()) {
|
||||
glen marked this conversation as resolved
Outdated
|
||||
Ok(set_pt) => {
|
||||
regulator.set_point.set(set_pt);
|
||||
true
|
||||
}
|
||||
Err(_) => false
|
||||
}
|
||||
)
|
||||
},
|
||||
on:keydown={
|
||||
move |event: KeyboardEvent| {
|
||||
|
|
Loading…
Add table
Reference in a new issue
This looks like the code is checking the OK-ness of the try_from twice. Is there a concise clear way to bind a variable to the SpecifiedValue payload in the OK return case and set
valid
to true and call the as-yet-unwritten regulator.set with that specified value, in that case, and in the alternative (Error) case, just setvalid
to false and do nothing to the regulator? That organization would seem to read more crisply, as long as it isn't too cumbersome to write... And in fact, if I recall, isn't that sort of thing whatif let OK(blah) = try_from { ... } else {valid.set(false)}
is for?P.S. If the code here switched to something like this suggestion, then as this is the only instance of
set_if_ok
, you could remove that method in favor of a simplerset
method, or in fact maybe just a direct call ofregulator.set_point.set(...)
, eliminating the entireimpl Regulator
block at lines 127-135 of assembly.rs, which seems like a win.So I guess I am specifically suggesting replacing this block with
-- presuming the syntax is OK -- and just removing that
impl Regulator
block in assembly.rs altogether.That sounds great to me. I'd reorganize the block to avoid the repetition of
valid.set
. Depending on whether you preferif let
ormatch
, we could do either of these:In the
match
version, the argument ofvalid.set
is just an inlined version of the oldRegulator::try_set
method. If we want to go this route, and you don't have a strong preference for inlining, I'd recommend just reverting commit894931a
, which replacedRegulator::try_set
withRegulator::set_if_ok
. We can also rewritetry_set
to useif let
instead ofmatch
, of course.