Skip to content

Commit

Permalink
feat: Pass through replaceMerge when using setOption. (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xalier authored Jan 10, 2025
1 parent f90ab4a commit d151b14
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
13 changes: 10 additions & 3 deletions src/core.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
}

// 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();
}
Expand Down Expand Up @@ -183,11 +183,18 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
* 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();
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
*/
Expand Down

0 comments on commit d151b14

Please sign in to comment.