salix/client/core/src/modified.js

26 lines
677 B
JavaScript
Raw Normal View History

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);