Skip to content

Commit

Permalink
feat(deep-object-assign): add pure version (#383)
Browse files Browse the repository at this point in the history
I thought we mutate the items during updates in Data Sets but apparently
we don't, we clone them (I really should do some interoperability
testing before I open PRs). This is basically `deepObjectAssign({},
base, update)` but with proper typesafety and more clearly communicating
the intention of not modifying the arguments.
  • Loading branch information
Thomaash authored Jun 14, 2020
1 parent d1786bc commit c19d1f1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/deep-object-assign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ export type Assignable<T> = T extends undefined
? { [Key in keyof T]?: Assignable<T[Key]> | undefined }
: T | undefined;

/**
* Pure version of deepObjectAssign, it doesn't modify any of it's arguments.
*
* @param base - The base object that fullfils the whole interface T.
* @param updates - Updates that may change or delete props.
*
* @returns A brand new instance with all the supplied objects deeply merged.
*/
export function pureDeepObjectAssign<T>(
base: T,
...updates: Assignable<T>[]
): T {
return deepObjectAssign({} as any, base, ...updates);
}

/**
* Deep version of object assign with additional deleting by the DELETE symbol.
*
Expand Down

0 comments on commit c19d1f1

Please sign in to comment.