Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
23 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
export default function thunkMiddleware({ dispatch, getState }) { | ||
return next => action => { | ||
function createThunkMiddleware(extraArgument) { | ||
return ({ dispatch, getState }) => next => action => { | ||
if (typeof action === 'function') { | ||
return action(dispatch, getState); | ||
return action(dispatch, getState, extraArgument); | ||
} | ||
|
||
return next(action); | ||
}; | ||
} | ||
|
||
const thunk = createThunkMiddleware(); | ||
thunk.withExtraArgument = createThunkMiddleware; | ||
|
||
export default 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
41aefcc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gaearon I've been studying the redux source to learn various functional programming techniques and was curious - may I ask why this particular code change happened (or what it enabled)? Thanks!
41aefcc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@QuotableWater7 It's just an extension to work with external API and be able to mock that in tests.
41aefcc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TrySound thanks!
41aefcc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!