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 { emit, on } = useNodeHooks(node)
const scope = effectScope()
const dragging = useDrag({ const dragging = useDrag({
id, id,
el: nodeElement, el: nodeElement,
@@ -60,14 +62,6 @@ const observer = useResizeObserver(
{ box: 'content-box' }, { 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) => { const updatePosition = (nodePos: XYZPosition, parentPos?: XYZPosition) => {
if (parentPos) { if (parentPos) {
node.computedPosition = getXYZPos({ x: parentPos.x, y: parentPos.y, z: parentPos.z! }, nodePos) node.computedPosition = getXYZPos({ x: parentPos.x, y: parentPos.y, z: parentPos.z! }, nodePos)
@@ -91,10 +85,15 @@ onUpdateNodeInternals((updateIds) => {
} }
}) })
onBeforeUnmount(() => observer.stop())
onMounted(() => { 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( watch(
[ [
@@ -121,6 +120,12 @@ onMounted(() => {
{ immediate: true, flush: 'post' }, { immediate: true, flush: 'post' },
) )
}) })
})
onBeforeUnmount(() => {
observer.stop()
scope.stop()
})
const onMouseEnter = (event: MouseEvent) => { const onMouseEnter = (event: MouseEvent) => {
if (!dragging) { if (!dragging) {