Skip to content

Commit

Permalink
chore: wip refactor
Browse files Browse the repository at this point in the history
The idea here was to reuse the experimental router within the actual
router. This turns out to be a lot of work without any security of
having something working and without breaking changes in the end. So I
think it's better to keep two versions of the createRouter function with
prefix `EXPERIMENTAL_`. In the end, one code base only uses one of the
function so it's fine to keep the code duplicated until v5. This branch
is here as a reminder of the failure.
  • Loading branch information
posva committed Jan 8, 2025
1 parent 794fdd5 commit 34c0c13
Show file tree
Hide file tree
Showing 3 changed files with 266 additions and 805 deletions.
1 change: 1 addition & 0 deletions packages/router/src/experimental/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ export interface EXPERIMENTAL_RouteRecordNormalized extends NEW_MatcherRecord {
* Arbitrary data attached to the record.
*/
meta: RouteMeta
parent?: EXPERIMENTAL_RouteRecordNormalized
}

function normalizeRouteRecord(
Expand Down
26 changes: 26 additions & 0 deletions packages/router/src/matcher/pathMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,32 @@ export interface RouteRecordMatcher extends PathParser {
alias: RouteRecordMatcher[]
}

export function NEW_createRouteRecordMatcher(
record: Readonly<RouteRecord>,
parent: RouteRecordMatcher | undefined,
options?: PathParserOptions
): RouteRecordMatcher {
const parser = tokensToParser(tokenizePath(record.path), options)

const matcher: RouteRecordMatcher = assign(parser, {
record,
parent,
// these needs to be populated by the parent
children: [],
alias: [],
})

if (parent) {
// both are aliases or both are not aliases
// we don't want to mix them because the order is used when
// passing originalRecord in Matcher.addRoute
if (!matcher.record.aliasOf === !parent.record.aliasOf)
parent.children.push(matcher)
}

return matcher
}

export function createRouteRecordMatcher(
record: Readonly<RouteRecord>,
parent: RouteRecordMatcher | undefined,
Expand Down
Loading

0 comments on commit 34c0c13

Please sign in to comment.