From 390175226ec4aa41e8bebad849db4142cbc097dd Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Wed, 18 Jan 2023 12:32:07 +0100 Subject: [PATCH] fix(core): add timeout when updating positions after extent changes Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> --- .../core/src/components/Nodes/NodeWrapper.vue | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/packages/core/src/components/Nodes/NodeWrapper.vue b/packages/core/src/components/Nodes/NodeWrapper.vue index b48cbdcc..25b81a34 100644 --- a/packages/core/src/components/Nodes/NodeWrapper.vue +++ b/packages/core/src/components/Nodes/NodeWrapper.vue @@ -139,21 +139,16 @@ watch( { flush: 'pre', immediate: true }, ) -watch( - [() => node.extent, () => nodeExtent], - ([nodeExtent, globalExtent], [oldNodeExtent, oldGlobalExtent]) => { - // update position if extent has actually changed - if (nodeExtent !== oldNodeExtent || globalExtent !== oldGlobalExtent) { - updatePosition() - } - }, - { flush: 'pre' }, -) +watch([() => node.extent, () => nodeExtent], ([nodeExtent, globalExtent], [oldNodeExtent, oldGlobalExtent]) => { + // update position if extent has actually changed + if (nodeExtent !== oldNodeExtent || globalExtent !== oldGlobalExtent) { + // todo: can we solve this without a timeout? Otherwise the extent is not properly calculated + setTimeout(updatePosition) + } +}) -// todo: do we need to wait for initialized? Or can we clamp the position immediately? -until(() => node.initialized) - .toBe(true) - .then(updatePosition) +// clamp initial position to nodes' extent +updatePosition() /** this re-calculates the current position, necessary for clamping by a node's extent */ function updatePosition() {