Skip to content

Instantly share code, notes, and snippets.

@r3dm1ke
Last active February 15, 2020 17:42
Show Gist options
  • Select an option

  • Save r3dm1ke/4d007dc8877955daeaa17a82b813cfb5 to your computer and use it in GitHub Desktop.

Select an option

Save r3dm1ke/4d007dc8877955daeaa17a82b813cfb5 to your computer and use it in GitHub Desktop.
const createInterceptorMiddleware = (interceptors) => (store) => (next) => (action) => {
interceptors
.filter(interceptor => interceptor.type === action.type)
.forEach(interceptor => interceptor.handler(action, store.dispatch, store.getState));
next(action);
}
const interceptors = [
{type: 'INCREMENT', handler: () => doSomeApiStuff()},
{type: 'DECREMENT', handler: () => doOtherApiStuff()}
];
const middleware = createInterceptorMiddleware(interceptors);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment