Created
January 16, 2017 04:10
-
-
Save Gethyl/f835b99b9b94fdf9b95f544e36bf194a to your computer and use it in GitHub Desktop.
Understanding redux-thunk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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