Skip to content

Commit

Permalink
add more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispader committed Mar 25, 2024
1 parent c1d3e21 commit 4a379dc
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ function isMergeableObject(value: unknown): value is Record<string, unknown> {
function mergeObject<TObject extends Record<string, unknown>>(target: TObject | null, source: TObject, shouldRemoveNullObjectValues = true): TObject {
const destination: Record<string, unknown> = {};

// First we want to copy over all keys from the target into the destination object,
// in case "target" is a mergable object.
// If "shouldRemoveNullObjectValues" is true, we want to remove null values from the merged object
// and therefore we need to omit keys where either the source or target value is null.
if (isMergeableObject(target)) {
const targetKeys = Object.keys(target);
for (let i = 0; i < targetKeys.length; ++i) {
Expand All @@ -48,6 +52,7 @@ function mergeObject<TObject extends Record<string, unknown>>(target: TObject |
}
}

// After copying over all keys from the target object, we want to merge the source object into the destination object.
const sourceKeys = Object.keys(source);
for (let i = 0; i < sourceKeys.length; ++i) {
const key = sourceKeys[i];
Expand Down

0 comments on commit 4a379dc

Please sign in to comment.