Skip to content

Commit

Permalink
feat: check attached and isMounted
Browse files Browse the repository at this point in the history
  • Loading branch information
meloalright committed Aug 17, 2024
1 parent 117dc0e commit 0a9aac4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion vue-skia-framework/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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?.())
Expand Down
1 change: 1 addition & 0 deletions vue-skia-framework/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0a9aac4

Please sign in to comment.