@rcsb/rcsb-saguaro-app
Version:
RCSB 1D Saguaro Web App
49 lines • 1.59 kB
JavaScript
import { asyncScheduler } from "rxjs";
import React from "react";
import { SearchQueryContextManager } from "../RcsbGroupWeb/RcsbGroupView/RcsbGroupSeacrhQuery/SearchQueryContextManager";
export class AbstractChartComponent extends React.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.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 = asyncScheduler.schedule(() => {
const data = sqData.chartMap.get(this.props.attributeName);
if (data)
this.setState({
data
});
}, x);
}
}
//# sourceMappingURL=AbsractChartComponent.js.map