salix/front/core/lib/modified.js

25 lines
696 B
JavaScript
Raw Normal View History

import isEqual from './equals';
export default function getModifiedData(object, objectOld) {
var newObject = {};
2018-09-24 08:43:54 +00:00
if (objectOld === null)
2018-02-01 12:28:45 +00:00
return object;
2018-09-24 08:43:54 +00:00
for (var k in object) {
var val = object[k];
2017-10-04 08:54:29 +00:00
var valOld = objectOld[k] === undefined ? null : objectOld[k];
if (!isEqual(val, valOld)) {
2018-09-24 08:43:54 +00:00
if (val instanceof Date) {
newObject[k] = new Date(val.getTime());
} else if (val instanceof Object) {
2017-02-28 10:46:18 +00:00
newObject[k] = getModifiedData(val, valOld);
2017-09-21 06:48:25 +00:00
} else {
newObject[k] = val;
}
}
}
2018-02-21 11:36:37 +00:00
return Object.keys(newObject).length ? newObject : undefined;
}