pub struct ReducerBinding<R: Reducer> { /* private fields */ }Expand description
A handle to one reducer’s state and actions inside one scope.
Names the scope and holds the state cell: reading keeps working after the scope is removed (the last frame of a page being navigated away from still renders), while pushing and subscribing quietly stop.
Implementations§
Source§impl<R: Reducer> ReducerBinding<R>
impl<R: Reducer> ReducerBinding<R>
Sourcepub fn peek(&self) -> Ref<'_, R>
pub fn peek(&self) -> Ref<'_, R>
Borrows the state in place, for as long as nothing changes it.
Sourcepub fn get(&self) -> Rc<R>
pub fn get(&self) -> Rc<R>
The state as it is now, shared rather than copied. A change made while it is held goes to a copy, so what was read stays as it was.
Sourcepub fn dispatch(&self) -> Dispatch
pub fn dispatch(&self) -> Dispatch
What may be asked of the actors in the scope that owns this reducer.
Sourcepub fn push(&self, update: R::Update)
pub fn push(&self, update: R::Update)
Applies an update directly, without an actor in between. A no-op once the owning scope is gone.
Sourcepub fn on_change(&self, f: impl Fn(&R) + 'static) -> Subscription
pub fn on_change(&self, f: impl Fn(&R) + 'static) -> Subscription
Calls f after every change, until the returned Subscription is
dropped.
The caller owns the lifetime, which is what a reconciler needs: the subscription must end with the component instance, not with the scope, or unmounted components accumulate as live listeners.
Sourcepub fn on_change_owned(&self, f: impl Fn(&R) + 'static)
pub fn on_change_owned(&self, f: impl Fn(&R) + 'static)
Like Self::on_change, but the subscription lives as long as the
scope - for backends with no effect system to hang a cleanup on.
Sourcepub fn bind(&self, f: impl Fn(&R) + 'static) -> Subscription
pub fn bind(&self, f: impl Fn(&R) + 'static) -> Subscription
Calls f immediately with the current state, then after every change.