mirror of
https://github.com/fleetdm/fleet
synced 2026-05-19 06:58:30 +00:00
* clean up routes and useless components * component clean up * removed redux from routes * rename file * moved useDeepEffect hook with others * removed redux, fleet, app_constants dirs; added types to utilities * style cleanup * typo fix * removed unused ts-ignore comments * removed redux packages!!! * formatting * fixed typing for simple search function * updated frontend readme
31 lines
771 B
TypeScript
31 lines
771 B
TypeScript
import { differenceWith, isArray, isEqual, isObject, map } from "lodash";
|
|
|
|
const deepDifference = (obj1: any, obj2: any) => {
|
|
const result: any = {};
|
|
|
|
map(obj1, (value, key) => {
|
|
const obj2Value = obj2[key];
|
|
|
|
if (isEqual(value, obj2Value)) return;
|
|
|
|
if (isArray(value) && isArray(obj2Value)) {
|
|
if (!value.length && obj2Value.length) {
|
|
result[key] = value;
|
|
} else {
|
|
const arrayDiff = differenceWith(value, obj2Value, isEqual);
|
|
|
|
if (arrayDiff.length) {
|
|
result[key] = arrayDiff;
|
|
}
|
|
}
|
|
} else if (isObject(value) && isObject(obj2Value)) {
|
|
result[key] = deepDifference(value, obj2Value);
|
|
} else {
|
|
result[key] = value;
|
|
}
|
|
});
|
|
|
|
return result;
|
|
};
|
|
|
|
export default deepDifference;
|