function withRequestState(getRequestStatePath) {
  // thunk decorator:
  return thunkCreator =>
    // thunk creator:
    (...args) =>
      // thunk:
      async (dispatch, getState) => {
        const statePath = getRequestStatePath(...args);
        try {
          dispatch(setRequestLoading(statePath));

          const result = await thunkCreator(...args)(dispatch, getState);

          // Dispatch `setRequestLoaded` after clearing the call stack because
          // we want to the actual data to be updated before we notify
          // components that fetching the data is completed
          setTimeout(() => dispatch(setRequestLoaded(statePath)));

          return result;
        } catch (error) {
          console.error(`Request ${statePath.join(",")} failed:`, error);
          dispatch(setRequestError(statePath, error));
          throw error;
        }
      };
}
/**
 * Decorator that tracks the state of a request action
 */
Decorator that tracks the state of a request action
Decorator that tracks the state of a request action
function withRequestState(getRequestStatePath) {
  return thunkCreator =>
    (...args) =>
      async (dispatch, getState) => {
        const statePath = getRequestStatePath(...args);
        try {
          dispatch(setRequestLoading(statePath));
          const result = await thunkCreator(...args)(dispatch, getState);
          setTimeout(() => dispatch(setRequestLoaded(statePath)));
          return result;
        } catch (error) {
          console.error(`Request ${statePath.join(",")} failed:`, error);
          dispatch(setRequestError(statePath, error));
          throw error;
        }
      };
}
function withRequestState ( getRequestStatePath ) { return thunkCreator => ( ... args ) => async ( dispatch , getState ) => { const statePath = getRequestStatePath ( ... args ) ; try { dispatch ( setRequestLoading ( statePath ) ) ; const result = await thunkCreator ( ... args ) ( dispatch , getState ) ; setTimeout ( ( ) => dispatch ( setRequestLoaded ( statePath ) ) ) ; return result ; } catch ( error ) { console . error ( ` ${ statePath . join ( "," ) } ` , error ) ; dispatch ( setRequestError ( statePath , error ) ) ; throw error ; } } ; }
Decorator that tracks the state of a request action
Decorator that tracks the state of a request action
// thunk decorator: // thunk creator: // thunk: // Dispatch `setRequestLoaded` after clearing the call stack because // we want to the actual data to be updated before we notify // components that fetching the data is completed