Skip to content

Instantly share code, notes, and snippets.

@Gethyl
Created January 16, 2017 04:10
Show Gist options
  • Save Gethyl/f835b99b9b94fdf9b95f544e36bf194a to your computer and use it in GitHub Desktop.
Save Gethyl/f835b99b9b94fdf9b95f544e36bf194a to your computer and use it in GitHub Desktop.
Understanding redux-thunk
// createThunkMiddleware from redux-thunk.js
export function createThunkMiddleware(extraArgument) {
return function thunkFunction ({ dispatch, getState }) {
return function nextFunction (next) {
console.info("In next function")
console.dir(next)
return function actionFunction (action) {
console.info("action RETURNED")
console.dir(action)
if (typeof action === 'function') {
console.info("++++++++++++++++++++++++++++++++++++++")
console.info("action is function")
console.info("++++++++++++++++++++++++++++++++++++++")
return action(dispatch, getState, extraArgument);
}
console.info("+++++++++++++++++calling NEXT++++++++++++++")
console.dir(next)
return next(action);
}
}
}
}
const thunk = createThunkMiddleware();
thunk.withExtraArgument = createThunkMiddleware;
export default thunk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment