pub trait Reducer<State, Action> {
fn reduce(&self, state: State, action: Action) -> State;
}
Expand description
Reducer trait
A reducer is responsible to calculate the next state based on the current state and an action.
You can do this by implementing the Reducer
or a function with the signature Fn(State, Action) -> State
Trait example
use redux_rs::Reducer;
enum Action {
Increment,
Decrement,
}
impl Reducer<u8, Action> for u8 {
fn reduce(&self, state: u8, action: Action) -> u8 {
match action {
Action::Increment => state + 1,
Action::Decrement => state - 1,
}
}
}
Fn example
use redux_rs::Reducer;
enum Action {
Increment,
Decrement,
}
fn reduce(state: u8, action: Action) -> u8 {
match action {
Action::Increment => state + 1,
Action::Decrement => state - 1,
}
}