Undocumented modification of oldValue when calling applyDiff
wweaver opened this issue · 1 comments
wweaver commented
It seems that when there are nested objects the original value is modified when calling applyDiff
import { applyDiff, getDiff } from 'recursive-diff';
const origVal = { foo: { a: 1, b: 2, c: 3 } };
const newVal = { foo: { a: 11, b: 22, d: 44 } };
const delta = getDiff(origVal, newVal);
console.log('before', { origVal, newVal });
/* --- output
before {
origVal: { foo: { a: 1, b: 2, c: 3 } },
newVal: { foo: { a: 11, b: 22, d: 44 } }
}
*/
const finalVal = applyDiff(origVal, delta);
console.log('after', { origVal, newVal, finalVal });
/* --- output
after {
origVal: { foo: { a: 11, b: 22, d: 44 } },
newVal: { foo: { a: 11, b: 22, d: 44 } },
finalVal: { foo: { a: 11, b: 22, d: 44 } }
}
*/
cosmicanant commented
this is by design itself. Updated the readme file to explain this behavior.