Handler

Struct Handler 

Source
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>,

Source

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.

Source

pub fn dispatch(&'ctx self, cx: Scope<'ctx>, msg: Msg)

Directly handle a state message without requiring a binding.

Source

pub fn read_signal(&'ctx self) -> &'ctx ReadSignal<T>

Provides a ReadSignal handle for the contained Signal implementation.

Source

pub fn bind_trigger<F, Val>( &'ctx self, cx: Scope<'ctx>, trigger: &'ctx ReadSignal<Val>, message_fn: F, )
where F: Fn(Rc<Val>) -> Msg + 'ctx,

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.

Source

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,

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.

Source

pub fn get_value<F, Val>(&'ctx self, getter_factory: F) -> Val
where F: Fn(&'ctx ReadSignal<T>) -> Val + 'ctx,

Auto Trait Implementations§

§

impl<'ctx, D, T, Msg> Freeze for Handler<'ctx, D, T, Msg>

§

impl<'ctx, D, T, Msg> !RefUnwindSafe for Handler<'ctx, D, T, Msg>

§

impl<'ctx, D, T, Msg> !Send for Handler<'ctx, D, T, Msg>

§

impl<'ctx, D, T, Msg> !Sync for Handler<'ctx, D, T, Msg>

§

impl<'ctx, D, T, Msg> Unpin for Handler<'ctx, D, T, Msg>
where Msg: Unpin,

§

impl<'ctx, D, T, Msg> !UnwindSafe for Handler<'ctx, D, T, Msg>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.