Bring all of it together
const store = {
state: {},
dispatch: (action) => {},
subscribe: (listener) => {},
getState: () => {},
}
const action = {
type: 'INIT_SPEAKERS',
payload: [
'Chris',
'Stefan',
'Patrick',
],
}
const initialState = { ... };
const reducer = (state = initialState, action) => {
let nextState = {};
// ...
// Code that creates new state using
// the previous state and action
// ...
return nextState;
};
const actions = [action1, action2, action3];
const reducer = () => { ... }
actions
.reduce(
(lastState, action) => reducer(lastState, action),
initialState
);
actions
.reduce(reducer, initialState);
import { of } from 'rxjs';
import { reduce } from 'rxjs/operators';
const actionStream = of(action1, action2, action3);
const stateStream = actionStream
.pipe(
reduce(reducer, initialState),
);