refactor(core): use computed to group edges

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2023-02-10 15:44:45 +01:00
committed by Braks
parent c528726f12
commit c62c18a20d
@@ -1,5 +1,4 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { WatchStopHandle } from 'vue'
import EdgeWrapper from '../../components/Edges/EdgeWrapper' import EdgeWrapper from '../../components/Edges/EdgeWrapper'
import ConnectionLine from '../../components/ConnectionLine/ConnectionLine.vue' import ConnectionLine from '../../components/ConnectionLine/ConnectionLine.vue'
import type { EdgeComponent, EdgeUpdatable, GraphEdge } from '../../types' import type { EdgeComponent, EdgeUpdatable, GraphEdge } from '../../types'
@@ -8,7 +7,6 @@ import MarkerDefinitions from './MarkerDefinitions.vue'
const slots = inject(Slots) const slots = inject(Slots)
const { const {
onPaneReady,
connectionStartHandle, connectionStartHandle,
nodesConnectable, nodesConnectable,
edgesUpdatable, edgesUpdatable,
@@ -46,23 +44,14 @@ const connectionLineVisible = $(
), ),
) )
let groups = $ref<ReturnType<typeof groupEdgesByZLevel>>([]) const groups = controlledComputed(
let stop: WatchStopHandle
onPaneReady(() => {
stop = watch(
[ [
() => getEdges.length,
() => getEdges.map((e) => e.zIndex), () => getEdges.map((e) => e.zIndex),
() => (elevateEdgesOnSelect ? getSelectedNodes.length : 0), () => (elevateEdgesOnSelect ? [getSelectedNodes.length] : [0]),
() => (elevateEdgesOnSelect ? getNodesInitialized.map((n) => n.computedPosition.z) : []), () => (elevateEdgesOnSelect ? getNodesInitialized.map((n) => n.computedPosition.z) : []),
], ],
() => { () => groupEdgesByZLevel(getEdges, findNode, elevateEdgesOnSelect),
groups = groupEdgesByZLevel(getEdges, findNode, elevateEdgesOnSelect) )
},
{ immediate: true },
)
})
onBeforeUnmount(() => { onBeforeUnmount(() => {
stop?.() stop?.()