[][src]Struct reactive_state::Store

pub struct Store<State, Action, Event, Effect> { /* fields omitted */ }

This struct is designed to operate as a central source of truth and global "immutable" state within your application.

The current state of this store (Store::state()) can only be modified by dispatching an Action via Store::dispatch() to the store. These actions are taken by a Reducer which you provided to the store (at construction) and a new current state is produced. The reducer also produces Events associated with the change. The previous state is never mutated, and remains as a reference for any element of your application which may rely upon it (ensure that it gets dropped when it is no longer required, lest it become a memory leak when large States are involved).

Listeners can susbscribe to changes to the State in this store (and Events produced) with Store::subscribe(), or they can also subscribe to changes associated with specific Events via subscribe_event()/subscribe_events().

Implementations

impl<State, Action, Event, Effect> Store<State, Action, Event, Effect> where
    Event: StoreEvent + Clone + Hash + Eq
[src]

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

Create a new Store, which uses the specified reducer to handle Actions which mutate the state and produce Events, and with the initial_state.

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

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().

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

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.

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

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()

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

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().

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

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().

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

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

Auto Trait Implementations

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

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

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

impl<State, Action, Event, Effect> Unpin for Store<State, Action, Event, Effect> where
    Action: Unpin,
    Event: Unpin

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Any for T where
    T: Any

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.