Skip to content

Commit

Permalink
Merge pull request #2096 from VisActor/refactor/react-vchart
Browse files Browse the repository at this point in the history
refactor: deprecated useSyncRender in react-vchart
  • Loading branch information
xile611 authored Jan 22, 2024
2 parents 21c95f4 + f74b564 commit a5381a3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "refactor: deprecated `useSyncRender` in react-vchart\n\n",
"type": "none",
"packageName": "@visactor/vchart"
}
],
"packageName": "@visactor/vchart",
"email": "[email protected]"
}
45 changes: 13 additions & 32 deletions packages/react-vchart/src/charts/BaseChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface BaseChartProps
* use sync render
*
* @since 1.8.3
* @deprecated 1.9.0
**/
useSyncRender?: boolean;
}
Expand Down Expand Up @@ -90,7 +91,6 @@ const BaseChart: React.FC<Props> = React.forwardRef((props, ref) => {
const prevSpec = useRef(pickWithout(props, notSpecKeys));
const eventsBinded = React.useRef<BaseChartProps>(null);
const skipFunctionDiff = !!props.skipFunctionDiff;
const useSyncRender = !!props.useSyncRender;

const parseSpec = (props: Props) => {
if (hasSpec && props.spec) {
Expand Down Expand Up @@ -134,13 +134,8 @@ const BaseChart: React.FC<Props> = React.forwardRef((props, ref) => {

const renderChart = () => {
if (chartContext.current.chart) {
if (useSyncRender) {
chartContext.current.chart.renderSync();
handleChartRender();
} else {
// eslint-disable-next-line promise/catch-or-return
chartContext.current.chart.renderAsync().then(handleChartRender);
}
chartContext.current.chart.renderSync();
handleChartRender();
}
};

Expand All @@ -160,18 +155,11 @@ const BaseChart: React.FC<Props> = React.forwardRef((props, ref) => {
if (hasSpec) {
if (!isEqual(eventsBinded.current.spec, props.spec, { skipFunction: skipFunctionDiff })) {
eventsBinded.current = props;
if (useSyncRender) {
chartContext.current.chart.updateSpecSync(parseSpec(props), undefined, {
morph: false,
enableExitAnimation: false
});
handleChartRender();
} else {
// eslint-disable-next-line promise/catch-or-return
chartContext.current.chart
.updateSpec(parseSpec(props), undefined, { morph: false, enableExitAnimation: false }) // morph临时关掉
.then(handleChartRender);
}
chartContext.current.chart.updateSpecSync(parseSpec(props), undefined, {
morph: false,
enableExitAnimation: false
});
handleChartRender();
}
return;
}
Expand All @@ -184,18 +172,11 @@ const BaseChart: React.FC<Props> = React.forwardRef((props, ref) => {
) {
prevSpec.current = newSpec;

if (useSyncRender) {
chartContext.current.chart.updateSpecSync(parseSpec(props), undefined, {
morph: false,
enableExitAnimation: false
});
handleChartRender();
} else {
// eslint-disable-next-line promise/catch-or-return
chartContext.current.chart
.updateSpec(parseSpec(props), undefined, { morph: false, enableExitAnimation: false }) // morph临时关掉
.then(handleChartRender);
}
chartContext.current.chart.updateSpecSync(parseSpec(props), undefined, {
morph: false,
enableExitAnimation: false
});
handleChartRender();
}
chartContext.current = {
...chartContext.current,
Expand Down

0 comments on commit a5381a3

Please sign in to comment.