-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'v3' of https://github.com/molefrog/wouter.git
- Loading branch information
Showing
38 changed files
with
565 additions
and
612 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Foundation: useLocation and paths | ||
*/ | ||
|
||
export type Path = string; | ||
|
||
export type SearchString = string; | ||
|
||
// the base useLocation hook type. Any custom hook (including the | ||
// default one) should inherit from it. | ||
export type BaseLocationHook = ( | ||
...args: any[] | ||
) => [Path, (path: Path, ...args: any[]) => any]; | ||
|
||
export type BaseSearchHook = (...args: any[]) => SearchString; | ||
|
||
/* | ||
* Utility types that operate on hook | ||
*/ | ||
|
||
// Returns the type of the location tuple of the given hook. | ||
export type HookReturnValue<H extends BaseLocationHook> = ReturnType<H>; | ||
|
||
// Returns the type of the navigation options that hook's push function accepts. | ||
export type HookNavigationOptions<H extends BaseLocationHook> = | ||
HookReturnValue<H>[1] extends ( | ||
path: Path, | ||
options: infer R, | ||
...rest: any[] | ||
) => any | ||
? R extends { [k: string]: any } | ||
? R | ||
: {} | ||
: {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export function parse( | ||
route: string, | ||
loose?: boolean | ||
): { | ||
keys: string[]; | ||
pattern: RegExp; | ||
}; | ||
|
||
export function parse(route: RegExp): { | ||
keys: false; | ||
pattern: RegExp; | ||
}; | ||
|
||
export type RouteParams<T extends string> = | ||
T extends `${infer Prev}/*/${infer Rest}` | ||
? RouteParams<Prev> & { wild: string } & RouteParams<Rest> | ||
: T extends `${string}:${infer P}?/${infer Rest}` | ||
? { [K in P]?: string } & RouteParams<Rest> | ||
: T extends `${string}:${infer P}/${infer Rest}` | ||
? { [K in P]: string } & RouteParams<Rest> | ||
: T extends `${string}:${infer P}?` | ||
? { [K in P]?: string } | ||
: T extends `${string}:${infer P}` | ||
? { [K in P]: string } | ||
: T extends `${string}*` | ||
? { wild: string } | ||
: T extends `${string}*?` | ||
? { wild?: string } | ||
: {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,31 @@ | ||
import { Path, BaseLocationHook } from "./use-browser-location"; | ||
import { | ||
Path, | ||
SearchString, | ||
BaseLocationHook, | ||
BaseSearchHook, | ||
} from "./location-hook"; | ||
|
||
export type Parser = (route: Path) => { pattern: RegExp; keys: string[] }; | ||
|
||
// the object returned from `useRouter` | ||
export interface RouterObject { | ||
readonly hook: BaseLocationHook; | ||
readonly searchHook: BaseSearchHook; | ||
readonly base: Path; | ||
readonly ownBase: Path; | ||
readonly parser: Parser; | ||
readonly parent?: RouterObject; | ||
readonly ssrPath?: Path; | ||
readonly ssrSearch?: SearchString; | ||
} | ||
|
||
// basic options to construct a router | ||
export type RouterOptions = { | ||
hook?: BaseLocationHook; | ||
searchHook?: BaseSearchHook; | ||
base?: Path; | ||
parser?: Parser; | ||
parent?: RouterObject; | ||
ssrPath?: Path; | ||
ssrSearch?: SearchString; | ||
}; |
Oops, something went wrong.