salix/client/core/src/lib/modified.js

26 lines
678 B
JavaScript
Raw Normal View History

2017-02-07 13:34:26 +00:00
import {module} from '../module';
import isEqual from './equals';
export default function getModifiedData(object, objectOld) {
var newObject = {};
for (var k in object) {
var val = object[k];
var valOld = objectOld[k];
if (val instanceof Object && !isEqual(val, valOld)) {
newObject[k] = getModifiedData(val, valOld);
}
else if (val instanceof Array && val.length !== valOld.length) {
newObject[k] = val;
}
else if (val !== valOld) {
newObject[k] = val;
}
}
return newObject;
}
export const NAME = 'getDataModified';
module.value(NAME, getModifiedData);