refactor(core): use watcheffect to observe node dimensions

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2023-02-10 13:28:42 +01:00
committed by Braks
parent 9a14d8b349
commit a5ee9d978c
2 changed files with 10 additions and 7 deletions

View File

@@ -88,13 +88,16 @@ onUpdateNodeInternals((updateIds) => {
}
})
onMounted(() => {
props.resizeObserver.observe(nodeElement.value as HTMLDivElement)
})
watchEffect(
(onCleanup) => {
if (!node.hidden) {
props.resizeObserver.observe(nodeElement.value as HTMLDivElement)
onBeforeUnmount(() => {
props.resizeObserver.unobserve(nodeElement.value as HTMLDivElement)
})
onCleanup(() => props.resizeObserver.unobserve(nodeElement.value as HTMLDivElement))
}
},
{ flush: 'post' },
)
watch(
[() => node.type, () => node.sourcePosition, () => node.targetPosition],

View File

@@ -29,7 +29,7 @@ until(() => nodes.length > 0 && getNodesInitialized.length === nodes.length)
onMounted(() => {
resizeObserver = new ResizeObserver((entries) => {
const updates = entries.map((entry: ResizeObserverEntry) => {
const updates = entries.map((entry) => {
const id = entry.target.getAttribute('data-id') as string
return {