what if your reducers were generators?

November 20, 2015 ยท View on GitHub

// You can defer the side-effect execution in middlewares const sideEffect = appState => dispatch => localStorage.setItem('counter', appState);

function plainOldReducer(appState) { return appState + 1; }

// Composition simply work function nestedReducer*(appState, action) { if (action === FOO) { yield sideEffect(appState); return plainOldReducer(appState); } else { return appState; } }

function rootReducer*(appState = 0, action) { return yield* nestedReducer(appState, action); }