mirror of
https://github.com/zaphar/sycamore-state.git
synced 2025-07-22 20:29:50 -04:00
Provide a helper method to get selectors from the state
This commit is contained in:
parent
3b220477d7
commit
f939f52a2b
12
src/lib.rs
12
src/lib.rs
@ -63,6 +63,18 @@ where
|
|||||||
{
|
{
|
||||||
create_effect(cx, move || self.dispatch(message_fn(trigger.get())));
|
create_effect(cx, move || self.dispatch(message_fn(trigger.get())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_selector<F, Val>(
|
||||||
|
&'ctx self,
|
||||||
|
cx: Scope<'ctx>,
|
||||||
|
selector_factory: F,
|
||||||
|
) -> &'ctx ReadSignal<Val>
|
||||||
|
where
|
||||||
|
F: Fn(&'ctx ReadSignal<T>) -> Val + 'ctx,
|
||||||
|
Val: PartialEq,
|
||||||
|
{
|
||||||
|
create_selector(cx, move || selector_factory(self.signal))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user