2017-02-06 17:01:04 +00:00
|
|
|
import isEqual from './equals';
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2017-02-06 17:01:04 +00:00
|
|
|
export default function getModifiedData(object, objectOld) {
|
2019-11-01 12:02:47 +00:00
|
|
|
let 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
|
|
|
|
2019-11-01 12:02:47 +00:00
|
|
|
for (let k in object) {
|
|
|
|
let val = object[k];
|
|
|
|
let valOld = objectOld[k] === undefined ? null : objectOld[k];
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2017-02-28 11:07:16 +00:00
|
|
|
if (!isEqual(val, valOld)) {
|
2019-11-01 12:02:47 +00:00
|
|
|
if (val instanceof Date)
|
2018-09-24 08:43:54 +00:00
|
|
|
newObject[k] = new Date(val.getTime());
|
2019-11-01 12:02:47 +00:00
|
|
|
else if (val instanceof Object)
|
2017-02-28 10:46:18 +00:00
|
|
|
newObject[k] = getModifiedData(val, valOld);
|
2019-11-01 12:02:47 +00:00
|
|
|
else
|
2017-02-28 11:07:16 +00:00
|
|
|
newObject[k] = val;
|
2017-01-31 13:13:06 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-06 17:01:04 +00:00
|
|
|
|
2018-02-21 11:36:37 +00:00
|
|
|
return Object.keys(newObject).length ? newObject : undefined;
|
2017-01-31 13:13:06 +00:00
|
|
|
}
|