Trait reactive_state::Reducer[][src]

pub trait Reducer<State, Action, Event, Effect> {
    fn reduce(
        &self,
        prev_state: &Rc<State>,
        action: &Action
    ) -> ReducerResult<State, Event, Effect>; }
Expand description

Using the reduce() method, implementors of this trait take an Action submitted to a store via Store::dispatch() and modifies the State in the store, producing a new State, and also producing events and effects associated with the Action and state modifications that occurred.

For an example of how a reducer function should work, see ReducerFn. For an example of how to use one in conjunction with a Store, see reactive_state.

Required methods

fn reduce(
    &self,
    prev_state: &Rc<State>,
    action: &Action
) -> ReducerResult<State, Event, Effect>
[src]

Take an Action submitted to a store via Store::dispatch() and modifies the prev_state, producing a new State, and also producing events associated with the Action and state modifications that occurred.

Note: If no Events are returned then it is assumed that the state has not changed, and store listeners do not need to be notified.

Note: If all Eventss are Event::none(), then it is also assumed that the state has not changed, and store listeners do not need to be notified.

This method should be a pure function, with any required side effects being emmitted via the returned ReducerResult.

Eventss should generally be treated purely as a notification that some subset of the state has been modified, such that playing the events and state transitions in reverse will result in the same application behaviour.

Effects are side effects invoked as a result of the action, these may involve dispatching further actions, or modifying some other part of the system that the store is involved with. Effects are processed using Middleware which has been added to the Store.

Implementors

impl<State, Action, Event, Effect> Reducer<State, Action, Event, Effect> for CompositeReducer<State, Action, Event, Effect>[src]

fn reduce(
    &self,
    prev_state: &Rc<State>,
    action: &Action
) -> ReducerResult<State, Event, Effect>
[src]

impl<T, State, Action, Event, Effect> Reducer<State, Action, Event, Effect> for T where
    T: Fn(&Rc<State>, &Action) -> ReducerResult<State, Event, Effect>, 
[src]

fn reduce(
    &self,
    prev_state: &Rc<State>,
    action: &Action
) -> ReducerResult<State, Event, Effect>
[src]