modules/containers/decorator.js
function wrapWithDispatch(asyncItems) {
  return asyncItems.map((item) => {
    const { key } = item;
    if (!key) return item;

    return {
      ...item,
      promise: (options) => {
        const { store: { dispatch } } = options;
        const next = item.promise(options);

        // NOTE: possibly refactor this with a breaking change in mind for future versions
        // we can return result of processed promise/thunk if need be
        if (isPromise(next)) {
          dispatch(load(key));
          // add action dispatchers
          next
            .then(data => dispatch(loadSuccess(key, data)))
            .catch(err => dispatch(loadFail(key, err)));
        } else if (next) {
          dispatch(loadSuccess(key, next));
        }

        return next;
      },
    };
  });
}
function wrapWithDispatch(asyncItems) {
  return asyncItems.map((item) => {
    const { key } = item;
    if (!key) return item;

    return {
      ...item,
      promise: (options) => {
        const { store: { dispatch } } = options;
        const next = item.promise(options);

        // NOTE: possibly refactor this with a breaking change in mind for future versions
        // we can return result of processed promise/thunk if need be
        if (isPromise(next)) {
          dispatch(load(key));
          // add action dispatchers
          next
            .then(data => dispatch(loadSuccess(key, data)))
            .catch(err => dispatch(loadFail(key, err)));
        } else if (next) {
          dispatch(loadSuccess(key, next));
        }

        return next;
      },
    };
  });
}
function wrapWithDispatch ( asyncItems ) { return asyncItems . map ( ( item ) => { const { key } = item ; if ( ! key ) return item ; return { ... item , promise : ( options ) => { const { store : { dispatch } } = options ; const next = item . promise ( options ) ; // NOTE: possibly refactor this with a breaking change in mind for future versions // we can return result of processed promise/thunk if need be if ( isPromise ( next ) ) { dispatch ( load ( key ) ) ; // add action dispatchers next . then ( data => dispatch ( loadSuccess ( key , data ) ) ) . catch ( err => dispatch ( loadFail ( key , err ) ) ) ; } else if ( next ) { dispatch ( loadSuccess ( key , next ) ) ; } return next ; } , } ; } ) ; }
Wraps react components with data loaders
@param  {Array} asyncItems
@return {WrappedComponent}
Wraps react components with data loaders