Skip to content

Commit a7b1667

Browse files
authored
refactor(router-core): remove pick utility in favor of direct object manipulation (#4983)
Based on the current usage of `pick`, directly addinf the picked keys to the objects will be less overhead with the same result. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - Refactor - Simplified internal routing logic related to navigation options; no change to runtime behavior. - Chores - Removed an internal utility no longer used. - Public API - One non-essential utility export was removed from package entry points, slightly reducing the public API surface. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 472cac4 commit a7b1667

File tree

5 files changed

+2
-16
lines changed

5 files changed

+2
-16
lines changed

packages/react-router/src/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export {
2525
parseSearchWith,
2626
stringifySearchWith,
2727
escapeJSON, // SSR
28-
pick,
2928
functionalUpdate,
3029
replaceEqualDeep,
3130
isPlainObject,

packages/router-core/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ export type { OptionalStructuralSharing } from './structuralSharing'
269269
export {
270270
last,
271271
functionalUpdate,
272-
pick,
273272
replaceEqualDeep,
274273
isPlainObject,
275274
isPlainArray,

packages/router-core/src/router.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
findLast,
1212
functionalUpdate,
1313
last,
14-
pick,
1514
replaceEqualDeep,
1615
} from './utils'
1716
import {
@@ -1617,7 +1616,7 @@ export class RouterCore<
16171616
if (foundMask) {
16181617
const { from: _from, ...maskProps } = foundMask
16191618
maskedDest = {
1620-
...pick(opts, ['from']),
1619+
from: opts.from,
16211620
...maskProps,
16221621
params,
16231622
}
@@ -1635,7 +1634,7 @@ export class RouterCore<
16351634

16361635
if (opts.mask) {
16371636
return buildWithMatches(opts, {
1638-
...pick(opts, ['from']),
1637+
from: opts.from,
16391638
...opts.mask,
16401639
})
16411640
}

packages/router-core/src/utils.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,6 @@ export function functionalUpdate<TPrevious, TResult = TPrevious>(
203203
return updater
204204
}
205205

206-
export function pick<TValue, TKey extends keyof TValue>(
207-
parent: TValue,
208-
keys: Array<TKey>,
209-
): Pick<TValue, TKey> {
210-
return keys.reduce((obj: any, key: TKey) => {
211-
obj[key] = parent[key]
212-
return obj
213-
}, {} as any)
214-
}
215-
216206
/**
217207
* This function returns `prev` if `_next` is deeply equal.
218208
* If not, it will replace any deeply equal children of `b` with those of `a`.

packages/solid-router/src/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export {
2525
parseSearchWith,
2626
stringifySearchWith,
2727
escapeJSON, // SSR
28-
pick,
2928
functionalUpdate,
3029
replaceEqualDeep,
3130
isPlainObject,

0 commit comments

Comments
 (0)