Skip to content

Commit

Permalink
RFE angus-c#520 purposal (keep oldValue in diff)
Browse files Browse the repository at this point in the history
  • Loading branch information
ftab committed Dec 5, 2022
1 parent 3c9d3fb commit 6b0d905
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions packages/collection-diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ function diff(obj1, obj2, pathConverter) {
Object(obj1AtKey) !== obj1AtKey ||
Object(obj2AtKey) !== obj2AtKey
) {
path = pushReplace(path, basePath, key, diffs, pathConverter, obj2);
path = pushReplace(path, basePath, key, diffs, pathConverter, obj2, obj1);
} else {
if (
!Object.keys(obj1AtKey).length &&
!Object.keys(obj2AtKey).length &&
String(obj1AtKey) != String(obj2AtKey)
) {
path = pushReplace(path, basePath, key, diffs, pathConverter, obj2);
path = pushReplace(path, basePath, key, diffs, pathConverter, obj2, obj1);
} else {
getDiff(obj1[key], obj2[key], basePath.concat(key), diffs);
}
Expand All @@ -138,11 +138,12 @@ function diff(obj1, obj2, pathConverter) {
.concat(finalDiffs.add);
}

function pushReplace(path, basePath, key, diffs, pathConverter, obj2) {
function pushReplace(path, basePath, key, diffs, pathConverter, obj2, obj1) {
path = basePath.concat(key);
diffs.replace.push({
op: 'replace',
path: pathConverter(path),
oldValue: obj1[key],
value: obj2[key],
});
return path;
Expand Down
7 changes: 4 additions & 3 deletions packages/collection-diff/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ function diff(obj1, obj2, pathConverter) {
Object(obj1AtKey) !== obj1AtKey ||
Object(obj2AtKey) !== obj2AtKey
) {
path = pushReplace(path, basePath, key, diffs, pathConverter, obj2);
path = pushReplace(path, basePath, key, diffs, pathConverter, obj2, obj1);
} else {
if (
!Object.keys(obj1AtKey).length &&
!Object.keys(obj2AtKey).length &&
String(obj1AtKey) != String(obj2AtKey)
) {
path = pushReplace(path, basePath, key, diffs, pathConverter, obj2);
path = pushReplace(path, basePath, key, diffs, pathConverter, obj2, obj1);
} else {
getDiff(obj1[key], obj2[key], basePath.concat(key), diffs);
}
Expand All @@ -133,11 +133,12 @@ function diff(obj1, obj2, pathConverter) {
.concat(finalDiffs.add);
}

function pushReplace(path, basePath, key, diffs, pathConverter, obj2) {
function pushReplace(path, basePath, key, diffs, pathConverter, obj2, obj1) {
path = basePath.concat(key);
diffs.replace.push({
op: 'replace',
path: pathConverter(path),
oldValue: obj1[key],
value: obj2[key],
});
return path;
Expand Down

0 comments on commit 6b0d905

Please sign in to comment.