MENU
compose()
compose() is used when you want to pass multiple store enhancers to the store. Store enhancers are higher order functions that add some extra functionality to the store. The only store enhancer which is supplied with Redux by default is applyMiddleware() however many other are available, eg. DevTools.
This example is identical to the previous one..
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.compose(Redux.applyMiddleware(alerter), Redux.applyMiddleware(alerter)));
</script>
</body>
</html>