From 90a2a6544d8762061ac19ec4a68c06c61dabcdb0 Mon Sep 17 00:00:00 2001 From: Braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Thu, 18 Nov 2021 14:32:30 +0100 Subject: [PATCH] update(zoom): remove watcher and use until * wait until height and width are set for zoom pane to trigger load hook Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com> --- src/container/ZoomPane/ZoomPane.vue | 33 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/container/ZoomPane/ZoomPane.vue b/src/container/ZoomPane/ZoomPane.vue index 67774ade..28a2a14d 100644 --- a/src/container/ZoomPane/ZoomPane.vue +++ b/src/container/ZoomPane/ZoomPane.vue @@ -55,6 +55,8 @@ const clampedZoom = clamp(props.defaultZoom, store.minZoom, store.maxZoom) const transform = ref({ x: clampedX, y: clampedY, zoom: clampedZoom }) const d3Zoom = ref(zoom().scaleExtent([store.minZoom, store.maxZoom]).translateExtent(store.translateExtent)) const d3Selection = ref() + +const { zoomIn, zoomOut, zoomTo, transform: setTransform, fitView } = useZoomPanHelper() store.transform = [transform.value.x, transform.value.y, transform.value.zoom] invoke(async () => { @@ -182,6 +184,20 @@ store.dimensions = { height: height.value, } +invoke(async () => { + await until(() => !isNaN(width.value) && width.value > 0 && !isNaN(height.value) && height.value > 0).toBeTruthy() + hooks.load.trigger({ + fitView: (params = { padding: 0.1 }) => fitView(params), + zoomIn, + zoomOut, + zoomTo, + setTransform, + project: onLoadProject(store), + getElements: onLoadGetElements(store), + toObject: onLoadToObject(store), + }) +}) + watch( [width, height], ([newWidth, newHeight]) => { @@ -200,23 +216,6 @@ watch( ]), { flush: 'pre' }, ) - -const { zoomIn, zoomOut, zoomTo, transform: setTransform, fitView } = useZoomPanHelper() -watchOnce( - () => !isNaN(width.value) && width.value > 0 && !isNaN(height.value) && height.value > 0, - () => { - hooks.load.trigger({ - fitView: (params = { padding: 0.1 }) => fitView(params), - zoomIn, - zoomOut, - zoomTo, - setTransform, - project: onLoadProject(store), - getElements: onLoadGetElements(store), - toObject: onLoadToObject(store), - }) - }, -)