MENU
applyMiddleware()
The middleware signature is ({ getState, dispatch }) => next => action
next(action), when invoking the reducer at the last stage of the pipeline, returns the action itself, and not the updated state. The call is synchronous.
RESETRUNFULL
RESETRUNFULL
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/redux@latest/dist/redux.min.js"></script>
</head>
<body>
<button onclick="store.dispatch({type: 'multiply', factor: 10})">Dispatch</button>
<script>
const reducer = (state, action) => {
alert(state);
return (action.type=="multiply") ? state * action.factor : state;
};
const alerter = ({ getState }) => next => action => {
alert(getState()+" ...before");
const v = getState() * next(action).factor;
alert(v+" ...after");
return action;
};
const store = Redux.createStore(reducer, 1, Redux.applyMiddleware(alerter, alerter));
</script>
</body>
</html>