Skip to content

Commit 8575bb1

Browse files
committed
fix: theme-switch-keep-data. close apache##21200
1 parent 6be0e14 commit 8575bb1

File tree

2 files changed

+101
-3
lines changed

2 files changed

+101
-3
lines changed

src/core/echarts.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,8 @@ class ECharts extends Eventful<ECEventDefinition> {
744744
return;
745745
}
746746

747+
const backup = this.getOption ? this.getOption() : null;
748+
747749
let silent = opts && opts.silent;
748750
let updateParams = null as UpdateLifecycleParams;
749751

@@ -761,9 +763,6 @@ class ECharts extends Eventful<ECEventDefinition> {
761763
try {
762764
this._updateTheme(theme);
763765
ecModel.setTheme(this._theme);
764-
765-
prepare(this);
766-
updateMethods.update.call(this, {type: 'setTheme'}, updateParams);
767766
}
768767
catch (e) {
769768
this[IN_MAIN_PROCESS_KEY] = false;
@@ -772,6 +771,13 @@ class ECharts extends Eventful<ECEventDefinition> {
772771

773772
this[IN_MAIN_PROCESS_KEY] = false;
774773

774+
if (backup) {
775+
this.setOption(backup as any, { notMerge: true, lazyUpdate: false, silent: !!silent });
776+
return;
777+
}
778+
779+
prepare(this);
780+
updateMethods.update.call(this, {type: 'setTheme'}, updateParams);
775781
flushPendingActions.call(this, silent);
776782
triggerUpdatedEvent.call(this, silent);
777783
}

test/theme-switch-keep-data.html

Lines changed: 92 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)