fix(applyChanges): handle empty flows + addNodes/addEdges closes #3770
This commit is contained in:
@@ -54,20 +54,26 @@ function applyChanges(changes: any[], elements: any[]): any[] {
|
|||||||
return changes.filter((c) => c.type === 'reset').map((c) => c.item);
|
return changes.filter((c) => c.type === 'reset').map((c) => c.item);
|
||||||
}
|
}
|
||||||
|
|
||||||
let remainingChanges = changes;
|
let remainingChanges = [];
|
||||||
const updatedElements: any[] = [];
|
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) {
|
for (const item of elements) {
|
||||||
const nextChanges: any[] = [];
|
const nextChanges: any[] = [];
|
||||||
const _remainingChanges: any[] = [];
|
const _remainingChanges: any[] = [];
|
||||||
|
|
||||||
for (const c of remainingChanges) {
|
for (const change of remainingChanges) {
|
||||||
if (c.type === 'add') {
|
if (change.id === item.id) {
|
||||||
updatedElements.push(c.item);
|
nextChanges.push(change);
|
||||||
} else if (c.id === item.id) {
|
|
||||||
nextChanges.push(c);
|
|
||||||
} else {
|
} else {
|
||||||
_remainingChanges.push(c);
|
_remainingChanges.push(change);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user