UNPKG

3.52 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4Object.defineProperty(exports, "__esModule", {
5 value: true
6});
7exports.default = void 0;
8var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
11var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
12var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
13var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14var _react = _interopRequireDefault(require("react"));
15var _reactDom = _interopRequireDefault(require("react-dom"));
16/**
17 * @deprecated Since we do not need support React15 any more.
18 * Will remove in next major version.
19 */
20var ContainerRender = exports.default = /*#__PURE__*/function (_React$Component) {
21 (0, _inherits2.default)(ContainerRender, _React$Component);
22 var _super = (0, _createSuper2.default)(ContainerRender);
23 function ContainerRender() {
24 var _this;
25 (0, _classCallCheck2.default)(this, ContainerRender);
26 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
27 args[_key] = arguments[_key];
28 }
29 _this = _super.call.apply(_super, [this].concat(args));
30 (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "removeContainer", function () {
31 if (_this.container) {
32 _reactDom.default.unmountComponentAtNode(_this.container);
33 _this.container.parentNode.removeChild(_this.container);
34 _this.container = null;
35 }
36 });
37 (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "renderComponent", function (props, ready) {
38 var _this$props = _this.props,
39 visible = _this$props.visible,
40 getComponent = _this$props.getComponent,
41 forceRender = _this$props.forceRender,
42 getContainer = _this$props.getContainer,
43 parent = _this$props.parent;
44 if (visible || parent._component || forceRender) {
45 if (!_this.container) {
46 _this.container = getContainer();
47 }
48 _reactDom.default.unstable_renderSubtreeIntoContainer(parent, getComponent(props), _this.container, function callback() {
49 if (ready) {
50 ready.call(this);
51 }
52 });
53 }
54 });
55 return _this;
56 }
57 (0, _createClass2.default)(ContainerRender, [{
58 key: "componentDidMount",
59 value: function componentDidMount() {
60 if (this.props.autoMount) {
61 this.renderComponent();
62 }
63 }
64 }, {
65 key: "componentDidUpdate",
66 value: function componentDidUpdate() {
67 if (this.props.autoMount) {
68 this.renderComponent();
69 }
70 }
71 }, {
72 key: "componentWillUnmount",
73 value: function componentWillUnmount() {
74 if (this.props.autoDestroy) {
75 this.removeContainer();
76 }
77 }
78 }, {
79 key: "render",
80 value: function render() {
81 return this.props.children({
82 renderComponent: this.renderComponent,
83 removeContainer: this.removeContainer
84 });
85 }
86 }]);
87 return ContainerRender;
88}(_react.default.Component);
89(0, _defineProperty2.default)(ContainerRender, "defaultProps", {
90 autoMount: true,
91 autoDestroy: true,
92 forceRender: false
93});
\No newline at end of file