From 1efd3ee3d53eaacba6a57e07b4b06b9bf941096a Mon Sep 17 00:00:00 2001 From: moklick Date: Mon, 8 Jan 2024 11:35:59 +0100 Subject: [PATCH] fix(applyChanges): handle empty flows + addNodes/addEdges closes #3770 --- packages/react/src/utils/changes.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/react/src/utils/changes.ts b/packages/react/src/utils/changes.ts index 30d01e47..be9460d0 100644 --- a/packages/react/src/utils/changes.ts +++ b/packages/react/src/utils/changes.ts @@ -54,20 +54,26 @@ function applyChanges(changes: any[], elements: any[]): any[] { return changes.filter((c) => c.type === 'reset').map((c) => c.item); } - let remainingChanges = changes; + let remainingChanges = []; const updatedElements: any[] = []; + for (const change of changes) { + if (change.type === 'add') { + updatedElements.push(change.item); + } else { + remainingChanges.push(change); + } + } + for (const item of elements) { const nextChanges: any[] = []; const _remainingChanges: any[] = []; - for (const c of remainingChanges) { - if (c.type === 'add') { - updatedElements.push(c.item); - } else if (c.id === item.id) { - nextChanges.push(c); + for (const change of remainingChanges) { + if (change.id === item.id) { + nextChanges.push(change); } else { - _remainingChanges.push(c); + _remainingChanges.push(change); } }