Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove double rendering #693

Merged
merged 12 commits into from
Jun 11, 2020
12 changes: 5 additions & 7 deletions src/components/chart_resizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ interface ResizerDispatchProps {

type ResizerProps = ResizerStateProps & ResizerDispatchProps;

const DEFAULT_RESIZE_DEBOUNCE = 200;

class Resizer extends React.Component<ResizerProps> {
private initialResizeComplete = false;
private containerRef: RefObject<HTMLDivElement>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated but could be changed when this file needs an update, containerRef could be read only

Expand All @@ -53,10 +55,8 @@ class Resizer extends React.Component<ResizerProps> {
componentDidMount() {
this.onResizeDebounced = debounce(this.onResize, this.props.resizeDebounce);
if (this.containerRef.current) {
const { clientWidth, clientHeight } = this.containerRef.current;
this.props.updateParentDimensions({ width: clientWidth, height: clientHeight, top: 0, left: 0 });
markov00 marked this conversation as resolved.
Show resolved Hide resolved
this.ro.observe(this.containerRef.current as Element);
}
this.ro.observe(this.containerRef.current as Element);
}

componentWillUnmount() {
Expand Down Expand Up @@ -102,11 +102,9 @@ const mapDispatchToProps = (dispatch: Dispatch): ResizerDispatchProps =>
);

const mapStateToProps = (state: GlobalChartState): ResizerStateProps => {
const settings = getSettingsSpecSelector(state);
const resizeDebounce =
settings.resizeDebounce === undefined || settings.resizeDebounce === null ? 200 : settings.resizeDebounce;
const { resizeDebounce } = getSettingsSpecSelector(state);
return {
resizeDebounce,
resizeDebounce: resizeDebounce == null || Number.isNaN(resizeDebounce) ? DEFAULT_RESIZE_DEBOUNCE : resizeDebounce,
markov00 marked this conversation as resolved.
Show resolved Hide resolved
};
};

Expand Down