1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
use crate::*;
pub fn redux<
V: View,
A: 'static,
S: 'static,
D: Fn() -> S + 'static,
F: Fn(&S) -> V + 'static,
R: Fn(&mut S, &A) + 'static + Clone,
>(
initial: D,
reducer: R,
f: F,
) -> impl View {
state(initial, move |state_handle, cx| {
let r = reducer.clone();
f(&cx[state_handle]).handle(move |cx, action: &A| r(&mut cx[state_handle], action))
})
}