function withAction(actionType) {
  return payloadOrThunkCreator => {
    function newCreator(...args) {
      const payloadOrThunk = payloadOrThunkCreator(...args);
      if (typeof payloadOrThunk === "function") {
        // thunk, return a new thunk
        return async (dispatch, getState) => {
          try {
            const payload = await payloadOrThunk(dispatch, getState);
            const dispatchValue = { type: actionType, payload: payload };
            dispatch(dispatchValue);

            return dispatchValue;
          } catch (error) {
            dispatch({ type: actionType, payload: error, error: true });
            throw error;
          }
        };
      } else {
        // payload, return an action
        return { type: actionType, payload: payloadOrThunk };
      }
    }
    newCreator.toString = () => actionType;
    return newCreator;
  };
}
/**
 * Decorator for turning a payload creator or thunk (including one returning a promise) into a flux standard action
 */
Decorator for turning a payload creator or thunk (including one returning a promise) into a flux standard action
Decorator for turning a payload creator or thunk ( including one returning a promise ) into a flux standard action
function withAction(actionType) {
  return payloadOrThunkCreator => {
    function newCreator(...args) {
      const payloadOrThunk = payloadOrThunkCreator(...args);
      if (typeof payloadOrThunk === "function") {
        return async (dispatch, getState) => {
          try {
            const payload = await payloadOrThunk(dispatch, getState);
            const dispatchValue = { type: actionType, payload: payload };
            dispatch(dispatchValue);
            return dispatchValue;
          } catch (error) {
            dispatch({ type: actionType, payload: error, error: true });
            throw error;
          }
        };
      } else {
        return { type: actionType, payload: payloadOrThunk };
      }
    }
    newCreator.toString = () => actionType;
    return newCreator;
  };
}
function withAction ( actionType ) { return payloadOrThunkCreator => { function newCreator ( ... args ) { const payloadOrThunk = payloadOrThunkCreator ( ... args ) ; if ( typeof payloadOrThunk === "function" ) { return async ( dispatch , getState ) => { try { const payload = await payloadOrThunk ( dispatch , getState ) ; const dispatchValue = { type : actionType , payload : payload } ; dispatch ( dispatchValue ) ; return dispatchValue ; } catch ( error ) { dispatch ( { type : actionType , payload : error , error : true } ) ; throw error ; } } ; } else { return { type : actionType , payload : payloadOrThunk } ; } } newCreator . toString = ( ) => actionType ; return newCreator ; } ; }
Decorator for turning a payload creator or thunk (including one returning a promise) into a flux standard action
Decorator for turning a payload creator or thunk ( including one returning a promise ) into a flux standard action
// thunk, return a new thunk // payload, return an action