From 773ae92e4f406474c00162e28b0dcebe56262973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Fri, 17 May 2019 23:36:00 +0800 Subject: [PATCH] rm redundant window.addEventListener --- src/components/Charts/Bar/index.js | 55 ------------------------- src/components/Charts/TagCloud/index.js | 15 +------ 2 files changed, 2 insertions(+), 68 deletions(-) diff --git a/src/components/Charts/Bar/index.js b/src/components/Charts/Bar/index.js index f898a122..4b8a6a59 100644 --- a/src/components/Charts/Bar/index.js +++ b/src/components/Charts/Bar/index.js @@ -1,8 +1,5 @@ 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, diff --git a/src/components/Charts/TagCloud/index.js b/src/components/Charts/TagCloud/index.js index 4898d821..2f60124a 100644 --- a/src/components/Charts/TagCloud/index.js +++ b/src/components/Charts/TagCloud/index.js @@ -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; }; -- GitLab