Why not carry the "old value" when the operation "update" occur?
Closed this issue · 4 comments
Hi, I think that would be helpful put in the rdiffResult object a property like "oldValue" when the operation is update.
make sense, will do!
@mcvtec hey, I am wondering how do you plan to use the oldVal
! Would you mind share your usecase?
@cosmicanant of course! I am using the package to track changes occurred in the data, so I compare the new data to the old one and I make messages logs for each property that changes like "Field 'name' changed from 'name example' to 'name ex' ". So to help I made a simple function to get the old data given the path returned in rdiffResult.
function getOldVal(oldObj: any, path: (number | string)[]) {
let oldVal: any;
path.forEach(keyVal=>{
if (!oldVal) {
oldVal = (oldObj as any)[keyVal]
} else {
oldVal = oldVal[keyVal]
}
});
return oldVal
}
ok, oldValue can be retrieved in the diff object by using an optional parameter to getDiff
function. see the note section of getDiff
API: https://github.com/cosmicanant/recursive-diff#api-details. A new version has been published for the same.