Skip to content

Commit

Permalink
Make sure to check object-type before comparision #31
Browse files Browse the repository at this point in the history
  • Loading branch information
alshakero committed Jun 2, 2018
1 parent 24dd436 commit f7f5665
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/duplex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,10 @@ function _generate(mirror, obj, patches, path) {
for (var t = oldKeys.length - 1; t >= 0; t--) {
var key = oldKeys[t];
var oldVal = mirror[key];

if (hasOwnProperty(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) {
var newVal = obj[key];

if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null) {
_generate(oldVal, newVal, patches, path + "/" + escapePathComponent(key));
}
Expand All @@ -217,9 +219,12 @@ function _generate(mirror, obj, patches, path) {
}
}
}
else {
else if(Array.isArray(mirror) === Array.isArray(obj)) {
patches.push({ op: "remove", path: path + "/" + escapePathComponent(key) });
deleted = true; // property has been deleted
} else {
patches.push({ op: "replace", path: path || '/', value: obj });
changed = true;
}
}

Expand Down

0 comments on commit f7f5665

Please sign in to comment.