1 | import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
2 | import _createClass from "@babel/runtime/helpers/createClass";
|
3 | import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
4 | import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
5 | import _get from "@babel/runtime/helpers/get";
|
6 | import _inherits from "@babel/runtime/helpers/inherits";
|
7 | import React from 'react';
|
8 |
|
9 | function create(name) {
|
10 | var Base = React[name];
|
11 | return (
|
12 |
|
13 | function (_Base) {
|
14 | _inherits(_class, _Base);
|
15 |
|
16 | function _class() {
|
17 | _classCallCheck(this, _class);
|
18 |
|
19 | return _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments));
|
20 | }
|
21 |
|
22 | _createClass(_class, [{
|
23 | key: "componentDidMount",
|
24 | value: function componentDidMount() {
|
25 | this.$isMounted = true;
|
26 | }
|
27 | }, {
|
28 | key: "componentWillUnmount",
|
29 | value: function componentWillUnmount() {
|
30 | this.$isMounted = false;
|
31 | }
|
32 | }, {
|
33 | key: "setState",
|
34 | value: function setState() {
|
35 | var _get2;
|
36 |
|
37 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
38 | args[_key] = arguments[_key];
|
39 | }
|
40 |
|
41 | if (this.$isMounted !== false) (_get2 = _get(_getPrototypeOf(_class.prototype), "setState", this)).call.apply(_get2, [this].concat(args));
|
42 | }
|
43 | }, {
|
44 | key: "forceUpdate",
|
45 | value: function forceUpdate() {
|
46 | if (this.$isMounted === true) _get(_getPrototypeOf(_class.prototype), "forceUpdate", this).call(this);
|
47 |
|
48 | if (this.$isMounted === undefined) {
|
49 | if (this.forceUpdateTimer) clearTimeout(this.forceUpdateTimer);
|
50 | this.forceUpdateTimer = setTimeout(this.forceUpdate.bind(this));
|
51 | }
|
52 | }
|
53 | }]);
|
54 |
|
55 | return _class;
|
56 | }(Base)
|
57 | );
|
58 | }
|
59 |
|
60 | export var Component = create('Component');
|
61 | export var PureComponent = create('PureComponent'); |
\ | No newline at end of file |