|
| 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