Skip to Content
Svelte Flow 2 is out! Read the announcement →
ReferenceTypes

EdgeChangeset

An EdgeChangeset is what Svelte Flow passes to your onedgeschange handler whenever edges change. It holds the EdgeChange objects that are about to be applied. Svelte Flow calls your handler before it applies the changes and then applies whatever is left in the changeset to your edges.

Source on GitHub 

<script lang="ts"> import { SvelteFlow, type Node, type Edge, type EdgeChangeset } from '@xyflow/svelte'; let nodes = $state.raw<Node[]>([]); let edges = $state.raw<Edge[]>([]); function onedgeschange(changes: EdgeChangeset<Edge>) { console.log(changes.toArray()); } </script> <SvelteFlow bind:nodes bind:edges {onedgeschange} />

Reading changes

A changeset is iterable, and it can hand you changes by type or by edge — so inspecting an update doesn’t mean scanning an array yourself.

// every change, in order for (const change of changes) { console.log(change.type, change.id); } // just the removals if (changes.getByType('remove').length > 0) { saveUndoSnapshot(); } // everything queued for one edge const changesForEdge = changes.getForEdge('e1-2');

Editing changes

Because the changeset is a real object, you can drop or add changes inside your handler before Svelte Flow applies them — handy for vetoing an update without rebuilding the array.

function onedgeschange(changes: EdgeChangeset<Edge>) { // keep this edge no matter what the interaction asked for changes.removeForEdge('e1-2'); }

Applying changes yourself

If you want to apply the changes yourself, use applyTo() and call clear() afterwards, so that Svelte Flow doesn’t apply them a second time.

function onedgeschange(changes: EdgeChangeset<Edge>) { edges = changes.applyTo(edges); changes.clear(); }

Notes

  • Construct one yourself with new EdgeChangeset(changes?) — for example to replay recorded changes.
  • Nodes have the mirrored NodeChangeset.