Struct Store

Source
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§

Source§

impl<State, Action, RootReducer> Store<State, Action, RootReducer>
where Action: Send + 'static, RootReducer: Reducer<State, Action> + Send + 'static, State: Send + 'static,

Source

pub fn new(root_reducer: RootReducer) -> Self
where State: Default,

Create a new store with the given root reducer and default state

Source

pub fn new_with_state(root_reducer: RootReducer, state: State) -> Self

Create a new store with the given root reducer and the provided state

Source

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.

Source

pub async fn select<S, 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.

Source

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

Source

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

Source

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§

Source§

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,

Source§

fn dispatch<'life0, 'async_trait>( &'life0 self, action: Action, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Dispatch a new action to the store Read more
Source§

fn select<'life0, 'async_trait, S, Result>( &'life0 self, selector: S, ) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>>
where S: Selector<State, Result = Result> + Send + 'static + 'async_trait, Result: Send + 'static + 'async_trait, Self: 'async_trait, 'life0: '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.
Source§

fn state_cloned<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = State> + Send + 'async_trait>>
where State: Clone, Self: 'async_trait, 'life0: '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
Source§

fn subscribe<'life0, 'async_trait, S>( &'life0 self, subscriber: S, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where S: 'async_trait + Subscriber<State> + Send + 'static, Self: 'async_trait, 'life0: 'async_trait,

Subscribe to state changes. Every time an action is dispatched the subscriber will be notified after the state is updated

Auto Trait Implementations§

§

impl<State, Action, RootReducer> Freeze for Store<State, Action, RootReducer>

§

impl<State, Action, RootReducer> RefUnwindSafe for Store<State, Action, RootReducer>
where RootReducer: RefUnwindSafe,

§

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>
where RootReducer: UnwindSafe,

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> 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, 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.