Skip to content

Commit

Permalink
perf(signals): avoid creating unnecessary objects in excludeKeys (#4240)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomasz Ducin <tomasz@ducin.it>
  • Loading branch information
ducin and Tomasz Ducin authored Feb 12, 2024
1 parent 1975af6 commit b90da9d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions modules/signals/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ export function excludeKeys<
Obj extends Record<string, unknown>,
Keys extends string[]
>(obj: Obj, keys: Keys): Omit<Obj, Keys[number]> {
return Object.keys(obj).reduce(
(acc, key) => (keys.includes(key) ? acc : { ...acc, [key]: obj[key] }),
{}
) as Omit<Obj, Keys[number]>;
return Object.keys(obj).reduce<Record<string, unknown>>((acc, key) => {
if (!keys.includes(key)) {
acc[key] = obj[key];
}
return acc;
}, {}) as Omit<Obj, Keys[number]>;
}

0 comments on commit b90da9d

Please sign in to comment.