Skip to content

Commit

Permalink
refactor: remove redundant function wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
exuanbo committed Dec 10, 2023
1 parent 3d8cf65 commit 4035e47
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/app/store/persistence/combinedProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const getCombinedProvider =
getQueryParamProvider(validate, fallback),
]
return {
read: () => providers.map((provider) => provider.read()).reduce((a, b) => combine(a, b)),
read: () => providers.map((provider) => provider.read()).reduce(combine),
write: (state) => providers.forEach((provider) => provider.write(state)),
}
}
9 changes: 5 additions & 4 deletions src/common/utils/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ type ExpandDeep<T> = T extends Record<string | number | symbol, unknown>
? Array<ExpandDeep<E>>
: T

export const merge = <Target extends PlainObject, Sources extends PlainObject[]>(
type Merge = <Target extends PlainObject, Sources extends PlainObject[]>(
target: Target,
...sources: Sources
): ExpandDeep<O.Assign<Target, Sources, 'deep'>> =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
sources.reduce<any>((resultObject, source) => mergeRecursively(resultObject, source), target)
) => ExpandDeep<O.Assign<Target, Sources, 'deep'>>

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const merge: Merge = (target, ...sources) => sources.reduce<any>(mergeRecursively, target)

0 comments on commit 4035e47

Please sign in to comment.