pub struct Handler<'ctx, D, T, Msg>where
D: MessageMapper<Msg, T>,{ /* private fields */ }Expand description
Provides the necessary wiring for a centralized state handling mechanism. The API guides you along handling the lifetimes properly as well as registering all the state management logic in one place.
Implementations§
Source§impl<'ctx, D, T, Msg> Handler<'ctx, D, T, Msg>where
D: MessageMapper<Msg, T>,
impl<'ctx, D, T, Msg> Handler<'ctx, D, T, Msg>where
D: MessageMapper<Msg, T>,
Sourcepub fn new(cx: Scope<'ctx>, initial: T, dispatcher: D) -> &'ctx Self
pub fn new(cx: Scope<'ctx>, initial: T, dispatcher: D) -> &'ctx Self
Constructs a new Handler with a lifetime anchored to the provided Scope. You will usually construct this in your top level scope and then pass the handlers down into your components.
Sourcepub fn dispatch(&'ctx self, cx: Scope<'ctx>, msg: Msg)
pub fn dispatch(&'ctx self, cx: Scope<'ctx>, msg: Msg)
Directly handle a state message without requiring a binding.
Sourcepub fn read_signal(&'ctx self) -> &'ctx ReadSignal<T>
pub fn read_signal(&'ctx self) -> &'ctx ReadSignal<T>
Provides a ReadSignal handle for the contained Signal implementation.
Sourcepub fn bind_trigger<F, Val>(
&'ctx self,
cx: Scope<'ctx>,
trigger: &'ctx ReadSignal<Val>,
message_fn: F,
)
pub fn bind_trigger<F, Val>( &'ctx self, cx: Scope<'ctx>, trigger: &'ctx ReadSignal<Val>, message_fn: F, )
Binds a triggering signal and associated message mapping function as
a state update for this Handler instance. This uses create_effect
so be aware that it will fire at least once when you first call it. It
is really easy to introduce an infinite signal update loop.
Sourcepub fn get_selector<F, Val>(
&'ctx self,
cx: Scope<'ctx>,
selector_factory: F,
) -> &'ctx ReadSignal<Val>
pub fn get_selector<F, Val>( &'ctx self, cx: Scope<'ctx>, selector_factory: F, ) -> &'ctx ReadSignal<Val>
Helper method to get a memoized value derived from the contained state for this Handler. The provided handler only notifies subscribers If the state has actually been updated.