Skip to content
This repository was archived by the owner on Dec 19, 2017. It is now read-only.

Commit 236d047

Browse files
committed
Typescript type defintion
1 parent 2a53bc0 commit 236d047

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

ko-component-router.d.ts

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
interface KoComponentRouterRoute {
2+
component: string;
3+
}
4+
5+
type CallbackResult = void | false | Promise<boolean>;
6+
type DoneCallback = (boolean) => void;
7+
8+
type KoComponentRouterPromiseMiddleware = (ctx: KoComponentRouterContext) => CallbackResult;
9+
type KoComponentRouterCallbackMiddleware = (ctx: KoComponentRouterContext, done: DoneCallback) => void;
10+
type KoComponentRouterLifecycleMiddleware = (ctx: KoComponentRouterContext) => {
11+
beforeRender: () => CallbackResult;
12+
afterRender: () => CallbackResult;
13+
beforeDispose: () => CallbackResult;
14+
afterDispose: () => CallbackResult;
15+
};
16+
type KoComponentRouterMiddleware = KoComponentRouterPromiseMiddleware
17+
| KoComponentRouterCallbackMiddleware
18+
| KoComponentRouterLifecycleMiddleware;
19+
20+
interface KoComponentRouterContext {
21+
$child: KoComponentRouterContext;
22+
$parent: KoComponentRouterContext;
23+
addBeforeNavigateCallback(cb: () => CallbackResult);
24+
addBeforeNavigateCallback(cb: (done: DoneCallback) => void);
25+
canonicalPath: string;
26+
element: HTMLElement;
27+
fullPath: string;
28+
params: any;
29+
path: string;
30+
pathname: string;
31+
route: KoComponentRouterRoute;
32+
router: KoComponentRouterInstance;
33+
}
34+
35+
interface KoComponentRouterInstance {
36+
$child: KoComponentRouterInstance;
37+
$parent: KoComponentRouterInstance;
38+
base: string;
39+
ctx: KoComponentRouterContext;
40+
isRoot: boolean;
41+
isNavigating: KnockoutObservable<boolean>;
42+
43+
getPathFromLocation(): string;
44+
resolvePath(path): any;
45+
update(path: string, push?: boolean): Promise<boolean>;
46+
}
47+
48+
interface KoComponentRouterRoutes {
49+
[path: string]: string
50+
| KoComponentRouterRoutes
51+
| Array<string | KoComponentRouterPromiseMiddleware | KoComponentRouterLifecycleMiddleware>;
52+
}
53+
54+
declare module 'ko-component-router' {
55+
interface RouterStatic extends KoComponentRouterInstance {
56+
}
57+
namespace RouterStatic {
58+
export var config: { base?: string; hashbang?: boolean; };
59+
export var middleware: KoComponentRouterMiddleware[];
60+
export var plugins: any[];
61+
export var routes: KoComponentRouterRoutes;
62+
export const head: KoComponentRouterInstance;
63+
export const tail: KoComponentRouterInstance;
64+
65+
export function canonicalizePath(path: string): string;
66+
export function get(index: number): KoComponentRouterInstance;
67+
export function getPath(url: string): string;
68+
export function parseUrl(url: string): { hash: string, pathname: string, search: string };
69+
export function sameOrigin(href: string): boolean;
70+
export function update(path: string, push?: boolean): Promise<boolean>;
71+
export function update(path: string, options: { push?: boolean; force?: boolean; with?: any }): Promise<boolean>;
72+
export function use(...middleware: KoComponentRouterMiddleware[]): void;
73+
export function usePlugin(...fns): void;
74+
}
75+
76+
export = RouterStatic;
77+
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"main": "dist/ko-component-router.js",
1818
"jsnext:main": "dist/modules/index.js",
1919
"module": "dist/modules/index.js",
20+
"types": "ko-component-router.d.ts",
2021
"files": [
2122
"dist"
2223
],

0 commit comments

Comments
 (0)