Skip to content

Commit

Permalink
fix duplicate bind event, fixed #155
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc committed Mar 2, 2018
1 parent caa31b4 commit 44c1e27
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion demo/dist/bundle.js

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion demo/src/charts/Events.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import React, { PureComponent } from 'react';
import ReactEcharts from '../../../src/index';

export default class Events extends PureComponent {
constructor(props) {
super(props);
this.state = {
cnt: 0,
};
}
getOption = () => ({
title : {
text: '某站点用户访问来源',
Expand Down Expand Up @@ -44,6 +50,9 @@ export default class Events extends PureComponent {
onChartClick = (param, echarts) => {
console.log(param, echarts);
alert('chart click');
this.setState({
cnt: this.state.cnt + 1,
})
};

onChartLegendselectchanged = (param, echart) => {
Expand Down Expand Up @@ -73,7 +82,7 @@ export default class Events extends PureComponent {
return (
<div className='examples'>
<div className='parent'>
<label> Chart With event <strong> onEvents </strong>: (Click the chart, and watch the console)</label>
<label> Chart With event <strong> onEvents </strong>{this.state.cnt}: (Click the chart, and watch the console)</label>
<ReactEcharts
option={this.getOption()}
style={{height: 300}}
Expand Down
2 changes: 1 addition & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var EchartsReactCore = function (_Component) {
try {
_elementResizeEvent2['default'].unbind(_this.echartsElement);
} catch (_) {}
// dispose echarts instance
_this.echartsLib.dispose(_this.echartsElement);
}
};
Expand Down Expand Up @@ -130,7 +131,6 @@ var EchartsReactCore = function (_Component) {
key: 'componentDidUpdate',
value: function componentDidUpdate(prevProps) {
var echartObj = this.renderEchartDom();
this.bindEvents(echartObj, this.props.onEvents || {});

// 以下属性修改的时候,需要 dispose 之后再新建
// 1. 切换 theme 的时候
Expand Down
2 changes: 1 addition & 1 deletion src/core.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export default class EchartsReactCore extends Component {
// update
componentDidUpdate(prevProps) {
const echartObj = this.renderEchartDom();
this.bindEvents(echartObj, this.props.onEvents || {});

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

0 comments on commit 44c1e27

Please sign in to comment.