From 7d9d251389091fb0522c1e0623c5d6e4d8885592 Mon Sep 17 00:00:00 2001 From: MeloAlright Date: Sat, 17 Aug 2024 13:28:11 +0800 Subject: [PATCH] Attached (#43) * feat: add progress in vue playground * feat: add 600 delay * feat: check attached and isMounted --- vue-skia-framework/plugin/index.ts | 7 ++++++- vue-skia-framework/type.ts | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/vue-skia-framework/plugin/index.ts b/vue-skia-framework/plugin/index.ts index 8e3182b..5bb4f26 100644 --- a/vue-skia-framework/plugin/index.ts +++ b/vue-skia-framework/plugin/index.ts @@ -64,6 +64,7 @@ const VSKNode = (name: string) => { instance._ssw_id = ( parent as ComponentInternalInstanceWithSoftSkiaWASM )._ssw_id; + instance._ssw_attached = true; instance._ssw_grouped = (child) => { core.setAttrBySerde(instance._ssw_id, { @@ -103,6 +104,7 @@ const VSKNode = (name: string) => { } const core = root.ssw; instance._ssw_id = SelfIncreaseCount.count; + instance._ssw_attached = true; var parent = instance.parent; while (!('_ssw_id' in parent)) { parent = parent.parent; @@ -208,7 +210,10 @@ const VSKNode = (name: string) => { while (!('_ssw_id' in parent)) { parent = parent.parent; } - core.removeChildFromContainer(child_id, (parent as ComponentInternalInstanceWithSoftSkiaWASM)._ssw_id) + instance._ssw_attached = false; + if ((parent as ComponentInternalInstanceWithSoftSkiaWASM)._ssw_attached && parent.isMounted) { + core.removeChildFromContainer(child_id, (parent as ComponentInternalInstanceWithSoftSkiaWASM)._ssw_id) + } }); return () => h(name, {}, slots.default?.()) diff --git a/vue-skia-framework/type.ts b/vue-skia-framework/type.ts index 82a975a..b1259a3 100644 --- a/vue-skia-framework/type.ts +++ b/vue-skia-framework/type.ts @@ -6,6 +6,7 @@ import { SoftSkiaWASM } from '../soft-skia-wasm/pkg/'; export type ComponentInternalInstanceWithSoftSkiaWASM = ComponentInternalInstance & { ssw: SoftSkiaWASM; _ssw_id: number; + _ssw_attached: boolean; _ssw_grouped?: (instance: ComponentInternalInstanceWithSoftSkiaWASM) => void; _ssw_batchDraw?: () => void; }