2016-10-10 02:26:47 -08:00
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2020-01-02 08:49:57 -09:00
|
|
|
import {Middleware} from 'redux';
|
2020-03-25 02:15:08 -08:00
|
|
|
const effectsMiddleware: Middleware = () => (next) => (action) => {
|
2016-07-13 12:44:24 -08:00
|
|
|
const ret = next(action);
|
|
|
|
|
if (action.effect) {
|
|
|
|
|
action.effect();
|
|
|
|
|
delete action.effect;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
};
|
2020-01-02 08:49:57 -09:00
|
|
|
export default effectsMiddleware;
|