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

28 lines
712 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];
2017-02-28 10:46:18 +00:00
if (val instanceof Object) {
if (!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);