25 lines
696 B
JavaScript
25 lines
696 B
JavaScript
import isEqual from './equals';
|
|
|
|
export default function getModifiedData(object, objectOld) {
|
|
var newObject = {};
|
|
if (objectOld === null)
|
|
return object;
|
|
|
|
for (var k in object) {
|
|
var val = object[k];
|
|
var 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;
|
|
}
|