update: a couple more perfomance related updates

* check for selected value inside Node instead of the wrapping renderer
* instead of "parsing" elements just return the current store.elements object
* use map funct to find index

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2021-11-19 15:41:00 +01:00
parent 08b9afb502
commit f92c5462bf
7 changed files with 49 additions and 51 deletions
+17 -14
View File
@@ -1,4 +1,5 @@
<script lang="ts" setup>
import { invoke } from '@vueuse/core'
import { Node as TNode } from '../../types'
import { useStore } from '../../composables'
import Node from '../../components/Nodes/Node.vue'
@@ -24,24 +25,26 @@ const type = (node: TNode) => {
}
return type
}
const selected = (nodeId: string) => store.selectedElements?.some(({ id }) => id === nodeId)
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>
<template>
<div class="vue-flow__nodes" :style="{ transform }">
<Suspense>
<template v-for="node of store.getNodes" :key="node.id">
<Node
:node="node"
:type="type(node)"
:snap-grid="snapGrid"
:select-nodes-on-drag="props.selectNodesOnDrag"
:selected="selected(node.id)"
>
<template #default="nodeProps">
<slot :name="`node-${node.type}`" v-bind="nodeProps"></slot>
</template>
</Node>
</template>
<Node
v-for="node of store.getNodes"
:key="node.id"
:node="node"
:type="type(node)"
:snap-grid="snapGrid"
:select-nodes-on-drag="props.selectNodesOnDrag"
>
<template #default="nodeProps">
<slot :name="`node-${node.type}`" v-bind="nodeProps"></slot>
</template>
</Node>
</Suspense>
</div>
</template>