[][src]Macro kayrx_ui::combine_reducers

macro_rules! combine_reducers {
    ($state:ty, $action:ty, $reducer:ident) => { ... };
    ($state:ty, $action:ty, $first:ident, $($second:ident),+) => { ... };
}

Combines multiple reducers into a single one.

The first one gets called first, chained into the second one and so on...

Usage

let reducer: Reducer<State, Action> = combine_reducers!(State, &Action, first_reducer, second_reducer, third_reducer);

(State and Action being the actual types.)

Example

enum Action {
    Increment,
    Decrement
}

fn counter_reducer(state: &u8, action: &Action) -> u8 {
    match action {
        Action::Increment => state + 1,
        Action::Decrement => state - 1
    }
}

fn add_two_reducer(state: &u8, _: &Action) -> u8 {
    state + 2
}

fn main() {
    let reducer: Reducer<u8, Action> = combine_reducers!(u8, &Action, counter_reducer, add_two_reducer);
}