forked from featurist/hyperdom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.d.ts
80 lines (52 loc) · 1.54 KB
/
router.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import {VdomFragment, Binding, App} from "index"
// TODO: what else is there?
export interface RouteDefinition {
definition: {
pattern: string,
}
}
export type NotFound = object
export interface Router {
push (url: string): void
reset (): void
route (path: string): RouteHandler
url (): string
notFound (handler: (url: string, routesTried: RouteDefinition[]) => string): NotFound
}
export interface RouteHistory {
push (url: string): void
url (): string
}
export interface ParamsToPushMap {
[param: string]: boolean
}
export type ParamsToPushFn = (oldParams: object, newParams: object) => boolean
export type ParamsToPush = ParamsToPushMap | ParamsToPushFn
export interface ParamsBindings {
[param: string]: Binding
}
export interface RoutableComponent {
bindings?: ParamsBindings
push?: ParamsToPush
redirect? (params: object): string | undefined
render? (): VdomFragment | App | string // TODO add `render() => string` test to hyperdomSpec
// TODO: Promise<void> ?
onload? (params: object): void
}
export interface RouteHandler {
(component: RoutableComponent): Route
isActive (params?: object): boolean
push (options?: object): void
url (params: object): string
href (): string
replace (): void
}
export interface Routes {
[route: string]: RouteHandler
}
export type Route = object
export function reset (): void
export function route (path: string): RouteHandler
export function router (options: object): Router
export function hash (): RouteHistory
export function pushState (): RouteHistory