File tree Expand file tree Collapse file tree 2 files changed +47
-35
lines changed Expand file tree Collapse file tree 2 files changed +47
-35
lines changed Original file line number Diff line number Diff line change @@ -67,19 +67,23 @@ class ECharts extends Component {
67
67
}
68
68
69
69
onMessage = e => {
70
- if ( ! e ) return null ;
70
+ try {
71
+ if ( ! e ) return null ;
71
72
72
- const { onData } = this . props ;
73
+ const { onData } = this . props ;
73
74
74
- const data = JSON . parse ( e . nativeEvent . data ) ;
75
+ const data = JSON . parse ( e . nativeEvent . data ) ;
75
76
76
- if ( data . types === "DATA" ) {
77
- onData ( data . payload ) ;
78
- } else if ( data . types === "CALLBACK" ) {
79
- /* eslint-disable no-case-declarations */
80
- const { uuid } = data ;
81
- /* eslint-enable no-case-declarations */
82
- this . callbacks [ uuid ] ( data . payload ) ;
77
+ if ( data . types === "DATA" ) {
78
+ onData ( data . payload ) ;
79
+ } else if ( data . types === "CALLBACK" ) {
80
+ /* eslint-disable no-case-declarations */
81
+ const { uuid } = data ;
82
+ /* eslint-enable no-case-declarations */
83
+ this . callbacks [ uuid ] ( data . payload ) ;
84
+ }
85
+ } catch ( error ) {
86
+ console . log ( error ) ;
83
87
}
84
88
} ;
85
89
Original file line number Diff line number Diff line change @@ -90,33 +90,41 @@ export const getJavascriptSource = (props) => {
90
90
chart.resize();
91
91
};
92
92
93
- window.document.addEventListener('message', function(e) {
94
- var req = parse(e.data);
95
-
96
- switch(req.types) {
97
- case "SET_OPTION":
98
- chart.setOption(req.payload.option, req.payload.notMerge,req.payload.lazyUpate);
99
- break;
100
- case "CLEAR":
101
- chart.clear();
102
- break;
103
- case "GET_OPTION":
104
- var option = chart.getOption();
105
- var data = {};
93
+ function processMessage (e) {
94
+ var req = parse(e.data);
106
95
107
- if(req.properties !== undefined) {
108
- req.properties.forEach((prop) => data[prop] = option[prop]);
109
- } else {
110
- var data = {
111
- option: option
112
- };
113
- }
96
+ switch(req.types) {
97
+ case "SET_OPTION":
98
+ chart.setOption(req.payload.option, req.payload.notMerge,req.payload.lazyUpate);
99
+ break;
100
+ case "CLEAR":
101
+ chart.clear();
102
+ break;
103
+ case "GET_OPTION":
104
+ var option = chart.getOption();
105
+ var data = {};
106
+
107
+ if(req.properties !== undefined) {
108
+ req.properties.forEach((prop) => data[prop] = option[prop]);
109
+ } else {
110
+ var data = {
111
+ option: option
112
+ };
113
+ }
114
+
115
+ sendCallbackData(req.uuid, data);
116
+ break;
117
+ default:
118
+ break;
119
+ }
120
+ }
114
121
115
- sendCallbackData(req.uuid, data);
116
- break;
117
- default:
118
- break;
119
- }
122
+ window.document.addEventListener('message', function(e) {
123
+ processMessage(e);
124
+ });
125
+
126
+ window.addEventListener('message', function(e) {
127
+ processMessage(e);
120
128
});
121
129
122
130
${ props . additionalCode }
You can’t perform that action at this time.
0 commit comments