1 2 3 4 5 6 7 8 9 < span class="line">10 11 12 13 14 15 16 17 18 19 20< br>21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39< /span> 40
|
< span class="function">function createThunkMiddleware(extraArgument) span>{ return ({ dispatch , getState }) => next => action => { if (typeof action === 'function') { return action(dispatch, getState, extraArgument); }
return next (action); }; }
const thunk = createThunkMiddleware(); thunk.withExtraArgument = createThunkMiddleware;
{ getState: store.getState, dispatch: (...args) => dispatch(...args) }
if action is a function, thunk middleware will intercept execution action, If action is an object, execute next method, next is thunk next middleware action => {... }, Because action is normally an object under normal circumstances, the method will always be executed according to the middleware array order
action => { if (typeof action === 'function') { return< /span> action(dispatch, getState, extraArgument); }
return next(action); }
Here is a little question Is action(dispatch, getState, extraArgument)
The dispatch in action is an empty method, but Finally, applyMiddleWare dispatch will be overwritten at the end The previous v3 dispatch is store.dispatch, and the later v4 dispatch is changed to an empty method, then here is dispatch< br>The method has no dispatch function, please refer to this [issue](https: If you still understand what is here, welcome to communicate
|