#[cfg(feature = "simple_logger")]
#[cfg_attr(docsrs, doc(cfg(feature = "simple_logger")))]
pub mod simple_logger;
#[cfg(feature = "web_logger")]
#[cfg_attr(docsrs, doc(cfg(feature = "web_logger")))]
pub mod web_logger;
use crate::Store;
pub struct ReduceMiddlewareResult<Event, Effect> {
pub events: Vec<Event>,
pub effects: Vec<Effect>,
}
impl<Event, Effect> Default for ReduceMiddlewareResult<Event, Effect> {
fn default() -> Self {
ReduceMiddlewareResult {
events: Vec::new(),
effects: Vec::new(),
}
}
}
pub type ReduceFn<State, Action, Event, Effect> = fn(
&Store<State, Action, Event, Effect>,
Option<&Action>,
) -> ReduceMiddlewareResult<Event, Effect>;
pub type NotifyFn<State, Action, Event, Effect> =
fn(&Store<State, Action, Event, Effect>, Vec<Event>) -> Vec<Event>;
pub trait Middleware<State, Action, Event, Effect> {
fn on_reduce(
&self,
store: &Store<State, Action, Event, Effect>,
action: Option<&Action>,
reduce: ReduceFn<State, Action, Event, Effect>,
) -> ReduceMiddlewareResult<Event, Effect> {
reduce(store, action)
}
fn process_effect(
&self,
_store: &Store<State, Action, Event, Effect>,
effect: Effect,
) -> Option<Effect> {
Some(effect)
}
fn on_notify(
&self,
store: &Store<State, Action, Event, Effect>,
events: Vec<Event>,
notify: NotifyFn<State, Action, Event, Effect>,
) -> Vec<Event> {
notify(store, events)
}
}