Move pointer creation into insert_regulator
This will make it easier to give each regulator a constructor instead of an "insert new" method.
This commit is contained in:
parent
ee8a01b9cb
commit
8f8e806d12
1 changed files with 14 additions and 10 deletions
|
@ -323,11 +323,15 @@ impl Assembly {
|
|||
);
|
||||
}
|
||||
|
||||
fn insert_regulator(&self, regulator: Rc<dyn Regulator>) {
|
||||
let subjects = regulator.subjects();
|
||||
fn insert_regulator<T: Regulator + 'static>(&self, regulator: T) {
|
||||
// add the regulator to the assembly's regulator list
|
||||
let regulator_rc = Rc::new(regulator);
|
||||
let key = self.regulators.update(
|
||||
|regs| regs.insert(regulator.clone())
|
||||
|regs| regs.insert(regulator_rc.clone())
|
||||
);
|
||||
|
||||
// add the regulator to each subject's regulator list
|
||||
let subjects = regulator_rc.subjects();
|
||||
let subject_regulators: Vec<_> = self.elements.with_untracked(
|
||||
|elts| subjects.into_iter().map(
|
||||
|subj| elts[subj].regulators
|
||||
|
@ -342,10 +346,10 @@ impl Assembly {
|
|||
let self_for_effect = self.clone();
|
||||
create_effect(move || {
|
||||
console::log_1(&JsValue::from(
|
||||
format!("Updated regulator with subjects {:?}", regulator.subjects())
|
||||
format!("Updated regulator with subjects {:?}", regulator_rc.subjects())
|
||||
));
|
||||
if regulator.set_point().with(|set_pt| set_pt.is_present()) {
|
||||
regulator.activate(&self_for_effect);
|
||||
if regulator_rc.set_point().with(|set_pt| set_pt.is_present()) {
|
||||
regulator_rc.activate(&self_for_effect);
|
||||
self_for_effect.realize();
|
||||
}
|
||||
});
|
||||
|
@ -386,11 +390,11 @@ impl Assembly {
|
|||
}
|
||||
);
|
||||
let set_point = create_signal(SpecifiedValue::from_empty_spec());
|
||||
self.insert_regulator(Rc::new(ProductRegulator {
|
||||
self.insert_regulator(ProductRegulator {
|
||||
subjects: subjects,
|
||||
measurement: measurement,
|
||||
set_point: set_point
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
pub fn insert_new_half_curvature_regulator(&self, subject: ElementKey) {
|
||||
|
@ -399,11 +403,11 @@ impl Assembly {
|
|||
move |elts| elts[subject].representation.with(|rep| rep[3])
|
||||
);
|
||||
let set_point = create_signal(SpecifiedValue::from_empty_spec());
|
||||
self.insert_regulator(Rc::new(HalfCurvatureRegulator {
|
||||
self.insert_regulator(HalfCurvatureRegulator {
|
||||
subject: subject,
|
||||
measurement: measurement,
|
||||
set_point: set_point
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
// --- realization ---
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue