recursive-diff
recursive-diff copied to clipboard
applyDiff doesn't work for arrays in objects
initial = { array: [1, 2, 3] };
final = { array: [1, 2, 4] };
const diff: ANY_OBJECT = {};
const diffPath = rdiff.getDiff(initial, final);
rdiff.applyDiff(diff, diffPath);
throwing error on rdiff.applyDiff(diff, diffPath);-
Invalid path: "array,2" for object: {}
Hi i think you are using apply diff wrong. The documentation says: applyDiff will apply the diff on the oldVal and update it as per the diff object.
So the a correct usage would be:
initial = { array: [1, 2, 3] };
final = { array: [1, 2, 4] };
const diff = rdiff.getDiff(initial, final);
rdiff.applyDiff(inital, diff);
After that, inital is deeply equal to final. I am not sure why you are creating a new empty obiect. Maybe you are trying something different? In that case, some more information, about what you are trying to achieve would be nice.