Skip to content

Commit f79b20a

Browse files
committed
unbind can not be called
1 parent 42d6896 commit f79b20a

File tree

6 files changed

+56
-39
lines changed

6 files changed

+56
-39
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A very simple echarts(v3.0) wrapper for react.
44

5-
[![Build Status](https://travis-ci.org/hustcc/echarts-for-react.svg?branch=master)](https://travis-ci.org/hustcc/echarts-for-react) [![npm](https://img.shields.io/npm/v/echarts-for-react.svg)](https://www.npmjs.com/package/echarts-for-react) [![npm](https://img.shields.io/npm/dt/echarts-for-react.svg)](https://www.npmjs.com/package/echarts-for-react) [![npm](https://img.shields.io/npm/l/echarts-for-react.svg)](https://www.npmjs.com/package/echarts-for-react) ![echarts supported](https://img.shields.io/badge/echarts-%5E3.0.0-blue.svg) ![react supported](https://img.shields.io/badge/React-%3E%3D0.13.2%20%7C%7C%20%5E0.14.0%20%7C%7C%20%5E15.0.0-blue.svg)
5+
[![Build Status](https://travis-ci.org/hustcc/echarts-for-react.svg?branch=master)](https://travis-ci.org/hustcc/echarts-for-react) [![Coverage Status](https://coveralls.io/repos/github/hustcc/echarts-for-react/badge.svg?branch=master)](https://coveralls.io/github/hustcc/echarts-for-react?branch=master) [![npm](https://img.shields.io/npm/v/echarts-for-react.svg)](https://www.npmjs.com/package/echarts-for-react) [![npm](https://img.shields.io/npm/dt/echarts-for-react.svg)](https://www.npmjs.com/package/echarts-for-react) [![npm](https://img.shields.io/npm/l/echarts-for-react.svg)](https://www.npmjs.com/package/echarts-for-react) ![echarts supported](https://img.shields.io/badge/echarts-%5E3.0.0-blue.svg) ![react supported](https://img.shields.io/badge/React-%3E%3D0.13.2%20%7C%7C%20%5E0.14%20%7C%7C%20%5E15.0.0%20%7C%7C%20%3E%3D16.0.0-blue.svg)
66

77
# 1. install
88

demo/dist/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ var EchartsReactCore = function (_Component) {
4545
return _this.echartsInstance.getInstanceByDom(_this.echartsElement) || _this.echartsInstance.init(_this.echartsElement, _this.props.theme);
4646
};
4747

48+
_this.dispose = function () {
49+
if (_this.echartsElement) {
50+
// if elementResizeEvent.unbind exist, just do it.
51+
try {
52+
_elementResizeEvent2['default'].unbind(_this.echartsElement);
53+
} catch (_) {}
54+
_this.echartsInstance.dispose(_this.echartsElement);
55+
}
56+
};
57+
4858
_this.rerender = function () {
4959
var _this$props = _this.props,
5060
onEvents = _this$props.onEvents,
@@ -117,7 +127,7 @@ var EchartsReactCore = function (_Component) {
117127

118128
// 切换 theme 的时候,需要 dispost 之后才新建
119129
if (this.props.theme !== prevProps.theme) {
120-
this.echartsInstance.dispose(this.echartsElement);
130+
this.dispose();
121131

122132
this.rerender(); // 重建
123133
return;
@@ -135,18 +145,15 @@ var EchartsReactCore = function (_Component) {
135145
}, {
136146
key: 'componentWillUnmount',
137147
value: function componentWillUnmount() {
138-
if (this.echartsElement) {
139-
// if elementResizeEvent.unbind exist, just do it.
140-
if (typeof _elementResizeEvent2['default'].unbind === 'function') {
141-
_elementResizeEvent2['default'].unbind(this.echartsElement);
142-
}
143-
this.echartsInstance.dispose(this.echartsElement);
144-
}
148+
this.dispose();
145149
}
146150

147151
// return the echart object
148152

149153

154+
// dispose echarts and element-resize-event
155+
156+
150157
// bind the events
151158

152159

lib/index.d.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1-
import React, { Component } from 'react';
1+
/// <reference types="react" />
2+
3+
import * as React from 'react';
4+
5+
type Func = (...args: any[]) => any;
6+
7+
interface EventMap {
8+
[key: string]: Func,
9+
}
10+
11+
interface ObjectMap {
12+
[key: string]: any,
13+
}
214

315
// Index
416
export interface ReactEchartsPropsTypes {
5-
option: object;
17+
option: ObjectMap;
618
notMerge?: boolean;
719
lazyUpdate?: boolean;
8-
style?: object;
20+
style?: ObjectMap;
921
className?: string;
10-
theme?: string;
11-
onChartReady?: () => void;
22+
theme?: string | null;
23+
onChartReady?: Func;
1224
showLoading?: boolean;
13-
loadingOption?: object;
14-
onEvents?: object;
25+
loadingOption?: ObjectMap;
26+
onEvents?: EventMap;
1527
echarts?: object;
1628
}
1729

18-
export class ReactEcharts extends Component<ReactEchartsPropsTypes, any> {
19-
getEchartsInstance: () => any;
20-
}
30+
export default class ReactEcharts extends React.Component<ReactEchartsPropsTypes, any>{}

package.json

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "echarts-for-react",
3-
"version": "2.0.3",
3+
"version": "2.0.4",
44
"description": "baidu Echarts(v3.x) components for react",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",
@@ -81,24 +81,20 @@
8181
"react-test-renderer": "^15.6.2",
8282
"rimraf": "^2.6.2",
8383
"style-loader": "^0.19.1",
84-
"ts-jest": "^21.2.3",
85-
"typescript": "^2.6.2",
8684
"webpack": "^3.10.0",
8785
"webpack-dev-server": "^2.9.7"
8886
},
8987
"dependencies": {
90-
"element-resize-event": "2.0.7"
88+
"element-resize-event": "2.0.8"
9189
},
9290
"peerDependencies": {
93-
"react": ">=0.13.2 || ^0.14 || ^15.0.0 || >=16.0.0-alpha.1 <17.0.0",
91+
"react": ">=0.13.2 || ^0.14 || ^15.0.0 || >=16.0.0",
9492
"prop-types": "^15.5.7",
9593
"echarts": "^3.0.0"
9694
},
9795
"jest": {
98-
"testRegex": "(/__tests__/.*\\.spec)\\.(ts|tsx|js|jsx)$",
96+
"testRegex": "(/__tests__/.*\\.spec)\\.(js|jsx)$",
9997
"moduleFileExtensions": [
100-
"ts",
101-
"tsx",
10298
"js",
10399
"jsx",
104100
"json"
@@ -108,13 +104,12 @@
108104
"jest-canvas-mock"
109105
],
110106
"transform": {
111-
"^.+\\.js[x]?$": "babel-jest",
112-
"^.+\\.ts[x]?$": "ts-jest"
107+
"^.+\\.js[x]?$": "babel-jest"
113108
},
114109
"moduleNameMapper": {},
115110
"collectCoverage": true,
116111
"collectCoverageFrom": [
117-
"src/*.{js,jsx,ts,tsx}",
112+
"src/*.{js,jsx}",
118113
"!**/node_modules/**",
119114
"!**/vendor/**"
120115
]

src/core.jsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default class EchartsReactCore extends Component {
2323

2424
// 切换 theme 的时候,需要 dispost 之后才新建
2525
if (this.props.theme !== prevProps.theme) {
26-
this.echartsInstance.dispose(this.echartsElement);
26+
this.dispose();
2727

2828
this.rerender(); // 重建
2929
return;
@@ -38,19 +38,24 @@ export default class EchartsReactCore extends Component {
3838

3939
// remove
4040
componentWillUnmount() {
41-
if (this.echartsElement) {
42-
// if elementResizeEvent.unbind exist, just do it.
43-
if (typeof elementResizeEvent.unbind === 'function') {
44-
elementResizeEvent.unbind(this.echartsElement);
45-
}
46-
this.echartsInstance.dispose(this.echartsElement);
47-
}
41+
this.dispose();
4842
}
4943

5044
// return the echart object
5145
getEchartsInstance = () => this.echartsInstance.getInstanceByDom(this.echartsElement) ||
5246
this.echartsInstance.init(this.echartsElement, this.props.theme);
5347

48+
// dispose echarts and element-resize-event
49+
dispose = () => {
50+
if (this.echartsElement) {
51+
// if elementResizeEvent.unbind exist, just do it.
52+
try {
53+
elementResizeEvent.unbind(this.echartsElement);
54+
} catch (_) {}
55+
this.echartsInstance.dispose(this.echartsElement);
56+
}
57+
};
58+
5459
rerender = () => {
5560
const { onEvents, onChartReady } = this.props;
5661

0 commit comments

Comments
 (0)