UNPKG

@rcsb/rcsb-saguaro-app

Version:
54 lines (53 loc) 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractChartComponent = void 0; const tslib_1 = require("tslib"); const rxjs_1 = require("rxjs"); const react_1 = tslib_1.__importDefault(require("react")); const SearchQueryContextManager_1 = require("../RcsbGroupWeb/RcsbGroupView/RcsbGroupSeacrhQuery/SearchQueryContextManager"); class AbstractChartComponent extends react_1.default.Component { constructor() { super(...arguments); this.state = { data: this.props.data, chartConfig: this.props.chartConfig }; } componentDidMount() { this.subscribe(); } componentWillUnmount() { this.unsubscribe(); } unsubscribe() { var _a, _b; (_b = (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe) === null || _b === void 0 ? void 0 : _b.call(_a); } subscribe() { this.subscription = SearchQueryContextManager_1.SearchQueryContextManager.dataSubscription((o) => { this.updateChartMap(o); }); } updateChartMap(sqData) { if (!sqData.chartMap) return; if (this.props.attributeName === sqData.attributeName) { this.asyncUpdate(sqData); } else { this.asyncUpdate(sqData, 10); } } asyncUpdate(sqData, x) { var _a; (_a = this.asyncSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe(); this.asyncSubscription = rxjs_1.asyncScheduler.schedule(() => { const data = sqData.chartMap.get(this.props.attributeName); if (data) this.setState({ data }); }, x); } } exports.AbstractChartComponent = AbstractChartComponent;