mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 15:15:44 -03:00
feat: Enhance deepMerge function to only update existing keys in target for improved merging logic
This commit is contained in:
@@ -779,27 +779,37 @@ export class VirtualScroller {
|
|||||||
console.log('Virtual scroller enabled');
|
console.log('Virtual scroller enabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function for deep merging objects
|
// Helper function for deep merging objects - only updates existing keys in target
|
||||||
deepMerge(target, source) {
|
deepMerge(target, source) {
|
||||||
if (!source) return target;
|
if (!source || !target) return target;
|
||||||
|
|
||||||
const result = { ...target };
|
const result = { ...target };
|
||||||
|
|
||||||
Object.keys(source).forEach(key => {
|
// Only iterate over keys that exist in target
|
||||||
if (source[key] !== null && typeof source[key] === 'object' && !Array.isArray(source[key])) {
|
Object.keys(target).forEach(key => {
|
||||||
// If property exists in target and is an object, recursively merge
|
// Check if source has this key
|
||||||
if (target[key] && typeof target[key] === 'object' && !Array.isArray(target[key])) {
|
if (source.hasOwnProperty(key)) {
|
||||||
result[key] = this.deepMerge(target[key], source[key]);
|
const targetValue = target[key];
|
||||||
|
const sourceValue = source[key];
|
||||||
|
|
||||||
|
// If both values are non-null objects and not arrays, merge recursively
|
||||||
|
if (
|
||||||
|
targetValue !== null &&
|
||||||
|
typeof targetValue === 'object' &&
|
||||||
|
!Array.isArray(targetValue) &&
|
||||||
|
sourceValue !== null &&
|
||||||
|
typeof sourceValue === 'object' &&
|
||||||
|
!Array.isArray(sourceValue)
|
||||||
|
) {
|
||||||
|
result[key] = this.deepMerge(targetValue, sourceValue);
|
||||||
} else {
|
} else {
|
||||||
// Otherwise just assign the source value
|
// For primitive types, arrays, or null, use the value from source
|
||||||
result[key] = source[key];
|
result[key] = sourceValue;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// For non-objects (including arrays), just assign the value
|
|
||||||
result[key] = source[key];
|
|
||||||
}
|
}
|
||||||
|
// If source does not have this key, keep the original value from target
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user