pub trait StoreApi<State, Action>{
// 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§
Sourcefn dispatch<'life0, 'async_trait>(
&'life0 self,
action: Action,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
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.
Sourcefn select<'life0, 'async_trait, S, Result>(
&'life0 self,
selector: S,
) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>>
fn select<'life0, 'async_trait, S, Result>( &'life0 self, selector: S, ) -> Pin<Box<dyn Future<Output = Result> + Send + '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.
Sourcefn 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,
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§
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.