@@ -18,38 +18,51 @@ function bindInterceptors(client, injectedParameters, middlewareInterceptors = {
1818 } ) ;
1919}
2020
21+ function getSourceAction ( config ) {
22+ return config . reduxSourceAction ;
23+ }
24+
2125export const multiClientMiddleware = ( clients , customMiddlewareOptions ) => {
2226 const middlewareOptions = { ...defaultOptions , ...customMiddlewareOptions } ;
2327 const setupedClients = { } ;
24- let storedAction ;
28+
2529 return ( { getState, dispatch } ) => next => action => {
2630 if ( ! middlewareOptions . isAxiosRequest ( action ) ) {
2731 return next ( action ) ;
2832 }
29- storedAction = action ;
33+
3034 const clientName = middlewareOptions . getClientName ( action ) || middlewareOptions . defaultClientName ;
35+
3136 if ( ! clients [ clientName ] ) {
3237 throw new Error ( `Client with name "${ clientName } " has not been defined in middleware` ) ;
3338 }
39+
3440 if ( ! setupedClients [ clientName ] ) {
3541 const clientOptions = { ...middlewareOptions , ...clients [ clientName ] . options } ;
42+
3643 if ( clientOptions . interceptors ) {
37- const getAction = ( ) => storedAction ;
3844 const middlewareInterceptors = middlewareOptions . interceptors ;
3945 const clientInterceptors = clients [ clientName ] . options && clients [ clientName ] . options . interceptors ;
40- const injectToInterceptor = { getState, dispatch, action, getAction } ;
46+ const injectToInterceptor = { getState, dispatch, action, getSourceAction } ;
4147 bindInterceptors ( clients [ clientName ] . client , injectToInterceptor , middlewareInterceptors , clientInterceptors ) ;
4248 }
49+
4350 setupedClients [ clientName ] = {
4451 client : clients [ clientName ] . client ,
4552 options : clientOptions
4653 } ;
4754 }
55+
4856 const setupedClient = setupedClients [ clientName ] ;
4957 const actionOptions = { ...setupedClient . options , ...setupedClient . options . getRequestOptions ( action ) } ;
5058 const [ REQUEST ] = getActionTypes ( action , actionOptions ) ;
5159 next ( { ...action , type : REQUEST } ) ;
52- return setupedClient . client . request ( actionOptions . getRequestConfig ( action ) )
60+
61+ const requestConfig = {
62+ ...actionOptions . getRequestConfig ( action ) ,
63+ reduxSourceAction : action
64+ } ;
65+ return setupedClient . client . request ( requestConfig )
5366 . then (
5467 ( response ) => {
5568 const newAction = actionOptions . onSuccess ( { action, next, response, getState, dispatch } , actionOptions ) ;
0 commit comments