From 9f5b7456d3acbca37b86db5948beaaba3f895207 Mon Sep 17 00:00:00 2001 From: Xalier Date: Sat, 3 Dec 2022 23:53:09 -0500 Subject: [PATCH] feat: Pass through replaceMerge when using setOption. --- README.md | 4 ++++ src/core.tsx | 13 ++++++++++--- src/types.ts | 4 ++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 343c02d..ca20840 100644 --- a/README.md +++ b/README.md @@ -237,6 +237,10 @@ the echarts option config, can see [https://echarts.apache.org/option.html#title when `setOption`, not merge the data, default is `false`. See [https://echarts.apache.org/api.html#echartsInstance.setOption](https://echarts.apache.org/api.html#echartsInstance.setOption). + - **`replaceMerge`** (optional, string | string[]) + +when `setOption`, default is `null`. See [https://echarts.apache.org/api.html#echartsInstance.setOption](https://echarts.apache.org/api.html#echartsInstance.setOption). + - **`lazyUpdate`** (optional, object) when `setOption`, lazy update the data, default is `false`. See [https://echarts.apache.org/api.html#echartsInstance.setOption](https://echarts.apache.org/api.html#echartsInstance.setOption). diff --git a/src/core.tsx b/src/core.tsx index 432627e..e144242 100644 --- a/src/core.tsx +++ b/src/core.tsx @@ -65,7 +65,7 @@ export default class EChartsReactCore extends PureComponent { } // when these props are not isEqual, update echarts - const pickKeys = ['option', 'notMerge', 'lazyUpdate', 'showLoading', 'loadingOption']; + const pickKeys = ['option', 'notMerge', 'replaceMerge', 'lazyUpdate', 'showLoading', 'loadingOption']; if (!isEqual(pick(this.props, pickKeys), pick(prevProps, pickKeys))) { this.updateEChartsOption(); } @@ -183,11 +183,18 @@ export default class EChartsReactCore extends PureComponent { * render the echarts */ private updateEChartsOption(): EChartsInstance { - const { option, notMerge = false, lazyUpdate = false, showLoading, loadingOption = null } = this.props; + const { + option, + notMerge = false, + replaceMerge = null, + lazyUpdate = false, + showLoading, + loadingOption = null, + } = this.props; // 1. get or initial the echarts object const echartInstance = this.getEchartsInstance(); // 2. set the echarts option - echartInstance.setOption(option, notMerge, lazyUpdate); + echartInstance.setOption(option, { notMerge, replaceMerge, lazyUpdate }); // 3. set loading mask if (showLoading) echartInstance.showLoading(loadingOption); else echartInstance.hideLoading(); diff --git a/src/types.ts b/src/types.ts index 4d37a87..f8a532d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -39,6 +39,10 @@ export type EChartsReactProps = { * notMerge config for echarts, default is `false` */ readonly notMerge?: boolean; + /** + * replaceMerge config for echarts, default is `null` + */ + readonly replaceMerge?: string | string[]; /** * lazyUpdate config for echarts, default is `false` */