pub struct Store<State, Action, RootReducer>{ /* private fields */ }
Expand description
The store is the heart of any redux application, it contains the state of the application.
The state of the store can be modified by dispatching actions to it. Updates to the state can be observed by subscribing to the store or by writing middleware. Getting a part of the store or the full store is possible with the select and state_cloned methods.
Implementations§
Source§impl<State, Action, RootReducer> Store<State, Action, RootReducer>
impl<State, Action, RootReducer> Store<State, Action, RootReducer>
Sourcepub fn new(root_reducer: RootReducer) -> Selfwhere
State: Default,
pub fn new(root_reducer: RootReducer) -> Selfwhere
State: Default,
Create a new store with the given root reducer and default state
Sourcepub fn new_with_state(root_reducer: RootReducer, state: State) -> Self
pub fn new_with_state(root_reducer: RootReducer, state: State) -> Self
Create a new store with the given root reducer and the provided state
Sourcepub async fn dispatch(&self, action: Action)
pub async fn dispatch(&self, action: Action)
Dispatch a new action to the store
Notice that this method takes &self and not &mut self, this enables us to dispatch actions from multiple places at once without requiring locks.
Sourcepub async fn select<S, Result>(&self, selector: S) -> Result
pub async fn select<S, Result>(&self, selector: S) -> Result
Select a part of the state, this is more efficient than copying the entire state all the time. In case you still need a full copy of the state, use the state_cloned method.
Sourcepub async fn state_cloned(&self) -> Statewhere
State: Clone,
pub async fn state_cloned(&self) -> Statewhere
State: Clone,
Returns a cloned version of the state. This is not efficient, if you only need a part of the state use select instead
Sourcepub async fn subscribe<S: Subscriber<State> + Send + 'static>(
&self,
subscriber: S,
)
pub async fn subscribe<S: Subscriber<State> + Send + 'static>( &self, subscriber: S, )
Subscribe to state changes. Every time an action is dispatched the subscriber will be notified after the state is updated
Sourcepub async fn wrap<M, OuterAction>(
self,
middleware: M,
) -> StoreWithMiddleware<Self, M, State, Action, OuterAction>
pub async fn wrap<M, OuterAction>( self, middleware: M, ) -> StoreWithMiddleware<Self, M, State, Action, OuterAction>
Wrap the store with middleware, see middleware module for more examples