chore(nodes): use scope for node watchers

This commit is contained in:
bcakmakoglu
2022-06-23 19:13:50 +02:00
committed by Braks
parent 6c06eeee74
commit eb28934cee
@@ -37,6 +37,8 @@ const nodeElement = ref()
const { emit, on } = useNodeHooks(node)
const scope = effectScope()
const dragging = useDrag({
id,
el: nodeElement,
@@ -60,14 +62,6 @@ const observer = useResizeObserver(
{ box: 'content-box' },
)
watch(
[() => node.width, () => node.height, () => node.type, () => node.sourcePosition, () => node.targetPosition],
() => {
updateNodeDimensions([{ id, nodeElement: nodeElement.value }])
},
{ flush: 'post' },
)
const updatePosition = (nodePos: XYZPosition, parentPos?: XYZPosition) => {
if (parentPos) {
node.computedPosition = getXYZPos({ x: parentPos.x, y: parentPos.y, z: parentPos.z! }, nodePos)
@@ -91,10 +85,15 @@ onUpdateNodeInternals((updateIds) => {
}
})
onBeforeUnmount(() => observer.stop())
onMounted(() => {
updateNodeDimensions([{ id, nodeElement: nodeElement.value, forceUpdate: true }])
scope.run(() => {
watch(
[() => node.width, () => node.height, () => node.type, () => node.sourcePosition, () => node.targetPosition],
() => {
updateNodeDimensions([{ id, nodeElement: nodeElement.value }])
},
{ immediate: true, flush: 'post' },
)
watch(
[
@@ -120,6 +119,12 @@ onMounted(() => {
},
{ immediate: true, flush: 'post' },
)
})
})
onBeforeUnmount(() => {
observer.stop()
scope.stop()
})
const onMouseEnter = (event: MouseEvent) => {