1
+ package react .router ;
2
+
3
+ import haxe .extern .EitherType ;
4
+ import haxe .Constraints ;
5
+ import react .ReactComponent ;
6
+
7
+ typedef HashHistory = Router ;
8
+ typedef BrowserHistory = Router ;
9
+ typedef RoutePropsOfParams <P > = RoutePropsOf <P , Dynamic >;
10
+ typedef RoutePropsOfQuery <Q > = RoutePropsOf <Dynamic , Q >;
11
+
12
+ typedef RoutePropsOf <P , Q > = {
13
+ params : P ,
14
+ location : {
15
+ query : Q ,
16
+ }
17
+ }
18
+
19
+ private typedef Object = Dynamic ;
20
+ @:enum
21
+ private abstract Action (String ) {
22
+ var Push = ' PUSH' ;
23
+ var Replace = ' REPLACE' ;
24
+ var Pop = ' POP' ;
25
+ }
26
+ private typedef Component = EitherType <Class <ReactComponent >, String >;
27
+ private typedef EnterHook = RouterState -> RedirectFunction -> ? Function -> Any ;
28
+ private typedef Hash = String ;
29
+ private typedef LeaveHook = RouterState -> Any ;
30
+ private typedef Location = {
31
+ pathname : Pathname ,
32
+ search : QueryString ,
33
+ query : Query ,
34
+ state : LocationState ,
35
+ action : Action ,
36
+ key : LocationKey ,
37
+ };
38
+ private typedef LocationDescriptorObject = {
39
+ pathname : Pathname ,
40
+ search : QueryString ,
41
+ query : Query ,
42
+ state : LocationState ,
43
+ };
44
+ private typedef LocationDescriptor = EitherType <LocationDescriptorObject , Path >;
45
+ private typedef LocationKey = String ;
46
+ private typedef LocationState = Object ;
47
+ private typedef Params = Object ;
48
+ private typedef Path = String ; // Pathname + QueryString + Hash;
49
+ private typedef Pathname = String ;
50
+ private typedef Query = Object ;
51
+ private typedef QueryString = String ;
52
+ private typedef RedirectFunction = ? LocationState -> EitherType <Pathname , Path >-> ? Query -> Void ;
53
+
54
+ private typedef Route = {
55
+ component : RouteComponent ,
56
+ ? path : RoutePattern ,
57
+ ? onEnter : EnterHook ,
58
+ ? onLeave : LeaveHook ,
59
+ }
60
+
61
+ private typedef RouteComponent = Component ;
62
+ private typedef RouteConfig = Array <Route >;
63
+ private typedef RouteHook = ? Location -> Any ;
64
+ private typedef RoutePattern = String ;
65
+ private typedef Router = {
66
+ push : LocationDescriptor -> Void ,
67
+ replace : LocationDescriptor -> Void ,
68
+ go : Int -> Void ,
69
+ goBack : Void -> Void ,
70
+ goForward : Void -> Void ,
71
+ setRouteLeaveHook : Route -> RouteHook -> Function ,
72
+ isActive : LocationDescriptor -> Bool -> Void ,
73
+ }
74
+ private typedef RouterState = {
75
+ location : Location ,
76
+ routes : Array <Route >,
77
+ params : Params ,
78
+ components : Array <Component >,
79
+ }
0 commit comments