batching events

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-07-17 17:13:07 +02:00
committed by Carl-Gerhard Lindesvärd
parent 244aa3b0d3
commit 5e225b7ae6
58 changed files with 2204 additions and 583 deletions

View File

@@ -13,9 +13,14 @@ export function toDots(
};
}
if (value === undefined || value === null) {
return acc;
}
return {
...acc,
[`${path}${key}`]: typeof value === 'string' ? value.trim() : value,
[`${path}${key}`]:
typeof value === 'string' ? value.trim() : String(value),
};
}, {});
}
@@ -52,3 +57,46 @@ export function getSuperJson<T>(str: string): T | null {
}
return json;
}
type AnyObject = Record<string, any>;
export function deepMergeObjects<T>(target: AnyObject, source: AnyObject): T {
const merged: AnyObject = {};
// Include all keys from both objects
const allKeys = new Set([...Object.keys(target), ...Object.keys(source)]);
allKeys.forEach((key) => {
const targetValue = target[key];
const sourceValue = source[key];
if (
(isNil(sourceValue) && !isNil(targetValue)) ||
(sourceValue === '' &&
typeof targetValue === 'string' &&
targetValue !== '')
) {
// Keep target value if source value is null or undefined
merged[key] = targetValue;
} else if (
sourceValue !== undefined &&
isObject(targetValue) &&
isObject(sourceValue)
) {
// Recursively merge objects
merged[key] = deepMergeObjects(targetValue, sourceValue);
} else if (sourceValue !== undefined) {
// Directly assign any non-undefined source values
merged[key] = sourceValue;
} else if (sourceValue === undefined && target[key] !== undefined) {
// Keep target value if source value is undefined
merged[key] = targetValue;
}
});
return merged as T;
}
// Helper function to check if a value is an object (but not null or an array)
function isObject(value: any): boolean {
return value !== null && typeof value === 'object' && !Array.isArray(value);
}