fix: suspension not working properly

* move invoke to vueflow to suspend
* await dimensions in Node/Edge-wrapper components
* await nodes/edges in renderer
* await elements in VueFlow

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2021-11-20 02:00:37 +01:00
parent a4e3bf52c7
commit d25fa579e4
6 changed files with 63 additions and 59 deletions
+2 -2
View File
@@ -1,9 +1,9 @@
<script lang="ts" setup> <script lang="ts" setup>
import { useHandle, useStore } from '../../composables' import { useHandle, useStore } from '../../composables'
import { ConnectionMode, Edge, EdgePositions, Position } from '../../types' import { ConnectionMode, Edge, EdgePositions, Position } from '../../types'
import { getEdgePositions, getHandle, getSourceTargetNodes, isEdgeVisible } from '../../container/EdgeRenderer/utils'
import { isEdge } from '../../utils'
import EdgeAnchor from './EdgeAnchor.vue' import EdgeAnchor from './EdgeAnchor.vue'
import { getEdgePositions, getHandle, getSourceTargetNodes, isEdgeVisible } from '~/container/EdgeRenderer/utils'
import { isEdge } from '~/utils'
interface EdgeProps { interface EdgeProps {
edge: Edge edge: Edge
-2
View File
@@ -148,7 +148,6 @@ onMounted(() => {
@move="onDrag" @move="onDrag"
@stop="onDragStop" @stop="onDragStop"
> >
<Suspense>
<div <div
ref="node-element" ref="node-element"
:class="[ :class="[
@@ -206,6 +205,5 @@ onMounted(() => {
/> />
</slot> </slot>
</div> </div>
</Suspense>
</DraggableCore> </DraggableCore>
</template> </template>
+7 -1
View File
@@ -1,6 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { CSSProperties } from 'vue' import { CSSProperties } from 'vue'
import { ConnectionLineType, Edge as TEdge } from '../../types' import { invoke } from '@vueuse/core'
import { ConnectionLineType } from '../../types'
import { useStore } from '../../composables' import { useStore } from '../../composables'
import Edge from '../../components/Edges/Edge.vue' import Edge from '../../components/Edges/Edge.vue'
import ConnectionLine from '../../components/ConnectionLine/ConnectionLine.vue' import ConnectionLine from '../../components/ConnectionLine/ConnectionLine.vue'
@@ -22,6 +23,11 @@ const props = withDefaults(defineProps<EdgeRendererProps>(), {
const store = useStore() const store = useStore()
invoke(async () => {
await until(store.getNodes).toMatch((y) => y && y.length > 0)
await until(store.transform).toMatch(([x, y, z]) => !isNaN(x) && x !== 0 && !isNaN(y) && y !== 0 && isNaN(z) && z !== 1)
})
const sourceNode = computed(() => store.nodes.find((n) => n.id === store.connectionNodeId)) const sourceNode = computed(() => store.nodes.find((n) => n.id === store.connectionNodeId))
const connectionLineVisible = computed( const connectionLineVisible = computed(
() => !!(store.nodesConnectable && sourceNode.value && store.connectionNodeId && store.connectionHandleType), () => !!(store.nodesConnectable && sourceNode.value && store.connectionNodeId && store.connectionHandleType),
+6 -7
View File
@@ -13,17 +13,16 @@ const props = withDefaults(defineProps<NodeRendererProps>(), {
const store = useStore() const store = useStore()
invoke(async () => {
await until(store.getNodes).toMatch((y) => y && y.length > 0)
await until(store.transform).toMatch(([x, y, z]) => !isNaN(x) && x !== 0 && !isNaN(y) && y !== 0 && isNaN(z) && z !== 1)
})
const transform = computed(() => `translate(${store.transform[0]}px,${store.transform[1]}px) scale(${store.transform[2]})`) const transform = computed(() => `translate(${store.transform[0]}px,${store.transform[1]}px) scale(${store.transform[2]})`)
const snapGrid = computed(() => (store.snapToGrid ? store.snapGrid : undefined)) const snapGrid = computed(() => (store.snapToGrid ? store.snapGrid : undefined))
invoke(async () => {
await until(store.getNodes).toMatch((y) => y.length > 0)
await until(store.transform).toMatch(([x, y, z]) => x !== 0 && y !== 0 && z !== 1)
})
</script> </script>
<template> <template>
<div class="vue-flow__nodes" :style="{ transform }">
<Suspense> <Suspense>
<div class="vue-flow__nodes" :style="{ transform }">
<Node <Node
v-for="node of store.getNodes" v-for="node of store.getNodes"
:key="node.id" :key="node.id"
@@ -35,6 +34,6 @@ invoke(async () => {
<slot :name="`node-${node.type}`" v-bind="nodeProps"></slot> <slot :name="`node-${node.type}`" v-bind="nodeProps"></slot>
</template> </template>
</Node> </Node>
</Suspense>
</div> </div>
</Suspense>
</template> </template>
+3 -1
View File
@@ -1,6 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { CSSProperties, onBeforeUnmount } from 'vue' import { CSSProperties, onBeforeUnmount } from 'vue'
import diff from 'microdiff' import diff from 'microdiff'
import { invoke } from '@vueuse/core'
import { import {
ConnectionLineType, ConnectionLineType,
ConnectionMode, ConnectionMode,
@@ -126,7 +127,7 @@ const init = (state: FlowState) => {
} }
onBeforeUnmount(() => store?.$dispose()) onBeforeUnmount(() => store?.$dispose())
init(options) onMounted(() => init(options))
watch(elements, (val) => store.setElements(val), { flush: 'post', deep: true }) watch(elements, (val) => store.setElements(val), { flush: 'post', deep: true })
watch( watch(
() => store.elements, () => store.elements,
@@ -146,6 +147,7 @@ watch(
}, },
{ flush: 'pre', deep: true }, { flush: 'pre', deep: true },
) )
invoke(async () => await until(store.elements).toMatch((y) => y.length > 0))
</script> </script>
<template> <template>
<div class="vue-flow"> <div class="vue-flow">
-1
View File
@@ -185,7 +185,6 @@ store.dimensions = {
invoke(async () => { invoke(async () => {
await until(() => !isNaN(width.value) && width.value > 0 && !isNaN(height.value) && height.value > 0).toBeTruthy() await until(() => !isNaN(width.value) && width.value > 0 && !isNaN(height.value) && height.value > 0).toBeTruthy()
await until(store.elements).toMatch((y) => y.length > 0)
const instance: FlowInstance = { const instance: FlowInstance = {
fitView: (params = { padding: 0.1 }) => fitView(params), fitView: (params = { padding: 0.1 }) => fitView(params),
zoomIn, zoomIn,