24 lines
672 B
JavaScript
24 lines
672 B
JavaScript
import isEqual from './equals';
|
|
|
|
export default function getModifiedData(object, objectOld) {
|
|
let newObject = {};
|
|
if (objectOld === null)
|
|
return object;
|
|
|
|
for (let k in object) {
|
|
let val = object[k];
|
|
let valOld = objectOld[k] === undefined ? null : objectOld[k];
|
|
|
|
if (!isEqual(val, valOld)) {
|
|
if (val instanceof Date)
|
|
newObject[k] = new Date(val.getTime());
|
|
else if (val instanceof Object)
|
|
newObject[k] = getModifiedData(val, valOld);
|
|
else
|
|
newObject[k] = val;
|
|
}
|
|
}
|
|
|
|
return Object.keys(newObject).length ? newObject : undefined;
|
|
}
|