Skip to content

Commit caa31b4

Browse files
committed
onEvent 为 null 报异常,fixed #154
1 parent cf67699 commit caa31b4

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

__tests__/index.spec.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,15 @@ describe('index.js', () => {
169169
click: () => {},
170170
}
171171
});
172-
173172
component.update(); // force update
174173
expect(preId).not.toBe(component.instance().getEchartsInstance().id);
174+
175+
// to null
176+
component.setProps({
177+
onEvents: null,
178+
});
179+
component.update();
180+
expect(preId).not.toBe(component.instance().getEchartsInstance().id);
175181
});
176182

177183
test('unmount', () => {

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ var EchartsReactCore = function (_Component) {
136136
// 1. 切换 theme 的时候
137137
// 2. 修改 opts 的时候
138138
// 3. 修改 onEvents 的时候,这样可以取消所以之前绑定的事件 issue #151
139-
if (prevProps.theme !== this.props.theme || !isEqual(prevProps.opts, this.props.opts) || !isEqual(Object.keys(prevProps.onEvents).sort(), Object.keys(this.props.onEvents).sort())) {
139+
if (prevProps.theme !== this.props.theme || !isEqual(prevProps.opts, this.props.opts) || !isEqual(Object.keys(prevProps.onEvents || {}).sort(), Object.keys(this.props.onEvents || {}).sort())) {
140140
this.dispose();
141141

142142
this.rerender(); // 重建

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "echarts-for-react",
3-
"version": "2.0.7",
3+
"version": "2.0.8",
44
"description": "baidu Echarts(v3.x & v4.x) components for react.",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/core.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default class EchartsReactCore extends Component {
2828
if (
2929
prevProps.theme !== this.props.theme ||
3030
!isEqual(prevProps.opts, this.props.opts) ||
31-
!isEqual(Object.keys(prevProps.onEvents).sort(), Object.keys(this.props.onEvents).sort())
31+
!isEqual(Object.keys(prevProps.onEvents || {}).sort(), Object.keys(this.props.onEvents || {}).sort())
3232
) {
3333
this.dispose();
3434

0 commit comments

Comments
 (0)