function withCachedData(getExistingStatePath, getRequestStatePath) {
  // thunk decorator:
  return thunkCreator =>
    // thunk creator:
    (...args) =>
      // thunk:
      (dispatch, getState) => {
        const options = args[args.length - 1] || {};
        const { reload, properties } = options;

        const existingStatePath = getExistingStatePath(...args);
        const requestStatePath = ["requests", ...getRequestStatePath(...args)];
        const existingData = getIn(getState(), existingStatePath);
        const { loading, loaded } = getIn(getState(), requestStatePath) || {};

        const hasRequestedProperties =
          properties &&
          existingData &&
          _.all(properties, p => existingData[p] !== undefined);

        // return existing data if
        if (
          // we don't want to reload
          !reload &&
          // and we have a an non-error request state or have a list of properties that all exist on the object
          (loading || loaded || hasRequestedProperties)
        ) {
          // TODO: if requestState is LOADING can we wait for the other reques
          // to complete and return that result instead?
          return existingData;
        } else {
          return thunkCreator(...args)(dispatch, getState);
        }
      };
}
// NOTE: this should be used together with withRequestState, probably via withCachedDataAndRequestState
this should be used together with withRequestState, probably via withCachedDataAndRequestState
this should be used together with withRequestState probably via withCachedDataAndRequestState
function withCachedData(getExistingStatePath, getRequestStatePath) {
  return thunkCreator =>
    (...args) =>
      (dispatch, getState) => {
        const options = args[args.length - 1] || {};
        const { reload, properties } = options;
        const existingStatePath = getExistingStatePath(...args);
        const requestStatePath = ["requests", ...getRequestStatePath(...args)];
        const existingData = getIn(getState(), existingStatePath);
        const { loading, loaded } = getIn(getState(), requestStatePath) || {};
        const hasRequestedProperties =
          properties &&
          existingData &&
          _.all(properties, p => existingData[p] !== undefined);
        if (
          !reload &&
          (loading || loaded || hasRequestedProperties)
        ) {
          return existingData;
        } else {
          return thunkCreator(...args)(dispatch, getState);
        }
      };
}
function withCachedData ( getExistingStatePath , getRequestStatePath ) { return thunkCreator => ( ... args ) => ( dispatch , getState ) => { const options = args [ args . length - 1 ] || { } ; const { reload , properties } = options ; const existingStatePath = getExistingStatePath ( ... args ) ; const requestStatePath = [ "requests" , ... getRequestStatePath ( ... args ) ] ; const existingData = getIn ( getState ( ) , existingStatePath ) ; const { loading , loaded } = getIn ( getState ( ) , requestStatePath ) || { } ; const hasRequestedProperties = properties && existingData && _ . all ( properties , p => existingData [ p ] !== undefined ) ; if ( ! reload && ( loading || loaded || hasRequestedProperties ) ) { return existingData ; } else { return thunkCreator ( ... args ) ( dispatch , getState ) ; } } ; }
NOTE: this should be used together with withRequestState, probably via withCachedDataAndRequestState
NOTE : this should be used together with withRequestState probably via withCachedDataAndRequestState
// thunk decorator: // thunk creator: // thunk: // return existing data if // we don't want to reload // and we have a an non-error request state or have a list of properties that all exist on the object // TODO: if requestState is LOADING can we wait for the other reques // to complete and return that result instead?