Struct StoreRef

Source
pub struct StoreRef<State, Action, Event, Effect>(/* private fields */);
Expand description

A wrapper for an Rc reference to a Store.

This wrapper exists to provide a standard interface for re-useable middleware and other components which may require a long living reference to the store in order to dispatch actions or modify it in some manner that could not be handled by a simple &Store.

Implementations§

Source§

impl<State, Action, Event, Effect> StoreRef<State, Action, Event, Effect>
where Event: Clone + Hash + Eq,

Source

pub fn new<R: Reducer<State, Action, Event, Effect> + 'static>( reducer: R, initial_state: State, ) -> Self

Methods from Deref<Target = Store<State, Action, Event, Effect>>§

Source

pub fn state(&self) -> Rc<State>

Get the current State stored in this store.

Modifications to this state need to be performed by dispatching an Action to the store using dispatch().

Source

pub fn dispatch<A: Into<Action>>(&self, action: A)

Dispatch an Action to be passed to the Reducer in order to modify the State in this store, and produce Events to be sent to the store listeners.

Source

pub fn subscribe<L: AsListener<State, Event>>(&self, listener: L)

Subscribe a Listener to changes in the store state and events produced by the Reducer as a result of Actions dispatched via dispatch().

The listener is a weak reference; when the strong reference associated with it (usually Callback) is dropped, the listener will be removed from this store upon dispatch().

If you want to subscribe to state changes associated with specific Events, see subscribe_event() or subscribe_event()

Source

pub fn subscribe_event<L: AsListener<State, Event>>( &self, listener: L, event: Event, )

Subscribe a Listener to changes in the store state and events produced by the Reducer as a result of Actions being dispatched via dispatch() and reduced with the store’s Reducer. This subscription is only active changes which produce the specific matching event from the Reducer.

The listener is a weak reference; when the strong reference associated with it (usually Callback) is dropped, the listener will be removed from this store upon dispatch().

Source

pub fn subscribe_events<L: AsListener<State, Event>, E: IntoIterator<Item = Event>>( &self, listener: L, events: E, )

Subscribe a Listener to changes in the store state and events produced by the Reducer as a result of Actions being dispatched via dispatch() and reduced with the store’s Reducer. This subscription is only active changes which produce any of the specific matching events from the Reducer.

The listener is a weak reference; when the strong reference associated with it (usually Callback) is dropped, the listener will be removed from this store upon dispatch().

Source

pub fn add_middleware<M: Middleware<State, Action, Event, Effect> + 'static>( &self, middleware: M, )

Add Middleware to modify the behaviour of this Store during a dispatch().

Trait Implementations§

Source§

impl<State, Action, Event, Effect> Clone for StoreRef<State, Action, Event, Effect>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<State, Action, Event, Effect> Deref for StoreRef<State, Action, Event, Effect>

Source§

type Target = Store<State, Action, Event, Effect>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<State, Action, Event, Effect> PartialEq for StoreRef<State, Action, Event, Effect>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<State, Action, Event, Effect> Freeze for StoreRef<State, Action, Event, Effect>

§

impl<State, Action, Event, Effect> !RefUnwindSafe for StoreRef<State, Action, Event, Effect>

§

impl<State, Action, Event, Effect> !Send for StoreRef<State, Action, Event, Effect>

§

impl<State, Action, Event, Effect> !Sync for StoreRef<State, Action, Event, Effect>

§

impl<State, Action, Event, Effect> Unpin for StoreRef<State, Action, Event, Effect>

§

impl<State, Action, Event, Effect> !UnwindSafe for StoreRef<State, Action, Event, Effect>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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, V> IntoOptPropValue<V> for T
where T: IntoPropValue<Option<V>>,

Source§

fn into_opt_prop_value(self) -> Option<V>

Convert self to an optional value of a Properties struct.
Source§

impl<T> IntoPropValue<Option<T>> for T

Source§

fn into_prop_value(self) -> Option<T>

Convert self to a value of a Properties struct.
Source§

impl<T> IntoPropValue<T> for T

Source§

fn into_prop_value(self) -> T

Convert self to a value of a Properties struct.
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> Any for T
where T: Any,

Source§

impl<T> CloneAny for T
where T: Any + Clone,