Commit 773ae92e authored by ι™ˆεΈ…'s avatar ι™ˆεΈ…

rm redundant window.addEventListener

parent 602814cc
import React, { Component } from 'react';
import { Chart, Axis, Tooltip, Geom } from 'bizcharts';
import Debounce from 'lodash-decorators/debounce';
import Bind from 'lodash-decorators/bind';
import ResizeObserver from 'resize-observer-polyfill';
import styles from '../index.less';
class Bar extends Component {
......@@ -11,14 +8,6 @@ class Bar extends Component {
autoHideXLabels: false,
};
componentDidMount() {
window.addEventListener('resize', this.resize, { passive: true });
}
componentWillUnmount() {
window.removeEventListener('resize', this.resize);
}
handleRoot = n => {
this.root = n;
};
......@@ -27,50 +16,6 @@ class Bar extends Component {
this.node = n;
};
resizeObserver() {
const ro = new ResizeObserver(entries => {
const { width, height } = entries[0].contentRect;
this.setState(preState => {
if (preState.width !== width || preState.height !== height) {
return {
height,
};
}
return null;
});
});
if (this.root) {
ro.observe(this.root);
}
}
@Bind()
@Debounce(400)
resize() {
if (!this.node) {
return;
}
const canvasWidth = this.node.parentNode.clientWidth;
const { data = [], autoLabel = true } = this.props;
if (!autoLabel) {
return;
}
const minWidth = data.length * 30;
const { autoHideXLabels } = this.state;
if (canvasWidth <= minWidth) {
if (!autoHideXLabels) {
this.setState({
autoHideXLabels: true,
});
}
} else if (autoHideXLabels) {
this.setState({
autoHideXLabels: false,
});
}
}
render() {
const {
height: propsHeight,
......
......@@ -19,11 +19,8 @@ class TagCloud extends Component {
};
componentDidMount() {
requestAnimationFrame(() => {
this.initTagCloud();
this.renderChart();
});
window.addEventListener('resize', this.resize, { passive: true });
this.initTagCloud();
this.renderChart();
}
componentDidUpdate(preProps) {
......@@ -35,16 +32,8 @@ class TagCloud extends Component {
componentWillUnmount() {
this.isUnmount = true;
window.cancelAnimationFrame(this.requestRef);
window.removeEventListener('resize', this.resize);
}
resize = () => {
this.requestRef = requestAnimationFrame(() => {
this.renderChart();
});
};
saveRootRef = node => {
this.root = node;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment