-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tarh
committed
Feb 11, 2015
1 parent
30b332a
commit 11927bf
Showing
5 changed files
with
1,159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea | ||
*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/// <reference path='../defs/Woc.d.ts' /> | ||
|
||
declare module EasyRouter { | ||
|
||
interface Query { | ||
parent?: any; | ||
redirectedFrom?: string; | ||
queryString: string; | ||
queryHash: string; | ||
queryParams: { [index: string]: string; }; | ||
route?: string; | ||
routeParams?: { [index: string]: string; }; | ||
processedQueryString?: string; | ||
remainingQueryString?: string; | ||
title?: string; | ||
} | ||
|
||
interface RouteActivator { | ||
/** | ||
* Required if canActivate is not defined | ||
*/ | ||
route?: string; | ||
useQueryString?: string; | ||
/** | ||
* @return any a boolean or a Promise<boolean> | ||
*/ | ||
canActivate?(query: Query): any; | ||
redirectTo?: string; | ||
/** | ||
* This callback is required except if a child router is defined | ||
* @return any void (undefined) or a Promise<void> | ||
*/ | ||
activate?(query: Query): any; | ||
/** | ||
* @return any a boolean or a Promise<boolean> | ||
*/ | ||
canDeactivate?(): any; | ||
/** | ||
* @return any void or a Promise<void> | ||
*/ | ||
deactivate?(): any; | ||
/** | ||
* A string or a callback(query: RouteProperties) that returns a string or a Promise<string> | ||
*/ | ||
title?: any; | ||
child?: ChildRouter; | ||
} | ||
|
||
interface MinimalRouter { | ||
navigate(queryString: string): Promise<boolean>; | ||
navigateToUnknown(): Promise<boolean>; | ||
navigateBack(level?: number): Promise<boolean>; | ||
/** | ||
* @param cb returns a boolean or a Promise<boolean> | ||
* @param onNavRm default value is FALSE | ||
*/ | ||
addCanLeaveListener(cb: () => any, onNavRm?: boolean): number; | ||
removeCanLeaveListener(handle: number): void; | ||
/** | ||
* @param onNavRm default value is FALSE | ||
*/ | ||
addLeaveListener(cb: () => void, onNavRm?: boolean): number; | ||
removeLeaveListener(handle: number): void; | ||
} | ||
|
||
interface ParentRouter { | ||
parentNavigateToUnknown(changeHist: boolean): Promise<boolean>; | ||
} | ||
|
||
interface ChildRouter { | ||
startAsChild(parent: ParentRouter, withHistory: boolean): void; | ||
childNavigate(queryString: string, changeHist: boolean, parentUrl: string, parentQuery: any): Promise<boolean>; | ||
leaveChildRouter(): Promise<boolean>; | ||
} | ||
|
||
interface RootConfig { | ||
baseUrl: string; | ||
/** | ||
* Default is true | ||
*/ | ||
hashMode: boolean; | ||
/** | ||
* Default is false | ||
*/ | ||
noHistory?: boolean; | ||
firstQueryString?: string; | ||
} | ||
|
||
class Router implements ParentRouter, ChildRouter, MinimalRouter { | ||
|
||
constructor( | ||
onAsyncErrCb: (err: any) => void, | ||
onRejectCb?: (err: any, query?: Query) => void, | ||
onUnknownRouteCb?: (query: Query) => void | ||
); | ||
|
||
startRoot(config: RootConfig): Promise<void>; | ||
map(activators: RouteActivator[]): Router; | ||
mapUnknownRoutes(activator: RouteActivator): Router; | ||
|
||
// - Parent router | ||
parentNavigateToUnknown(changeHist: boolean): Promise<boolean>; | ||
|
||
// - Child router | ||
startAsChild(parent: ParentRouter, withHistory: boolean): void; | ||
childNavigate(queryString: string, changeHist: boolean, parentUrl: string, parentQuery: any): Promise<boolean>; | ||
leaveChildRouter(): Promise<boolean>; | ||
|
||
// - Minimal router | ||
navigate(queryString: string): Promise<boolean>; | ||
navigateToUnknown(): Promise<boolean>; | ||
navigateBack(level?: number): Promise<boolean>; | ||
/** | ||
* @param cb returns a boolean or a Promise<boolean> | ||
* @param onNavRm default value is FALSE | ||
*/ | ||
addCanLeaveListener(cb: () => any, onNavRm?: boolean): number; | ||
removeCanLeaveListener(handle: number): void; | ||
/** | ||
* @param onNavRm default value is FALSE | ||
*/ | ||
addLeaveListener(cb: () => void, onNavRm?: boolean): number; | ||
removeLeaveListener(handle: number): void; | ||
|
||
// - Router listeners | ||
addCanNavigateListener(cb: (query: Query) => any, onNavRm?: boolean): number; | ||
removeCanNavigateListener(handle: number): void; | ||
addNavigateListener(cb: (query: Query) => void, onNavRm?: boolean): number; | ||
removeNavigateListener(handle: number): void; | ||
} | ||
} |
Oops, something went wrong.