1 | ;
|
2 | /*
|
3 | * Copyright 2015 Palantir Technologies, Inc. All rights reserved.
|
4 | *
|
5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
6 | * you may not use this file except in compliance with the License.
|
7 | * You may obtain a copy of the License at
|
8 | *
|
9 | * http://www.apache.org/licenses/LICENSE-2.0
|
10 | *
|
11 | * Unless required by applicable law or agreed to in writing, software
|
12 | * distributed under the License is distributed on an "AS IS" BASIS,
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 | * See the License for the specific language governing permissions and
|
15 | * limitations under the License.
|
16 | */
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.AbstractPureComponent = void 0;
|
19 | var tslib_1 = require("tslib");
|
20 | var React = tslib_1.__importStar(require("react"));
|
21 | var utils_1 = require("./utils");
|
22 | /**
|
23 | * An abstract component that Blueprint components can extend
|
24 | * in order to add some common functionality like runtime props validation.
|
25 | *
|
26 | * @deprecated componentWillReceiveProps is deprecated in React 16.9; use AbstractPureComponent2 instead
|
27 | */
|
28 | // eslint-disable-next-line @typescript-eslint/ban-types
|
29 | var AbstractPureComponent = /** @class */ (function (_super) {
|
30 | tslib_1.__extends(AbstractPureComponent, _super);
|
31 | function AbstractPureComponent(props, context) {
|
32 | var _this = _super.call(this, props, context) || this;
|
33 | // Not bothering to remove entries when their timeouts finish because clearing invalid ID is a no-op
|
34 | _this.timeoutIds = [];
|
35 | /**
|
36 | * Clear all known timeouts.
|
37 | */
|
38 | _this.clearTimeouts = function () {
|
39 | if (_this.timeoutIds.length > 0) {
|
40 | for (var _i = 0, _a = _this.timeoutIds; _i < _a.length; _i++) {
|
41 | var timeoutId = _a[_i];
|
42 | window.clearTimeout(timeoutId);
|
43 | }
|
44 | _this.timeoutIds = [];
|
45 | }
|
46 | };
|
47 | if (!utils_1.isNodeEnv("production")) {
|
48 | _this.validateProps(_this.props);
|
49 | }
|
50 | return _this;
|
51 | }
|
52 | AbstractPureComponent.prototype.componentWillReceiveProps = function (nextProps) {
|
53 | if (!utils_1.isNodeEnv("production")) {
|
54 | this.validateProps(nextProps);
|
55 | }
|
56 | };
|
57 | AbstractPureComponent.prototype.componentWillUnmount = function () {
|
58 | this.clearTimeouts();
|
59 | };
|
60 | /**
|
61 | * Set a timeout and remember its ID.
|
62 | * All stored timeouts will be cleared when component unmounts.
|
63 | *
|
64 | * @returns a "cancel" function that will clear timeout when invoked.
|
65 | */
|
66 | AbstractPureComponent.prototype.setTimeout = function (callback, timeout) {
|
67 | var handle = window.setTimeout(callback, timeout);
|
68 | this.timeoutIds.push(handle);
|
69 | return function () { return window.clearTimeout(handle); };
|
70 | };
|
71 | /**
|
72 | * Ensures that the props specified for a component are valid.
|
73 | * Implementations should check that props are valid and usually throw an Error if they are not.
|
74 | * Implementations should not duplicate checks that the type system already guarantees.
|
75 | *
|
76 | * This method should be used instead of React's
|
77 | * [propTypes](https://facebook.github.io/react/docs/reusable-components.html#prop-validation) feature.
|
78 | * Like propTypes, these runtime checks run only in development mode.
|
79 | */
|
80 | AbstractPureComponent.prototype.validateProps = function (_props) {
|
81 | // implement in subclass
|
82 | };
|
83 | return AbstractPureComponent;
|
84 | }(React.PureComponent));
|
85 | exports.AbstractPureComponent = AbstractPureComponent;
|
86 | //# sourceMappingURL=abstractPureComponent.js.map |
\ | No newline at end of file |