tca/
reducer.rs

1use crate::{Effect, Store};
2
3/// A protocol that describes how to evolve the current state of an application to the next state,
4/// given an action, and describes what ``Effect``s should be executed later by the store, if any.
5pub trait Reducer<State, Action: Send> {
6    fn reduce(state: &mut State, action: Action) -> Effect<Action>;
7
8    /// Heler for quickly initiating store from any `Feature` that implements reducer for any
9    /// initial state
10    fn store(initial_state: State) -> Store<State, Action>
11    where
12        Self: Send + Sync + Sized + 'static,
13        Action: std::fmt::Debug + Send + 'static,
14        State: PartialEq + Clone + Send + Sync + 'static,
15    {
16        Store::new::<Self>(initial_state)
17    }
18
19    /// Heler for quickly initiating store from any `Feature` that implements reducer for default
20    /// state
21    fn default_store() -> Store<State, Action>
22    where
23        Self: Send + Sync + Sized + 'static,
24        Action: std::fmt::Debug + Send + 'static,
25        State: Default + PartialEq + Clone + Send + Sync + 'static,
26    {
27        Store::new::<Self>(State::default())
28    }
29}