Skip to content

Instantly share code, notes, and snippets.

@beaucollins
Created January 8, 2019 21:01
Show Gist options
  • Select an option

  • Save beaucollins/62a2d5c5733f8a0dd448b8d4aca2131b to your computer and use it in GitHub Desktop.

Select an option

Save beaucollins/62a2d5c5733f8a0dd448b8d4aca2131b to your computer and use it in GitHub Desktop.
function asyncReaction<T: ActionTypes>(detector: Detector<T>, handler: Handler<T>): AppMiddleware {
return store => next => action => {
const detected = detector(action);
if (detected !== null) {
handler(detected, store.getState()).then(store.dispatch);
}
return next(action);
}
}
const middleware = asyncReaction(isProjectsCreate, createProjectHTTP);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment