Skip to content

Commit dafad2a

Browse files
authored
refactor(router-core): router uses .some() over .find() for boolean results (#4829)
This change is a no-op, even in terms of performance. But it's more of an "anti-slippery-slope" measure, so we don't end up with array copying methods like `.map` or `.filter` being used instead of simpler methods like `.find` or `.some`
1 parent 106e030 commit dafad2a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

packages/router-core/src/router.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,7 @@ export class RouterCore<
18481848
pendingMatches,
18491849
// If a cached moved to pendingMatches, remove it from cachedMatches
18501850
cachedMatches: s.cachedMatches.filter(
1851-
(d) => !pendingMatches.find((e) => e.id === d.id),
1851+
(d) => !pendingMatches.some((e) => e.id === d.id),
18521852
),
18531853
}))
18541854
}
@@ -1906,14 +1906,14 @@ export class RouterCore<
19061906
const newMatches = s.pendingMatches || s.matches
19071907

19081908
exitingMatches = previousMatches.filter(
1909-
(match) => !newMatches.find((d) => d.id === match.id),
1909+
(match) => !newMatches.some((d) => d.id === match.id),
19101910
)
19111911
enteringMatches = newMatches.filter(
19121912
(match) =>
1913-
!previousMatches.find((d) => d.id === match.id),
1913+
!previousMatches.some((d) => d.id === match.id),
19141914
)
19151915
stayingMatches = previousMatches.filter((match) =>
1916-
newMatches.find((d) => d.id === match.id),
1916+
newMatches.some((d) => d.id === match.id),
19171917
)
19181918

19191919
return {
@@ -2107,12 +2107,12 @@ export class RouterCore<
21072107
}
21082108

21092109
const resolvePreload = (matchId: string) => {
2110-
return !!(allPreload && !this.state.matches.find((d) => d.id === matchId))
2110+
return !!(allPreload && !this.state.matches.some((d) => d.id === matchId))
21112111
}
21122112

21132113
// make sure the pending component is immediately rendered when hydrating a match that is not SSRed
21142114
// the pending component was already rendered on the server and we want to keep it shown on the client until minPendingMs is reached
2115-
if (!this.isServer && this.state.matches.find((d) => d._forcePending)) {
2115+
if (!this.isServer && this.state.matches.some((d) => d._forcePending)) {
21162116
triggerOnReady()
21172117
}
21182118

@@ -2590,7 +2590,7 @@ export class RouterCore<
25902590
loaderPromise: createControlledPromise<void>(),
25912591
preload:
25922592
!!preload &&
2593-
!this.state.matches.find((d) => d.id === matchId),
2593+
!this.state.matches.some((d) => d.id === matchId),
25942594
}))
25952595

25962596
const runLoader = async () => {

0 commit comments

Comments
 (0)