Function create_selector
pub fn create_selector<T>(f: impl FnMut() -> T + 'static) -> ReadSignal<T>where
T: PartialEq,
Expand description
Creates a memoized value from some signals.
Unlike create_memo
, this function will not notify dependents of a hange 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
let state = create_signal(1);
let squared = create_selector(move || state.get() * state.get());
assert_eq!(squared.get(), 1);
create_effect(move || println!("x^2 = {}", squared.get()));
state.set(2); // Triggers the effect.
assert_eq!(squared.get(), 4);
state.set(-2); // Does not trigger the effect.
assert_eq!(squared.get(), 4);