Skip to content

Commit 37c5f3c

Browse files
authoredSep 6, 2023
chore(router): update generic names (#10845)
1 parent 9b1d184 commit 37c5f3c

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed
 

‎.changeset/gold-ghosts-draw.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@remix-run/router": patch
3+
---
4+
5+
[REMOVE] Use long generic names

‎packages/router/history.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ export interface Path {
5656
* An entry in a history stack. A location contains information about the
5757
* URL path, as well as possibly some arbitrary state and a key.
5858
*/
59-
export interface Location<S = any> extends Path {
59+
export interface Location<State = any> extends Path {
6060
/**
6161
* A value of arbitrary data associated with this location.
6262
*/
63-
state: S;
63+
state: State;
6464

6565
/**
6666
* A unique string associated with this location. May be used to safely store
@@ -100,8 +100,8 @@ export interface Listener {
100100

101101
/**
102102
* Describes a location that is the destination of some navigation, either via
103-
* `history.push` or `history.replace`. May be either a URL or the pieces of a
104-
* URL path.
103+
* `history.push` or `history.replace`. This may be either a URL or the pieces
104+
* of a URL path.
105105
*/
106106
export type To = string | Partial<Path>;
107107

@@ -503,7 +503,7 @@ export function warning(cond: any, message: string) {
503503
try {
504504
// Welcome to debugging history!
505505
//
506-
// This error is thrown as a convenience so you can more easily
506+
// This error is thrown as a convenience, so you can more easily
507507
// find the source for a warning that appears in the console by
508508
// enabling "pause on exceptions" in your JavaScript debugger.
509509
throw new Error(message);

‎packages/router/utils.ts

+24-17
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,19 @@ interface DataFunctionArgs<Context> {
145145

146146
// TODO: (v7) Change the defaults from any to unknown in and remove Remix wrappers:
147147
// ActionFunction, ActionFunctionArgs, LoaderFunction, LoaderFunctionArgs
148+
// Also, make them a type alias instead of an interface
148149

149150
/**
150151
* Arguments passed to loader functions
151152
*/
152-
export interface LoaderFunctionArgs<C = any> extends DataFunctionArgs<C> {}
153+
export interface LoaderFunctionArgs<Context = any>
154+
extends DataFunctionArgs<Context> {}
153155

154156
/**
155157
* Arguments passed to action functions
156158
*/
157-
export interface ActionFunctionArgs<C = any> extends DataFunctionArgs<C> {}
159+
export interface ActionFunctionArgs<Context = any>
160+
extends DataFunctionArgs<Context> {}
158161

159162
/**
160163
* Loaders and actions can return anything except `undefined` (`null` is a
@@ -166,15 +169,19 @@ type DataFunctionValue = Response | NonNullable<unknown> | null;
166169
/**
167170
* Route loader function signature
168171
*/
169-
export interface LoaderFunction<C = any> {
170-
(args: LoaderFunctionArgs<C>): Promise<DataFunctionValue> | DataFunctionValue;
172+
export interface LoaderFunction<Context = any> {
173+
(args: LoaderFunctionArgs<Context>):
174+
| Promise<DataFunctionValue>
175+
| DataFunctionValue;
171176
}
172177

173178
/**
174179
* Route action function signature
175180
*/
176-
export interface ActionFunction<C = any> {
177-
(args: ActionFunctionArgs<C>): Promise<DataFunctionValue> | DataFunctionValue;
181+
export interface ActionFunction<Context = any> {
182+
(args: ActionFunctionArgs<Context>):
183+
| Promise<DataFunctionValue>
184+
| DataFunctionValue;
178185
}
179186

180187
/**
@@ -353,10 +360,10 @@ type PathParam<Path extends string> =
353360
_PathParam<Path>;
354361

355362
// Attempt to parse the given string segment. If it fails, then just return the
356-
// plain string type as a default fallback. Otherwise return the union of the
363+
// plain string type as a default fallback. Otherwise, return the union of the
357364
// parsed string literals that were referenced as dynamic segments in the route.
358365
export type ParamParseKey<Segment extends string> =
359-
// if could not find path params, fallback to `string`
366+
// if you could not find path params, fallback to `string`
360367
[PathParam<Segment>] extends [never] ? string : PathParam<Segment>;
361368

362369
/**
@@ -400,7 +407,7 @@ function isIndexRoute(
400407
return route.index === true;
401408
}
402409

403-
// Walk the route tree generating unique IDs where necessary so we are working
410+
// Walk the route tree generating unique IDs where necessary, so we are working
404411
// solely with AgnosticDataRouteObject's within the Router
405412
export function convertRoutesToDataRoutes(
406413
routes: AgnosticRouteObject[],
@@ -493,12 +500,12 @@ export function matchRoutes<
493500
return matches;
494501
}
495502

496-
export interface UIMatch<D = unknown, H = unknown> {
503+
export interface UIMatch<Data = unknown, Handle = unknown> {
497504
id: string;
498505
pathname: string;
499506
params: AgnosticRouteMatch["params"];
500-
data: D;
501-
handle: H;
507+
data: Data;
508+
handle: Handle;
502509
}
503510

504511
export function convertRouteMatchToUiMatch(
@@ -567,7 +574,7 @@ function flattenRoutes<
567574
let path = joinPaths([parentPath, meta.relativePath]);
568575
let routesMeta = parentsMeta.concat(meta);
569576

570-
// Add the children before adding this route to the array so we traverse the
577+
// Add the children before adding this route to the array, so we traverse the
571578
// route tree depth-first and child routes appear before their parents in
572579
// the "flattened" version.
573580
if (route.children && route.children.length > 0) {
@@ -644,10 +651,10 @@ function explodeOptionalSegments(path: string): string[] {
644651
let result: string[] = [];
645652

646653
// All child paths with the prefix. Do this for all children before the
647-
// optional version for all children so we get consistent ordering where the
654+
// optional version for all children, so we get consistent ordering where the
648655
// parent optional aspect is preferred as required. Otherwise, we can get
649656
// child sections interspersed where deeper optional segments are higher than
650-
// parent optional segments, where for example, /:two would explodes _earlier_
657+
// parent optional segments, where for example, /:two would explode _earlier_
651658
// then /:one. By always including the parent as required _for all children_
652659
// first, we avoid this issue
653660
result.push(
@@ -656,7 +663,7 @@ function explodeOptionalSegments(path: string): string[] {
656663
)
657664
);
658665

659-
// Then if this is an optional value, add all child versions without
666+
// Then, if this is an optional value, add all child versions without
660667
if (isOptional) {
661668
result.push(...restExploded);
662669
}
@@ -972,7 +979,7 @@ function compilePath(
972979
regexpSource += "\\/*$";
973980
} else if (path !== "" && path !== "/") {
974981
// If our path is non-empty and contains anything beyond an initial slash,
975-
// then we have _some_ form of path in our regex so we should expect to
982+
// then we have _some_ form of path in our regex, so we should expect to
976983
// match only if we find the end of this path segment. Look for an optional
977984
// non-captured trailing slash (to match a portion of the URL) or the end
978985
// of the path (if we've matched to the end). We used to do this with a

0 commit comments

Comments
 (0)
Please sign in to comment.