1 | import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
2 | import _createClass from "@babel/runtime/helpers/esm/createClass";
|
3 | import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
4 | import _inherits from "@babel/runtime/helpers/esm/inherits";
|
5 | import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
6 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
7 | import React from 'react';
|
8 | import ReactDOM from 'react-dom';
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | var ContainerRender = function (_React$Component) {
|
15 | _inherits(ContainerRender, _React$Component);
|
16 | var _super = _createSuper(ContainerRender);
|
17 | function ContainerRender() {
|
18 | var _this;
|
19 | _classCallCheck(this, ContainerRender);
|
20 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
21 | args[_key] = arguments[_key];
|
22 | }
|
23 | _this = _super.call.apply(_super, [this].concat(args));
|
24 | _defineProperty(_assertThisInitialized(_this), "removeContainer", function () {
|
25 | if (_this.container) {
|
26 | ReactDOM.unmountComponentAtNode(_this.container);
|
27 | _this.container.parentNode.removeChild(_this.container);
|
28 | _this.container = null;
|
29 | }
|
30 | });
|
31 | _defineProperty(_assertThisInitialized(_this), "renderComponent", function (props, ready) {
|
32 | var _this$props = _this.props,
|
33 | visible = _this$props.visible,
|
34 | getComponent = _this$props.getComponent,
|
35 | forceRender = _this$props.forceRender,
|
36 | getContainer = _this$props.getContainer,
|
37 | parent = _this$props.parent;
|
38 | if (visible || parent._component || forceRender) {
|
39 | if (!_this.container) {
|
40 | _this.container = getContainer();
|
41 | }
|
42 | ReactDOM.unstable_renderSubtreeIntoContainer(parent, getComponent(props), _this.container, function callback() {
|
43 | if (ready) {
|
44 | ready.call(this);
|
45 | }
|
46 | });
|
47 | }
|
48 | });
|
49 | return _this;
|
50 | }
|
51 | _createClass(ContainerRender, [{
|
52 | key: "componentDidMount",
|
53 | value: function componentDidMount() {
|
54 | if (this.props.autoMount) {
|
55 | this.renderComponent();
|
56 | }
|
57 | }
|
58 | }, {
|
59 | key: "componentDidUpdate",
|
60 | value: function componentDidUpdate() {
|
61 | if (this.props.autoMount) {
|
62 | this.renderComponent();
|
63 | }
|
64 | }
|
65 | }, {
|
66 | key: "componentWillUnmount",
|
67 | value: function componentWillUnmount() {
|
68 | if (this.props.autoDestroy) {
|
69 | this.removeContainer();
|
70 | }
|
71 | }
|
72 | }, {
|
73 | key: "render",
|
74 | value: function render() {
|
75 | return this.props.children({
|
76 | renderComponent: this.renderComponent,
|
77 | removeContainer: this.removeContainer
|
78 | });
|
79 | }
|
80 | }]);
|
81 | return ContainerRender;
|
82 | }(React.Component);
|
83 | _defineProperty(ContainerRender, "defaultProps", {
|
84 | autoMount: true,
|
85 | autoDestroy: true,
|
86 | forceRender: false
|
87 | });
|
88 | export { ContainerRender as default }; |
\ | No newline at end of file |