Skip to main content

switch

Function switch 

Source
pub fn switch<K, P>(
    selector: impl Fn() -> K + 'static,
    arm: impl Fn(&K) -> P + 'static,
) -> Keyed<K>
where K: PartialEq + Clone + 'static, P: Piece,
Expand description

One tracked read, one arm (docs/state.md): a subtree per value of selector, rebuilt when the value changes. The arm closure usually matches, so its arms erase with .any():

ⓘ
switch(move || tab.get(), |t| match t {
    Tab::Body => body_pane().any(),
    Tab::Headers => headers_pane().any(),
})

Revisiting a value builds its arm afresh; inactive arms are not kept alive. State that must survive a switch belongs in the model, not the subtree. Replaces runs of sibling when(move || tab.get() == …, …).

Day API ↩ Guides· daybrite.dev