UNPKG

5.41 kBJavaScriptView Raw
1function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
2
3function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
5function _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); } }
6
7function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
8
9function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
10
11function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
12
13function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
14
15function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
16
17function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
18
19function _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; } }
20
21function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
22
23import React from 'react';
24import ReactDOM from 'react-dom';
25/**
26 * @deprecated Since we do not need support React15 any more.
27 * Will remove in next major version.
28 */
29
30var ContainerRender = /*#__PURE__*/function (_React$Component) {
31 _inherits(ContainerRender, _React$Component);
32
33 var _super = _createSuper(ContainerRender);
34
35 function ContainerRender() {
36 var _this;
37
38 _classCallCheck(this, ContainerRender);
39
40 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
41 args[_key] = arguments[_key];
42 }
43
44 _this = _super.call.apply(_super, [this].concat(args));
45
46 _this.removeContainer = function () {
47 if (_this.container) {
48 ReactDOM.unmountComponentAtNode(_this.container);
49
50 _this.container.parentNode.removeChild(_this.container);
51
52 _this.container = null;
53 }
54 };
55
56 _this.renderComponent = function (props, ready) {
57 var _this$props = _this.props,
58 visible = _this$props.visible,
59 getComponent = _this$props.getComponent,
60 forceRender = _this$props.forceRender,
61 getContainer = _this$props.getContainer,
62 parent = _this$props.parent;
63
64 if (visible || parent._component || forceRender) {
65 if (!_this.container) {
66 _this.container = getContainer();
67 }
68
69 ReactDOM.unstable_renderSubtreeIntoContainer(parent, getComponent(props), _this.container, function callback() {
70 if (ready) {
71 ready.call(this);
72 }
73 });
74 }
75 };
76
77 return _this;
78 }
79
80 _createClass(ContainerRender, [{
81 key: "componentDidMount",
82 value: function componentDidMount() {
83 if (this.props.autoMount) {
84 this.renderComponent();
85 }
86 }
87 }, {
88 key: "componentDidUpdate",
89 value: function componentDidUpdate() {
90 if (this.props.autoMount) {
91 this.renderComponent();
92 }
93 }
94 }, {
95 key: "componentWillUnmount",
96 value: function componentWillUnmount() {
97 if (this.props.autoDestroy) {
98 this.removeContainer();
99 }
100 }
101 }, {
102 key: "render",
103 value: function render() {
104 return this.props.children({
105 renderComponent: this.renderComponent,
106 removeContainer: this.removeContainer
107 });
108 }
109 }]);
110
111 return ContainerRender;
112}(React.Component);
113
114ContainerRender.defaultProps = {
115 autoMount: true,
116 autoDestroy: true,
117 forceRender: false
118};
119export { ContainerRender as default };
\No newline at end of file