-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.d.ts
41 lines (33 loc) · 973 Bytes
/
index.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
import { StoreonModule } from "storeon";
/**
* Router key on store
*/
export const routerKey: unique symbol;
/**
* Event changes a path
*/
export const routerChanged: unique symbol;
/**
* Navigate event
*/
export const routerNavigate: unique symbol;
export type RouterRecordState<MatchParameters> = {
match: MatchParameters | false;
path: string;
params: string[];
};
export type RouterState<MatchParameters> = {
[routerKey]: RouterRecordState<MatchParameters>;
};
export type RouterEvents<MatchParameters> = {
[routerChanged]: RouterRecordState<MatchParameters>;
[routerNavigate]: string;
};
export type Path = string | RegExp;
export type Callback<MatchParameters> = (
...properties: string[]
) => MatchParameters;
export type Route<MatchParameter> = [Path, Callback<MatchParameter>];
export function createRouter<MatchParameter>(
routes: Route<MatchParameter>[],
): StoreonModule<RouterState<MatchParameter>, RouterEvents<MatchParameter>>;