addEdge()
This util is a convenience function to add a new Edge
to an
array of edges. It also performs some validation to make sure you donβt add an
invalid edge or duplicate an existing one.
import { writable } from 'svelte/store';
import { addEdge } from '@xyflow/svelte';
const edges = writable([]);
const onAddEdge = () => {
const newEdge = {
id: '1-2',
source: '1',
target: '2'
};
$edges = addEdge(newEdge, $edges);
}
Signature
Name | Type |
---|---|
#Params |
|
# edge | |
# edges | Edge[] |
#Returns |
|
Edge[] |
Notes
- If an edge with the same
target
andsource
already exists (and the sametargetHandle
andsourceHandle
if those are set), then this util wonβt add a new edge even if theid
property is different.
Last updated on