Skip to content

Commit 7c1b9f1

Browse files
authored
Merge pull request #95 from timsun28/master
Flow-Router Extra Typescript types
2 parents 955b127 + d91109d commit 7c1b9f1

File tree

3 files changed

+134
-3
lines changed

3 files changed

+134
-3
lines changed

package-types.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"typesEntry": "types.d.ts"
3+
}

package.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ Package.describe({
77

88
Package.onUse((api) => {
99
api.versionsFrom('1.4');
10-
api.use(['modules', 'ecmascript', 'promise', 'tracker', 'reactive-dict', 'reactive-var', 'ejson', 'check'], ['client', 'server']);
10+
api.use(['modules', 'ecmascript', 'promise', 'tracker', 'reactive-dict', 'reactive-var', 'ejson', 'check', 'zodern:types'], ['client', 'server']);
1111

1212
api.use(['templating', 'blaze'], 'client', { weak: true });
1313
api.mainModule('client/_init.js', 'client');
1414
api.mainModule('server/_init.js', 'server');
1515
});
1616

1717
Package.onTest((api) => {
18-
api.use(['ecmascript', 'tinytest', 'underscore', 'check', 'mongo', 'http', 'random', 'communitypackages:[email protected]', 'communitypackages:[email protected]', 'montiapm:[email protected]', 'ostrio:flow-router-extra'], ['client', 'server']);
18+
api.use(['ecmascript', 'tinytest', 'underscore', 'check', 'mongo', 'http', 'random', 'communitypackages:[email protected]', 'communitypackages:[email protected]', 'montiapm:[email protected]', 'ostrio:flow-router-extra', 'zodern:types'], ['client', 'server']);
1919
api.use(['reactive-var', 'tracker'], 'client');
2020

2121
api.addFiles('test/common/fast_render_route.js', ['client', 'server']);
@@ -44,4 +44,4 @@ Package.onTest((api) => {
4444
Npm.depends({
4545
page: '1.9.0',
4646
qs: '6.10.5'
47-
});
47+
});

types.d.ts

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
type Trigger = (context: ReturnType<Router["current"]>, redirect: Router["go"], stop: () => void, data: any) => void;
2+
3+
type TriggerFilterParam = { only: string[] } | { except: string[] };
4+
5+
type DynamicImport<T extends string> = Promise<typeof import(T)>;
6+
7+
type Hook = (params: Param, qs: QueryParam) => void;
8+
9+
type waitOn = (
10+
params: Param,
11+
qs: QueryParam,
12+
ready: (func: () => ReturnType<waitOn>) => void
13+
) =>
14+
| Promise<any>
15+
| Array<Promise<any>>
16+
| Meteor.SubscriptionHandle
17+
| Tracker.Computation
18+
| Array<Tracker.Computation>
19+
| DynamicImport<string>
20+
| Array<DynamicImport<string> | Meteor.SubscriptionHandle>;
21+
22+
type waitOnResources = (
23+
params: Param,
24+
qs: QueryParam
25+
) => {
26+
images: string[];
27+
other: string[];
28+
};
29+
30+
type data = (params: Param, qs: QueryParam) => Mongo.CursorStatic | Object | Object[] | false | null | void;
31+
32+
type action = (params: Param, qs: QueryParam, data: any) => void;
33+
34+
type Param = {
35+
[key: string]: string;
36+
};
37+
38+
type QueryParam = Param;
39+
40+
interface Router {
41+
go: (path: string, params?: { [key: string]: string }, qs?: { [key: string]: string }) => boolean;
42+
route: (
43+
path: string,
44+
options?: {
45+
name?: string;
46+
whileWaiting?: Hook;
47+
waitOn?: waitOn;
48+
waitOnResources?: waitOnResources;
49+
endWaiting?: () => void;
50+
data?: data;
51+
onNoData?: Hook;
52+
triggersEnter?: Array<Trigger>;
53+
action?: action;
54+
triggersExit?: Array<Trigger>;
55+
conf?: { [key: string]: any; forceReRender?: boolean };
56+
[key: string]: any;
57+
}
58+
) => Route;
59+
group: (options: { name: string; prefix: string; [key: string]: any }) => any;
60+
render: (layout: string, template: string, data?: { [key: string]: any }, callback?: () => void) => void;
61+
62+
refresh: (layout: string, template: string) => void;
63+
reload: () => void;
64+
pathRegExp: RegExp;
65+
decodeQueryParamsOnce: boolean;
66+
67+
getParam: (param: string) => string;
68+
getQueryParam: (param: string) => string;
69+
setParams: (params: Param) => boolean;
70+
setQueryParams: (params: QueryParam) => boolean;
71+
72+
url: (path: string, params?: Param, qs?: QueryParam) => string;
73+
path: (path: string, params?: Param, qs?: QueryParam) => string;
74+
current: () => {
75+
context: Context;
76+
oldRoute: Route;
77+
params: Param;
78+
path: string;
79+
queryParams: QueryParam;
80+
route: Route;
81+
};
82+
getRouteName: () => string;
83+
84+
watchPathChange: () => void;
85+
withReplaceState: (callback: () => void) => void;
86+
87+
onRouteRegister: (callback: (route: Route) => void) => void;
88+
89+
wait: () => void;
90+
initialize: (options: { hashbang: boolean; page: { click: boolean } }) => void;
91+
92+
triggers: {
93+
enter: (triggers: Trigger[], filter?: TriggerFilterParam) => void;
94+
exit: (triggers: Trigger[], filter?: TriggerFilterParam) => void;
95+
};
96+
}
97+
98+
interface Route {
99+
conf: { [key: string]: string | boolean };
100+
globals: Array<any>;
101+
group: string;
102+
name: string;
103+
options: { name: string };
104+
path: string;
105+
pathDef: string;
106+
render: () => void;
107+
}
108+
109+
type Context = {
110+
canonicalPath: string;
111+
hash: string;
112+
params: Param;
113+
path: string;
114+
pathname: string;
115+
querystring: string;
116+
state: { [key: string]: string };
117+
title: string;
118+
};
119+
120+
interface Helpers {
121+
name: (routeName: string | RegExp) => boolean;
122+
path: (pathName: string | RegExp) => boolean;
123+
pathFor: (pathName: string, params: Param) => string;
124+
configure: (options: { activeClass: string; caseSensitive: boolean; disabledClass: string; regex: string }) => void;
125+
}
126+
127+
export const FlowRouter: Router;
128+
export const RouterHelpers: Helpers;

0 commit comments

Comments
 (0)