File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 1
- export default function thunkMiddleware ( { dispatch , getState } ) {
2
- return next => action => {
1
+ function createThunkMiddleware ( extraArgument ) {
2
+ return ( { dispatch , getState } ) => next => action => {
3
3
if ( typeof action === 'function' ) {
4
- return action ( dispatch , getState ) ;
4
+ return action ( dispatch , getState , extraArgument ) ;
5
5
}
6
6
7
7
return next ( action ) ;
8
8
} ;
9
9
}
10
+
11
+ const thunk = createThunkMiddleware ( ) ;
12
+ thunk . withExtraArgument = createThunkMiddleware ;
13
+
14
+ export default thunk ;
Original file line number Diff line number Diff line change @@ -76,4 +76,19 @@ describe('thunk middleware', () => {
76
76
}
77
77
} ) ;
78
78
} ) ;
79
+
80
+ describe ( 'withExtraArgument' , ( ) => {
81
+ it ( 'must pass the third argument' , done => {
82
+ const extraArg = { lol : true } ;
83
+ thunkMiddleware . withExtraArgument ( extraArg ) ( {
84
+ dispatch : doDispatch ,
85
+ getState : doGetState ,
86
+ } ) ( ) ( ( dispatch , getState , arg ) => {
87
+ chai . assert . strictEqual ( dispatch , doDispatch ) ;
88
+ chai . assert . strictEqual ( getState , doGetState ) ;
89
+ chai . assert . strictEqual ( arg , extraArg ) ;
90
+ done ( ) ;
91
+ } ) ;
92
+ } ) ;
93
+ } ) ;
79
94
} ) ;
You can’t perform that action at this time.
0 commit comments