From ec1911b8899c4f925e47c59ded71aa8f259ae3d0 Mon Sep 17 00:00:00 2001 From: Aaron Fenyes Date: Fri, 1 Nov 2024 04:43:30 -0700 Subject: [PATCH] Simplify memos --- app-proto/src/outline.rs | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/app-proto/src/outline.rs b/app-proto/src/outline.rs index 329fc58..65e440f 100644 --- a/app-proto/src/outline.rs +++ b/app-proto/src/outline.rs @@ -43,13 +43,9 @@ fn ConstraintOutlineItem(constraint_key: ConstraintKey, element_key: ElementKey) constraint.subjects.0 }; let other_subject_label = assembly.elements.with(|elts| elts[other_subject].label.clone()); - let class = create_memo(move || { - if constraint.lorentz_prod_valid.get() { - "cst" - } else { - "cst invalid" - } - }); + let class = constraint.lorentz_prod_valid.map( + |&lorentz_prod_valid| if lorentz_prod_valid { "cst" } else { "cst invalid" } + ); view! { li(class=class.get()) { input(r#type="checkbox", bind:checked=constraint.active) @@ -64,13 +60,9 @@ fn ConstraintOutlineItem(constraint_key: ConstraintKey, element_key: ElementKey) #[component(inline_props)] fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View { let state = use_context::(); - let class = create_memo(move || { - if state.selection.with(|sel| sel.contains(&key)) { - "selected" - } else { - "" - } - }); + let class = state.selection.map( + move |sel| if sel.contains(&key) { "selected" } else { "" } + ); let label = element.label.clone(); let rep_components = element.representation.iter().map(|u| { let u_coord = format!("{:.3}", u).replace("-", "\u{2212}"); @@ -176,15 +168,16 @@ fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View { // #[component] pub fn Outline() -> View { - // sort the elements alphabetically by ID - let elements_sorted = create_memo(|| { - let state = use_context::(); - state.assembly.elements - .get_clone() + let state = use_context::(); + + // list the elements alphabetically by ID + let element_list = state.assembly.elements.map( + |elts| elts + .clone() .into_iter() .sorted_by_key(|(_, elt)| elt.id.clone()) .collect() - }); + ); view! { ul( @@ -195,7 +188,7 @@ pub fn Outline() -> View { } ) { Keyed( - list=elements_sorted, + list=element_list, view=|(key, elt)| view! { ElementOutlineItem(key=key, element=elt) },