Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
michalczaplinski committed Oct 17, 2024
1 parent 7aa3db9 commit 71b2a14
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/interactivity/src/proxies/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ const deepMergeRecursive = (
source: any,
override: boolean = true
) => {
// Only merge if both target and source are plain objects
// If target is not a plain object and the source is, we don't need to merge
// them because the source will be used as the new value of the target.
if ( ! ( isPlainObject( target ) && isPlainObject( source ) ) ) {
return;
}
Expand All @@ -324,7 +325,8 @@ const deepMergeRecursive = (
typeof desc.set === 'function'
) {
if ( override || isNew ) {
// Define the property on the target object
// Because we are setting a getter or setter, we need to use
// Object.defineProperty to define the property on the target object.
Object.defineProperty( target, key, {
...desc,
configurable: true,
Expand All @@ -349,8 +351,8 @@ const deepMergeRecursive = (
);
}
}
// Both target and source are plain objects, merge them recursively
if ( isPlainObject( target[ key ] ) ) {
// Recursively merge nested objects
deepMergeRecursive( target[ key ], source[ key ], override );
}

Expand All @@ -368,7 +370,6 @@ const deepMergeRecursive = (
}
}

// Update the iterable version if new keys were added
if ( hasNewKeys && objToIterable.has( target ) ) {
objToIterable.get( target )!.value++;
}
Expand Down

0 comments on commit 71b2a14

Please sign in to comment.