Skip to content

Instantly share code, notes, and snippets.

@matt-hensley
Last active December 14, 2016 20:14
Show Gist options
  • Select an option

  • Save matt-hensley/101a4107a912db0799293413e1c096b7 to your computer and use it in GitHub Desktop.

Select an option

Save matt-hensley/101a4107a912db0799293413e1c096b7 to your computer and use it in GitHub Desktop.
ko-computer-router types
interface KoComponentRouterMiddlewareContext {
element: Node;
router: any;
route: any;
path: string;
pathname: string;
params: Object;
}
interface KoComponentRouterContext extends KoComponentRouterMiddlewareContext {
$parent: KoComponentRouterContext;
$child: KoComponentRouterContext;
addBeforeNavigateCallback(callback: () => boolean | Promise<boolean>);
addBeforeNavigateCallback(callback: (done: (boolean) => void) => void);
}
interface KoComponentRouterLifecycle {
beforeRender?: Function;
afterRender?: Function;
beforeDispose?: Function;
afterDispose?: Function;
}
type KoComponentRouterMiddlewarePromise = (ctx: KoComponentRouterMiddlewareContext) => Promise<any>;
type KoComponentRouterMiddlewareLifecycle = (ctx: KoComponentRouterMiddlewareContext) => KoComponentRouterLifecycle;
type KoComponentRouterMiddlewareCallback = (ctx: KoComponentRouterMiddlewareContext, done: () => void) => void;
type KoComponentRouterMiddleware = KoComponentRouterMiddlewarePromise
| KoComponentRouterMiddlewareLifecycle
| KoComponentRouterMiddlewareCallback;
interface KoComponentRouterRouter {
isNavigating: KnockoutObservable<boolean>;
getPathFromLocation(): string;
resolvePath(path: string): KoComponentRouterRoute;
}
interface KoComponentRouterRoute {
matches(path: string): boolean;
}
interface KoComponentRouterStatic {
history: KnockoutObservableArray<any>;
isRoot: boolean;
canonicalizePath(path: string): string;
getPath(url: string): string;
link(router: KoComponentRouterRouter, base: string);
parseUrl(url: string): HTMLAnchorElement;
sameOrigin(href: string): boolean;
update(url: string, push: boolean): Promise<boolean>;
unlink(router: KoComponentRouterRouter);
use(middleware: KoComponentRouterMiddleware);
}
interface KnockoutStatic {
router: KoComponentRouterStatic & KoComponentRouterRouter;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment