Skip to content

Commit

Permalink
feat(vue-shape): export clearItemsCache, VueNodeTeleport
Browse files Browse the repository at this point in the history
  • Loading branch information
wangcch committed Nov 7, 2024
1 parent e725973 commit 10af484
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions packages/x6-vue-shape/src/teleport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { defineComponent, h, reactive, isVue3, Teleport, markRaw, Fragment } from 'vue-demi'
import {
defineComponent,
h,
reactive,
isVue3,
Teleport,
markRaw,
Fragment,
onMounted,
} from 'vue-demi'
import { Graph } from '@antv/x6'
import { VueShape } from './node'

Expand All @@ -15,7 +24,10 @@ export function connect(
if (active) {
items[id] = markRaw(
defineComponent({
render: () => h(Teleport, { to: container } as any, [h(component, { node, graph })]),
render: () =>
h(Teleport, { to: container } as any, [
h(component, { node, graph }),
]),
provide: () => ({
getNode: () => node,
getGraph: () => graph,
Expand All @@ -31,6 +43,12 @@ export function disconnect(id: string) {
}
}

export function clearItemsCache() {
Object.keys(items).forEach((key) => {
delete items[key]
})
}

export function isActive() {
return active
}
Expand All @@ -52,3 +70,15 @@ export function getTeleport(): any {
},
})
}

export const VueNodeTeleport = defineComponent({
name: 'VueNodeTeleport',
setup() {
onMounted(() => {
clearItemsCache()
})

const TeleportContainer = getTeleport()
return () => h(TeleportContainer)
},
})

0 comments on commit 10af484

Please sign in to comment.