pub trait Middleware<State, Action, Event, Effect> {
// Provided methods
fn on_reduce(
&self,
store: &Store<State, Action, Event, Effect>,
action: Option<&Action>,
reduce: ReduceFn<State, Action, Event, Effect>,
) -> ReduceMiddlewareResult<Event, Effect> { ... }
fn process_effect(
&self,
_store: &Store<State, Action, Event, Effect>,
effect: Effect,
) -> Option<Effect> { ... }
fn on_notify(
&self,
store: &Store<State, Action, Event, Effect>,
events: Vec<Event>,
notify: NotifyFn<State, Action, Event, Effect>,
) -> Vec<Event> { ... }
}Expand description
Middleware used to modify the behaviour of a Store during a
Store::dispatch().
Provided Methods§
Sourcefn on_reduce(
&self,
store: &Store<State, Action, Event, Effect>,
action: Option<&Action>,
reduce: ReduceFn<State, Action, Event, Effect>,
) -> ReduceMiddlewareResult<Event, Effect>
fn on_reduce( &self, store: &Store<State, Action, Event, Effect>, action: Option<&Action>, reduce: ReduceFn<State, Action, Event, Effect>, ) -> ReduceMiddlewareResult<Event, Effect>
This method is invoked by the Store during a
Store::dispatch() just before the Action is sent to the
Reducer. It is necessary to call the
provided reduce function, which executes subsequent
middleware and runs the Reducer, and usually
the events produced by the reduce function are returned from
this method.
This method allows modifying the action in question, or even removing it, preventing the Reducer from processing the action. It also allows modifying the events produced by the Reducer before the Middleware::on_notify() is invoked and they are sent to the Store listeners.
Sourcefn process_effect(
&self,
_store: &Store<State, Action, Event, Effect>,
effect: Effect,
) -> Option<Effect>
fn process_effect( &self, _store: &Store<State, Action, Event, Effect>, effect: Effect, ) -> Option<Effect>
Process an Effect. Returns None if the effect was
processed/consumed by this handler, otherwise returns
Some(effect).
Sourcefn on_notify(
&self,
store: &Store<State, Action, Event, Effect>,
events: Vec<Event>,
notify: NotifyFn<State, Action, Event, Effect>,
) -> Vec<Event>
fn on_notify( &self, store: &Store<State, Action, Event, Effect>, events: Vec<Event>, notify: NotifyFn<State, Action, Event, Effect>, ) -> Vec<Event>
This method is invoked by the Store during a
Store::dispatch() after the Reducer has
processed the Action and all Middleware::on_reduce()
methods have completed, just before resulting events are
sent to the store listeners. It is necessary to call the
provided notify function, which executes subsequent
middleware and then notifies the listeners.
This method allows modifying the events in question before the listeners are notified.
Implementors§
impl<State, Action, Event, Effect> Middleware<State, Action, Event, Effect> for SimpleLoggerMiddleware
simple_logger only.impl<State, Action, Event, Effect> Middleware<State, Action, Event, Effect> for WebLoggerMiddleware
web_logger only.