fix(useReactFlow): use onNodesChange and onEdgesChange

This commit is contained in:
moklick
2022-03-15 18:38:58 +01:00
parent 514c15c0ef
commit 5b32746422
5 changed files with 107 additions and 36 deletions
+8 -2
View File
@@ -44,8 +44,14 @@ function handleParentExpand(res: any[], updateItem: any) {
}
}
function applyChanges(changes: NodeChange[] | EdgeChange[], elements: any[]): any[] {
const initElements: any[] = [];
function applyChanges(changes: any[], elements: any[]): any[] {
// unfortunately we need this hack to handle the setNodes and setEdges function of the
// useReactFlow hook.
if (changes.some((c) => c.type === 'reset')) {
return changes.filter((c) => c.type === 'reset').map((c) => c.item);
}
const initElements: any[] = changes.filter((c) => c.type === 'add').map((c) => c.item);
return elements.reduce((res: any[], item: any) => {
const currentChange = changes.find((c) => c.id === item.id);