Function sycamore_reactive::create_selector [−][src]
pub fn create_selector<F, Out>(derived: F) -> ReadSignal<Out> where
F: FnMut() -> Out + 'static,
Out: PartialEq + 'static,
Expand description
Creates a memoized value from some signals. Also know as “derived stores”.
Unlike create_memo
, this function will not notify dependents of a change if the output is
the same. That is why the output of the function must implement PartialEq
.
To specify a custom comparison function, use create_selector_with
.
Example
use sycamore_reactive::*;
let state = Signal::new(0);
let double = create_selector(cloned!((state) => move || *state.get() * 2));
assert_eq!(*double.get(), 0);
state.set(1);
assert_eq!(*double.get(), 2);