Skip to content

Commit 3eead95

Browse files
Sherafftannerlinsley
authored andcommitted
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 5318678 commit 3eead95

File tree

5 files changed

+4
-14
lines changed

5 files changed

+4
-14
lines changed

packages/react-router/src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export {
2222
parseSearchWith,
2323
stringifySearchWith,
2424
pick,
25+
escapeJSON, // SSR
2526
functionalUpdate,
2627
replaceEqualDeep,
2728
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 {
@@ -1626,7 +1625,7 @@ export class RouterCore<
16261625
if (foundMask) {
16271626
const { from: _from, ...maskProps } = foundMask
16281627
maskedDest = {
1629-
...pick(opts, ['from']),
1628+
from: opts.from,
16301629
...maskProps,
16311630
params,
16321631
}
@@ -1644,7 +1643,7 @@ export class RouterCore<
16441643

16451644
if (opts.mask) {
16461645
return buildWithMatches(opts, {
1647-
...pick(opts, ['from']),
1646+
from: opts.from,
16481647
...opts.mask,
16491648
})
16501649
}

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export {
2222
parseSearchWith,
2323
stringifySearchWith,
2424
pick,
25+
escapeJSON, // SSR
2526
functionalUpdate,
2627
replaceEqualDeep,
2728
isPlainObject,

0 commit comments

Comments
 (0)