pub struct Store<State, Action, RootReducer> where
State: Send,
RootReducer: Send, { /* 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
sourceimpl<State, Action, RootReducer> Store<State, Action, RootReducer> where
Action: Send + 'static,
RootReducer: Reducer<State, Action> + Send + 'static,
State: Send + 'static,
impl<State, Action, RootReducer> Store<State, Action, RootReducer> where
Action: Send + 'static,
RootReducer: Reducer<State, Action> + Send + 'static,
State: Send + 'static,
sourcepub fn new(root_reducer: RootReducer) -> Self where
State: Default,
pub fn new(root_reducer: RootReducer) -> Self where
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: Selector<State, Result = Result>, Result>(
&self,
selector: S
) -> Result where
S: Selector<State, Result = Result> + Send + 'static,
Result: Send + 'static,
pub async fn select<S: Selector<State, Result = Result>, Result>(
&self,
selector: S
) -> Result where
S: Selector<State, Result = Result> + Send + 'static,
Result: Send + 'static,
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) -> State where
State: Clone,
pub async fn state_cloned(&self) -> State where
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> where
M: MiddleWare<State, OuterAction, Self, Action> + Send + Sync,
OuterAction: Send + Sync + 'static,
State: Sync,
Action: Sync,
RootReducer: Sync,
pub async fn wrap<M, OuterAction>(
self,
middleware: M
) -> StoreWithMiddleware<Self, M, State, Action, OuterAction> where
M: MiddleWare<State, OuterAction, Self, Action> + Send + Sync,
OuterAction: Send + Sync + 'static,
State: Sync,
Action: Sync,
RootReducer: Sync,
Wrap the store with middleware, see middleware module for more examples
Trait Implementations
sourceimpl<State, Action, RootReducer> StoreApi<State, Action> for Store<State, Action, RootReducer> where
Action: Send + Sync + 'static,
RootReducer: Reducer<State, Action> + Send + Sync + 'static,
State: Send + Sync + 'static,
impl<State, Action, RootReducer> StoreApi<State, Action> for Store<State, Action, RootReducer> where
Action: Send + Sync + 'static,
RootReducer: Reducer<State, Action> + Send + Sync + 'static,
State: Send + Sync + 'static,
sourcefn dispatch<'life0, 'async_trait>(
&'life0 self,
action: Action
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
fn dispatch<'life0, 'async_trait>(
&'life0 self,
action: Action
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
Dispatch a new action to the store Read more
sourcefn select<'life0, 'async_trait, S: Selector<State, Result = Result>, Result>(
&'life0 self,
selector: S
) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>> where
S: Selector<State, Result = Result> + Send + 'static,
Result: Send + 'static,
S: 'async_trait,
Result: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn select<'life0, 'async_trait, S: Selector<State, Result = Result>, Result>(
&'life0 self,
selector: S
) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>> where
S: Selector<State, Result = Result> + Send + 'static,
Result: Send + 'static,
S: 'async_trait,
Result: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
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. Read more
sourcefn state_cloned<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = State> + Send + 'async_trait>> where
State: Clone,
'life0: 'async_trait,
Self: 'async_trait,
fn state_cloned<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = State> + Send + 'async_trait>> where
State: Clone,
'life0: 'async_trait,
Self: 'async_trait,
Returns a cloned version of the state. This is not efficient, if you only need a part of the state use select instead Read more
sourcefn subscribe<'life0, 'async_trait, S: Subscriber<State> + Send + 'static>(
&'life0 self,
subscriber: S
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where
S: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn subscribe<'life0, 'async_trait, S: Subscriber<State> + Send + 'static>(
&'life0 self,
subscriber: S
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where
S: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
Subscribe to state changes. Every time an action is dispatched the subscriber will be notified after the state is updated Read more
Auto Trait Implementations
impl<State, Action, RootReducer> !RefUnwindSafe for Store<State, Action, RootReducer>
impl<State, Action, RootReducer> Send for Store<State, Action, RootReducer>
impl<State, Action, RootReducer> Sync for Store<State, Action, RootReducer> where
RootReducer: Sync,
impl<State, Action, RootReducer> Unpin for Store<State, Action, RootReducer> where
RootReducer: Unpin,
impl<State, Action, RootReducer> !UnwindSafe for Store<State, Action, RootReducer>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more