hyper/lib/utils/effects.ts
2020-03-25 17:12:51 +01:00

18 lines
537 B
TypeScript

/**
* Simple redux middleware that executes
* the `effect` field if provided in an action
* since this is preceded by the `plugins`
* middleware. It allows authors to interrupt,
* defer or add to existing side effects at will
* as the result of an action being triggered.
*/
import {Middleware} from 'redux';
const effectsMiddleware: Middleware = () => (next) => (action) => {
const ret = next(action);
if (action.effect) {
action.effect();
delete action.effect;
}
return ret;
};
export default effectsMiddleware;