diff --git a/app-proto/src/outline.rs b/app-proto/src/outline.rs index e29781b..99a8dd6 100644 --- a/app-proto/src/outline.rs +++ b/app-proto/src/outline.rs @@ -43,13 +43,9 @@ fn ConstraintOutlineItem(constraint_key: usize, element_key: usize) -> View { constraint.args.0 }; let other_arg_label = assembly.elements.with(|elts| elts[other_arg].label.clone()); - let class = create_memo(move || { - if constraint.rep_valid.get() { - "cst" - } else { - "cst invalid" - } - }); + let class = constraint.rep_valid.map( + |&rep_valid| if rep_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: usize, element_key: usize) -> View { #[component(inline_props)] fn ElementOutlineItem(key: usize, 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.rep.iter().map(|u| { let u_coord = format!("{:.3}", u).replace("-", "\u{2212}"); @@ -176,15 +168,16 @@ fn ElementOutlineItem(key: usize, 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) },