Fixed bug with corrupted map state on token deletion

This commit is contained in:
Mitchell McCaffrey
2021-04-16 13:36:14 +10:00
parent 3577938501
commit 1d5cf77aea
7 changed files with 36 additions and 24 deletions
+10 -1
View File
@@ -1,8 +1,17 @@
import { applyChange, revertChange, diff as deepDiff } from "deep-diff";
import get from "lodash.get";
export function applyChanges(target, changes) {
for (let change of changes) {
applyChange(target, true, change);
if (change.path && (change.kind === "E" || change.kind === "A")) {
// If editing an object or array ensure that the value exists
const valid = get(target, change.path) !== undefined;
if (valid) {
applyChange(target, true, change);
}
} else {
applyChange(target, true, change);
}
}
}