Skip to content

Commit 899ef4b

Browse files
committed
fix: chart instance should always be initialized
1 parent 677f100 commit 899ef4b

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 6.0.2
2+
3+
* Make `notMerge` option still respect `update-options`.
4+
* The default behavior of `notMerge` now revert to checking if there is a reference change for the `option` prop.
5+
16
## 6.0.1
27

38
* Update should always be `notMerge: true`.

src/ECharts.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default defineComponent({
8080
const { autoresize, manualUpdate, loading, loadingOptions } = toRefs(props);
8181

8282
const realOption = computed(
83-
() => manualOption.value || props.option || Object.create(null)
83+
() => manualOption.value || props.option || null
8484
);
8585
const realTheme = computed(() => props.theme || unref(defaultTheme) || {});
8686
const realInitOptions = computed(
@@ -92,7 +92,7 @@ export default defineComponent({
9292
const nonEventAttrs = computed(() => omitOn(attrs));
9393

9494
function init(option?: Option) {
95-
if (chart.value || !root.value) {
95+
if (!root.value) {
9696
return;
9797
}
9898

@@ -141,7 +141,10 @@ export default defineComponent({
141141
}
142142

143143
function commit() {
144-
instance.setOption(option || realOption.value, realUpdateOptions.value);
144+
const opt = option || realOption.value;
145+
if (opt) {
146+
instance.setOption(opt, realUpdateOptions.value);
147+
}
145148
}
146149

147150
if (autoresize.value) {
@@ -226,16 +229,14 @@ export default defineComponent({
226229
}
227230
});
228231

229-
const publicApi = usePublicAPI(chart, init);
232+
const publicApi = usePublicAPI(chart);
230233

231234
useLoading(chart, loading, loadingOptions);
232235

233236
useAutoresize(chart, autoresize, root);
234237

235238
onMounted(() => {
236-
if (props.option) {
237-
init();
238-
}
239+
init();
239240
});
240241

241242
onUnmounted(cleanup);

src/composables/api.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { Ref } from "vue-demi";
3-
import { EChartsType, Option } from "../types";
3+
import { EChartsType } from "../types";
44

55
const METHOD_NAMES = [
66
"getWidth",
@@ -24,17 +24,12 @@ type MethodName = typeof METHOD_NAMES[number];
2424
type PublicMethods = Pick<EChartsType, MethodName>;
2525

2626
export function usePublicAPI(
27-
chart: Ref<EChartsType | undefined>,
28-
init: (option?: Option) => void
27+
chart: Ref<EChartsType | undefined>
2928
): PublicMethods {
3029
function makePublicMethod<T extends MethodName>(
3130
name: T
3231
): (...args: Parameters<EChartsType[T]>) => ReturnType<EChartsType[T]> {
3332
return (...args) => {
34-
if (!chart.value) {
35-
init();
36-
}
37-
3833
if (!chart.value) {
3934
throw new Error("ECharts is not initialized yet.");
4035
}

src/demo/Demo.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,9 @@ export default {
590590
},
591591
mounted() {
592592
this.startActions();
593+
},
594+
beforeUnmount() {
595+
this.stopActions();
593596
}
594597
};
595598
</script>

0 commit comments

Comments
 (0)