feat(nodes): Pass node slots as injections to wrapper

* Avoids drilling slots which causes huge performance issues when 100+ nodes are present due to re-binding of props on each level
This commit is contained in:
Braks
2022-04-04 21:42:48 +02:00
parent b47197f498
commit 4cbdf0ccc1
6 changed files with 39 additions and 84 deletions
+4 -12
View File
@@ -3,6 +3,7 @@ import ZoomPane from '../ZoomPane/ZoomPane.vue'
import { createHooks, useHooks } from '../../store'
import { useVueFlow } from '../../composables'
import type { FlowProps } from '../../types/flow'
import { Slots } from '../../context'
import useWatch from './watch'
const props = withDefaults(defineProps<FlowProps>(), {
@@ -74,6 +75,9 @@ if (edges && edges.value) {
() => (edges.value = [...storedEdges.value]),
)
}
const slots = useSlots()
provide(Slots, slots)
</script>
<script lang="ts">
export default {
@@ -83,20 +87,8 @@ export default {
<template>
<div class="vue-flow">
<ZoomPane :key="`renderer-${id}`">
<template v-for="nodeName of Object.keys(getNodeTypes)" #[`node-${nodeName}`]="nodeProps" :key="`node-${nodeName}-${id}`">
<slot :name="`node-${nodeName}`" v-bind="nodeProps" />
</template>
<template v-for="edgeName of Object.keys(getEdgeTypes)" #[`edge-${edgeName}`]="edgeProps" :key="`edge-${edgeName}-${id}`">
<slot :name="`edge-${edgeName}`" v-bind="edgeProps" />
</template>
<template #connection-line="customConnectionLineProps">
<slot name="connection-line" v-bind="customConnectionLineProps" />
</template>
<slot name="zoom-pane" />
</ZoomPane>
<slot />
</div>
</template>
<style>
@import '../../style.css';
</style>