UNPKG

coolant

Version:

The modular build radiator

45 lines (44 loc) 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var react_1 = tslib_1.__importDefault(require("react")); var event_1 = require("../event"); var Connector = /** @class */ (function (_super) { tslib_1.__extends(Connector, _super); function Connector(props) { var _this = _super.call(this, props) || this; // tslint:disable-next-line:readonly-keyword _this.intervalId = null; _this.state = { data: null }; return _this; } Connector.prototype.render = function () { var ComponentToConnect = this.props.component; return this.state.data === null ? react_1.default.createElement(react_1.default.Fragment, null) : react_1.default.createElement(ComponentToConnect, tslib_1.__assign({ data: this.state.data }, this.props.otherComponentProps)); }; Connector.prototype.componentDidMount = function () { var _this = this; this.intervalId = event_1.periodically(function () { return _this.updateState(); }, this.props.updateIntervalSeconds); }; Connector.prototype.componentWillUnmount = function () { if (this.intervalId !== null) { clearInterval(this.intervalId); } }; Connector.prototype.updateState = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { var data; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.props.provider()]; case 1: data = _a.sent(); this.setState({ data: data }); return [2 /*return*/]; } }); }); }; return Connector; }(react_1.default.Component)); exports.Connector = Connector;