Trait StoreApi

Source
pub trait StoreApi<State, Action>
where Action: Send + 'static, State: Send + 'static,
{ // Required methods fn dispatch<'life0, 'async_trait>( &'life0 self, action: Action, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; 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; 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; // Provided method fn state_cloned<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = State> + Send + 'async_trait>> where State: Clone, Self: Sync + 'async_trait, 'life0: 'async_trait { ... } }
Expand description

The store api offers an abstraction around all store functionality.

Both Store and StoreWithMiddleware implement StoreApi. This enables us to wrap multiple middlewares around each other.

Required Methods§

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

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

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

Provided Methods§

Source

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<Inner, M, State, InnerAction, OuterAction> StoreApi<State, OuterAction> for StoreWithMiddleware<Inner, M, State, InnerAction, OuterAction>
where Inner: StoreApi<State, InnerAction> + Send + Sync, M: MiddleWare<State, OuterAction, Inner, InnerAction> + Send + Sync, State: Send + Sync + 'static, InnerAction: Send + Sync + 'static, OuterAction: Send + Sync + 'static,

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,