2017-01-31 13:13:06 +00:00
|
|
|
import {module} from './module';
|
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) {
|
|
|
|
var newObject = {};
|
|
|
|
for (var k in object) {
|
|
|
|
var val = object[k];
|
|
|
|
var valOld = objectOld[k];
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2017-02-06 17:01:04 +00:00
|
|
|
if (val instanceof Object && !isEqual(val, valOld)) {
|
|
|
|
newObject[k] = getModifiedData(val, valOld);
|
2017-01-31 13:13:06 +00:00
|
|
|
}
|
2017-02-06 17:01:04 +00:00
|
|
|
else if (val instanceof Array && val.length !== valOld.length) {
|
|
|
|
newObject[k] = val;
|
|
|
|
}
|
|
|
|
else if (val !== valOld) {
|
|
|
|
newObject[k] = val;
|
|
|
|
}
|
2017-01-31 13:13:06 +00:00
|
|
|
}
|
2017-02-06 17:01:04 +00:00
|
|
|
|
|
|
|
return newObject;
|
2017-01-31 13:13:06 +00:00
|
|
|
}
|
2017-02-06 17:01:04 +00:00
|
|
|
|
|
|
|
export const NAME = 'getDataModified';
|
|
|
|
module.value(NAME, getModifiedData);
|