Skip to content

Commit 44c1e27

Browse files
committed
fix duplicate bind event, fixed #155
1 parent caa31b4 commit 44c1e27

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

demo/dist/bundle.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/src/charts/Events.jsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import React, { PureComponent } from 'react';
22
import ReactEcharts from '../../../src/index';
33

44
export default class Events extends PureComponent {
5+
constructor(props) {
6+
super(props);
7+
this.state = {
8+
cnt: 0,
9+
};
10+
}
511
getOption = () => ({
612
title : {
713
text: '某站点用户访问来源',
@@ -44,6 +50,9 @@ export default class Events extends PureComponent {
4450
onChartClick = (param, echarts) => {
4551
console.log(param, echarts);
4652
alert('chart click');
53+
this.setState({
54+
cnt: this.state.cnt + 1,
55+
})
4756
};
4857

4958
onChartLegendselectchanged = (param, echart) => {
@@ -73,7 +82,7 @@ export default class Events extends PureComponent {
7382
return (
7483
<div className='examples'>
7584
<div className='parent'>
76-
<label> Chart With event <strong> onEvents </strong>: (Click the chart, and watch the console)</label>
85+
<label> Chart With event <strong> onEvents </strong>{this.state.cnt}: (Click the chart, and watch the console)</label>
7786
<ReactEcharts
7887
option={this.getOption()}
7988
style={{height: 300}}

lib/core.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ var EchartsReactCore = function (_Component) {
5151
try {
5252
_elementResizeEvent2['default'].unbind(_this.echartsElement);
5353
} catch (_) {}
54+
// dispose echarts instance
5455
_this.echartsLib.dispose(_this.echartsElement);
5556
}
5657
};
@@ -130,7 +131,6 @@ var EchartsReactCore = function (_Component) {
130131
key: 'componentDidUpdate',
131132
value: function componentDidUpdate(prevProps) {
132133
var echartObj = this.renderEchartDom();
133-
this.bindEvents(echartObj, this.props.onEvents || {});
134134

135135
// 以下属性修改的时候,需要 dispose 之后再新建
136136
// 1. 切换 theme 的时候

src/core.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export default class EchartsReactCore extends Component {
1919
// update
2020
componentDidUpdate(prevProps) {
2121
const echartObj = this.renderEchartDom();
22-
this.bindEvents(echartObj, this.props.onEvents || {});
2322

2423
// 以下属性修改的时候,需要 dispose 之后再新建
2524
// 1. 切换 theme 的时候
@@ -60,6 +59,7 @@ export default class EchartsReactCore extends Component {
6059
try {
6160
elementResizeEvent.unbind(this.echartsElement);
6261
} catch (_) {}
62+
// dispose echarts instance
6363
this.echartsLib.dispose(this.echartsElement);
6464
}
6565
};

0 commit comments

Comments
 (0)