define(['exports', 'react', 'hoist-non-react-statics', 'react-redux', './TopicsListComponent-3ae3045d', 'invariant', 'lodash', './index-d6e61a32'], function (exports, React, hoistNonReactStatics, reactRedux, TopicsListComponent, invariant, lodash, index) { 'use strict';

  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
  var invariant__default = /*#__PURE__*/_interopDefaultLegacy(invariant);

  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { TopicsListComponent._defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  const allowedModes = [index.RESTART_ON_REMOUNT, index.DAEMON, index.ONCE_TILL_UNMOUNT];

  const checkKey = key => invariant__default['default'](lodash.isString(key) && !lodash.isEmpty(key), '(app/utils...) injectSaga: Expected `key` to be a non empty string');

  const checkDescriptor = descriptor => {
    const shape = {
      saga: lodash.isFunction,
      mode: mode => lodash.isString(mode) && allowedModes.includes(mode)
    };
    invariant__default['default'](lodash.conformsTo(descriptor, shape), '(app/utils...) injectSaga: Expected a valid saga descriptor');
  };

  function injectSagaFactory(store, isValid) {
    return function injectSaga(key, descriptor = {}, args) {
      if (!isValid) index.checkStore(store);

      const newDescriptor = _objectSpread(_objectSpread({}, descriptor), {}, {
        mode: descriptor.mode || index.DAEMON
      });

      const {
        saga,
        mode
      } = newDescriptor;
      checkKey(key);
      checkDescriptor(newDescriptor);
      let hasSaga = Reflect.has(store.injectedSagas, key);

      if (process.env.NODE_ENV !== 'production') {
        const oldDescriptor = store.injectedSagas[key]; // enable hot reloading of daemon and once-till-unmount sagas

        if (hasSaga && oldDescriptor.saga !== saga) {
          oldDescriptor.task.cancel();
          hasSaga = false;
        }
      }

      if (!hasSaga || hasSaga && mode !== index.DAEMON && mode !== index.ONCE_TILL_UNMOUNT) {
        /* eslint-disable no-param-reassign */
        store.injectedSagas[key] = _objectSpread(_objectSpread({}, newDescriptor), {}, {
          task: store.runSaga(saga, args)
        });
        /* eslint-enable no-param-reassign */
      }
    };
  }
  function ejectSagaFactory(store, isValid) {
    return function ejectSaga(key) {
      if (!isValid) index.checkStore(store);
      checkKey(key);

      if (Reflect.has(store.injectedSagas, key)) {
        const descriptor = store.injectedSagas[key];

        if (descriptor.mode && descriptor.mode !== index.DAEMON) {
          descriptor.task.cancel(); // Clean up in production; in development we need `descriptor.saga` for hot reloading

          if (process.env.NODE_ENV === 'production') {
            // Need some value to be able to detect `ONCE_TILL_UNMOUNT` sagas in `injectSaga`
            store.injectedSagas[key] = 'done'; // eslint-disable-line no-param-reassign
          }
        }
      }
    };
  }
  function getInjectors(store) {
    index.checkStore(store);
    return {
      injectSaga: injectSagaFactory(store, true),
      ejectSaga: ejectSagaFactory(store, true)
    };
  }

  const useInjectSaga = ({
    key,
    saga,
    mode
  }) => {
    const context = React__default['default'].useContext(reactRedux.ReactReduxContext);
    React__default['default'].useEffect(() => {
      const injectors = getInjectors(context.store);
      injectors.injectSaga(key, {
        saga,
        mode
      });
      return () => {
        injectors.ejectSaga(key);
      };
    }, []);
  };

  /**
   * Parses the JSON returned by a network request
   *
   * @param  {object} response A response from a network request
   *
   * @return {object}          The parsed JSON from the request
   */
  function parseJSON(response) {
    if (response.status === 204 || response.status === 205) {
      return null;
    }

    return response.json();
  }
  /**
   * Checks if a network request came back fine, and throws an error if not
   *
   * @param  {object} response   A response from a network request
   *
   * @return {object|undefined} Returns either the response, or throws an error
   */


  function checkStatus(response) {
    if (response.status >= 200 && response.status < 300) {
      return response;
    }

    const error = new Error(response.statusText);
    error.response = response;
    throw error;
  }
  /**
   * Requests a URL, returning a promise
   *
   * @param  {string} url       The URL we want to request
   * @param  {object} [options] The options we want to pass to "fetch"
   *
   * @return {object}           The response data
   */


  function request(url, options) {
    return fetch(url, options).then(checkStatus).then(parseJSON);
  }

  exports.request = request;
  exports.useInjectSaga = useInjectSaga;

});
//# sourceMappingURL=request-bd26fd61.js.map
