From 46815e546ae03dc4b6f644cecf961fbb93c6b2cd Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 5 Dec 2023 14:26:55 +0100 Subject: [PATCH] TSDocs for applyNodeChanges & applyEdgeChanges --- packages/react/src/utils/changes.ts | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/packages/react/src/utils/changes.ts b/packages/react/src/utils/changes.ts index c113ebe1..0cf87e6f 100644 --- a/packages/react/src/utils/changes.ts +++ b/packages/react/src/utils/changes.ts @@ -139,10 +139,50 @@ function applyChanges(changes: any[], elements: any[]): any[] { }, initElements); } +/** + * Drop in function that applies node changes to an array of nodes. + * @public + * @remarks Various events on the component can produce an {@link NodeChange} that describes how to update the edges of your flow in some way. + If you don't need any custom behaviour, this util can be used to take an array of these changes and apply them to your edges. + * @param changes - Array of changes to apply + * @param nodes - Array of nodes to apply the changes to + * @returns Array of updated nodes + * @example + * const onNodesChange = useCallback( + (changes) => { + setNodes((oldNodes) => applyNodeChanges(changes, oldNodes)); + }, + [setNodes], + ); + + return ( + + ); + */ export function applyNodeChanges(changes: NodeChange[], nodes: Node[]): Node[] { return applyChanges(changes, nodes) as Node[]; } +/** + * Drop in function that applies edge changes to an array of edges. + * @public + * @remarks Various events on the component can produce an {@link EdgeChange} that describes how to update the edges of your flow in some way. + If you don't need any custom behaviour, this util can be used to take an array of these changes and apply them to your edges. + * @param changes - Array of changes to apply + * @param edges - Array of edge to apply the changes to + * @returns Array of updated edges + * @example + * const onEdgesChange = useCallback( + (changes) => { + setEdges((oldEdges) => applyEdgeChanges(changes, oldEdges)); + }, + [setEdges], + ); + + return ( + + ); + */ export function applyEdgeChanges(changes: EdgeChange[], edges: Edge[]): Edge[] { return applyChanges(changes, edges) as Edge[]; }