"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

var _react = _interopRequireWildcard(require("react"));

var _spin = _interopRequireDefault(require("../spin"));

var _exception = _interopRequireDefault(require("./exception"));

var asyncComponent = function asyncComponent(importComponent) {
  var AsyncComponent = /*#__PURE__*/function (_Component) {
    (0, _inherits2["default"])(AsyncComponent, _Component);

    var _super = (0, _createSuper2["default"])(AsyncComponent);

    function AsyncComponent() {
      var _this;

      (0, _classCallCheck2["default"])(this, AsyncComponent);
      _this = _super.apply(this, arguments);
      _this.state = {};
      return _this;
    }

    (0, _createClass2["default"])(AsyncComponent, [{
      key: "componentDidMount",
      value: function componentDidMount() {
        var _this2 = this;

        importComponent().then(function (_ref) {
          var component = _ref["default"];

          _this2.setState({
            component: component
          });
        }, _exception["default"]);
      }
    }, {
      key: "render",
      value: function render() {
        var Cmp = this.state.component;
        return Cmp ? /*#__PURE__*/_react["default"].createElement(Cmp, (0, _extends2["default"])({}, this.props)) : /*#__PURE__*/_react["default"].createElement(_spin["default"], null);
      }
    }]);
    return AsyncComponent;
  }(_react.Component);

  return AsyncComponent;
};

var _default = asyncComponent;
exports["default"] = _default;
//# sourceMappingURL=AsyncComponent.js.map
