refactor(core): check if element still exists before attempting removal

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2023-01-06 09:21:03 +01:00
committed by Braks
parent 20dc364360
commit 8422dbdc56
+5 -10
View File
@@ -115,16 +115,11 @@ export const applyChanges = <
| EdgeRemoveChange
)[]
addRemoveChanges.forEach((change) => {
switch (change.type) {
case 'add':
elements.push(<T>change.item)
break
case 'remove':
elements.splice(
elements.findIndex((el) => el.id === change.id),
1,
)
break
if (change.type === 'add') {
elements.push(<T>change.item)
} else if (change.type === 'remove') {
const index = elements.findIndex((el) => el.id === change.id)
if (index !== -1) elements.splice(index, 1)
}
})