text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.default = void 0;
  
  require("core-js/modules/es6.object.define-property");
  
  var _global = require("global");
  
  var _coreEvents = _interopRequireDefault(require("@storybook/core-events"));
  
  var _actions = require("./actions");
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  
  var ConfigApi =
  /*#__PURE__*/
  function () {
    function ConfigApi(_ref) {
      var _this = this;
  
      var channel = _ref.channel,
          storyStore = _ref.storyStore,
          reduxStore = _ref.reduxStore,
          clearDecorators = _ref.clearDecorators;
  
      _classCallCheck(this, ConfigApi);
  
      _defineProperty(this, "configure", function (loaders, module) {
        var render = function render() {
          try {
            _this._renderMain(loaders);
          } catch (error) {
            if (module.hot && module.hot.status() === 'apply') {
              // We got this issue, after webpack fixed it and applying it.
              // Therefore error message is displayed forever even it's being fixed.
              // So, we'll detect it reload the page.
              _global.location.reload();
            } else {
              // If we are accessing the site, but the error is not fixed yet.
              // There we can render the error.
              _this._renderError(error); // Clear out the store as chances as only some of the stories will have
              // made it in before the error was thrown
  
  
              _this._storyStore.clean();
            }
          }
        };
  
        if (module.hot) {
          module.hot.accept(function () {
            setTimeout(render);
          });
          module.hot.dispose(function () {
            _this._clearDecorators();
          });
        }
  
        if (_this._channel) {
          render();
        } else {
          loaders();
        }
      });
  
      // channel can be null when running in node
      // always check whether channel is available
      this._channel = channel;
      this._storyStore = storyStore;
      this._reduxStore = reduxStore;
      this._clearDecorators = clearDecorators;
    }
  
    _createClass(ConfigApi, [{
      key: "_renderMain",
      value: function _renderMain(loaders) {
        if (loaders) loaders();
  
        var stories = this._storyStore.dumpStoryBook(); // send to the parent frame.
  
  
        this._channel.emit(_coreEvents.default.SET_STORIES, {
          stories: stories
        }); // clear the error if exists.
  
  
        this._reduxStore.dispatch((0, _actions.clearError)());
  
        this._reduxStore.dispatch((0, _actions.setInitialStory)(stories));
      }
    }, {
      key: "_renderError",
      value: function _renderError(e) {
        var stack = e.stack,
            message = e.message;
        var error = {
          stack: stack,
          message: message
        };
  
        this._reduxStore.dispatch((0, _actions.setError)(error));
      }
    }]);
  
    return ConfigApi;
  }();
  
  exports.default = ConfigApi;