choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
148 lines (122 loc) • 4.14 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function _createSuper(Derived) {
function isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
return function () {
var Super = _getPrototypeOf(Derived),
result;
if (isNativeReflectConstruct()) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
import { Component } from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
var ContainerRender =
/*#__PURE__*/
function (_Component) {
_inherits(ContainerRender, _Component);
var _super = _createSuper(ContainerRender);
function ContainerRender() {
var _this;
_classCallCheck(this, ContainerRender);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
_defineProperty(_assertThisInitialized(_this), "removeContainer", function () {
if (_this.container) {
ReactDOM.unmountComponentAtNode(_this.container);
_this.container.parentNode.removeChild(_this.container);
_this.container = null;
}
});
_defineProperty(_assertThisInitialized(_this), "renderComponent", function (props, ready) {
var _this$props = _this.props,
visible = _this$props.visible,
getComponent = _this$props.getComponent,
forceRender = _this$props.forceRender,
getContainer = _this$props.getContainer,
parent = _this$props.parent;
if (visible || parent._component || forceRender) {
if (!_this.container) {
_this.container = getContainer();
}
ReactDOM.unstable_renderSubtreeIntoContainer(parent, getComponent(props), _this.container, function callback() {
if (ready) {
ready.call(this);
}
});
}
});
return _this;
}
_createClass(ContainerRender, [{
key: "componentDidMount",
value: function componentDidMount() {
if (this.props.autoMount) {
this.renderComponent();
}
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate() {
if (this.props.autoMount) {
this.renderComponent();
}
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
if (this.props.autoDestroy) {
this.removeContainer();
}
}
}, {
key: "render",
value: function render() {
return this.props.children({
renderComponent: this.renderComponent,
removeContainer: this.removeContainer
});
}
}]);
return ContainerRender;
}(Component);
_defineProperty(ContainerRender, "propTypes", {
autoMount: PropTypes.bool,
autoDestroy: PropTypes.bool,
visible: PropTypes.bool,
forceRender: PropTypes.bool,
parent: PropTypes.any,
getComponent: PropTypes.func.isRequired,
getContainer: PropTypes.func.isRequired,
children: PropTypes.func.isRequired
});
_defineProperty(ContainerRender, "defaultProps", {
autoMount: true,
autoDestroy: true,
forceRender: false
});
export { ContainerRender as default };
//# sourceMappingURL=ContainerRender.js.map