react-sweet-state
Version:
Global + local state combining the best of Redux and Context API
17 lines (13 loc) • 367 B
JavaScript
import shallowEqual from '../utils/shallow-equal';
const updateMiddleware = storeState => next => arg => {
let output;
const state = storeState.getState();
const nextState = next(state, arg, out => {
output = out;
});
if (!shallowEqual(nextState, state)) {
storeState.setState(nextState);
}
return output;
};
export default updateMiddleware;