Skip to content

Commit

Permalink
Add destroyDelay prop (#1085)
Browse files Browse the repository at this point in the history
* fix: use on-unmounted instead of on-before-unmount

* feat: add destroyDelay prop
  • Loading branch information
doutatsu authored Apr 9, 2024
1 parent f5ffcab commit 8d19c31
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
defineComponent,
h,
nextTick,
onBeforeUnmount,
onUnmounted,
onMounted,
ref,
shallowRef,
Expand Down Expand Up @@ -49,8 +49,15 @@ export const Chart = defineComponent({
const chart = toRaw(chartRef.value)

if (chart) {
chart.destroy()
chartRef.value = null
if (props.destroyDelay > 0) {
setTimeout(() => {
chart.destroy()
chartRef.value = null
}, props.destroyDelay)
} else {
chart.destroy()
chartRef.value = null
}
}
}

Expand All @@ -60,7 +67,7 @@ export const Chart = defineComponent({

onMounted(renderChart)

onBeforeUnmount(destroyChart)
onUnmounted(destroyChart)

watch(
[() => props.options, () => props.data],
Expand Down
4 changes: 4 additions & 0 deletions src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export const Props = {
type: String as PropType<ChartType>,
required: true
},
destroyDelay: {
type: Number,
default: 0 // No delay by default
},
...CommonProps,
...A11yProps
} as const

0 comments on commit 8d19c31

Please sign in to comment.