Updated typings and tests for Navigation 1.2.0

This commit is contained in:
Graham Mendick
2015-12-10 13:44:18 +00:00
parent 4dc5ab8736
commit a0d8937030
2 changed files with 138 additions and 10 deletions

View File

@@ -38,8 +38,8 @@ module NavigationTests {
// Configuration
Navigation.StateInfoConfig.build([
{ key: 'home', initial: 'page', states: [
{ key: 'page', route: '' }
{ key: 'home', initial: 'page', help: 'home.htm', states: [
{ key: 'page', route: '', help: 'page.htm' }
]},
{ key: 'person', initial: 'list', states: [
{ key: 'list', route: ['people/{page}', 'people/{page}/sort/{sort}'], transitions: [
@@ -97,24 +97,28 @@ module NavigationTests {
// Navigation
Navigation.start('home');
Navigation.StateController.navigate('person');
Navigation.StateController.navigate('person', null, Navigation.HistoryAction.Add);
Navigation.StateController.refresh();
Navigation.StateController.refresh({ page: 2 });
Navigation.StateController.refresh({ page: 3 });
Navigation.StateController.refresh({ page: 2 }, Navigation.HistoryAction.Replace);
Navigation.StateController.navigate('select', { id: 10 });
var canGoBack: boolean = Navigation.StateController.canNavigateBack(1);
Navigation.StateController.navigateBack(1);
Navigation.StateController.clearStateContext();
// Navigation Link
var link = Navigation.StateController.getNavigationLink('person');
link = Navigation.StateController.getRefreshLink();
link = Navigation.StateController.getRefreshLink({ page: 2 });
Navigation.StateController.navigateLink(link);
link = Navigation.StateController.getNavigationLink('select', { id: 10 });
var nextDialog = Navigation.StateController.getNextState('select').parent;
person = nextDialog;
Navigation.StateController.navigateLink(link);
Navigation.StateController.navigateLink(link, false);
link = Navigation.StateController.getNavigationBackLink(1);
var crumb = Navigation.StateController.crumbs[0];
link = crumb.navigationLink;
Navigation.StateController.navigateLink(link, true);
Navigation.StateController.navigateLink(link, true, Navigation.HistoryAction.None);
// StateContext
Navigation.StateController.navigate('home');
@@ -124,10 +128,15 @@ module NavigationTests {
person === Navigation.StateContext.dialog;
personList === Navigation.StateContext.state;
var url: string = Navigation.StateContext.url;
var title: string = Navigation.StateContext.title;
var page: number = Navigation.StateContext.data.page;
Navigation.StateController.refresh({ page: 2 });
person = Navigation.StateContext.oldDialog;
personList = Navigation.StateContext.oldState;
page = Navigation.StateContext.oldData.page;
page = Navigation.StateContext.previousData.page;
// Navigation Data
Navigation.StateController.refresh({ page: 2 });
var data = Navigation.StateContext.includeCurrentData({ sort: 'name' }, ['page']);
Navigation.StateController.refresh(data);
Navigation.StateContext.clear('sort');

View File

@@ -1,4 +1,4 @@
// Type definitions for Navigation 1.1.0
// Type definitions for Navigation 1.2.0
// Project: http://grahammendick.github.io/navigation/
// Definitions by: Graham Mendick <https://github.com/grahammendick>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
@@ -31,6 +31,10 @@ declare module Navigation {
* Gets the textual description of the dialog
*/
title?: string;
/**
* Gets the additional dialog attributes
*/
[extras: string]: any;
}
/**
@@ -75,6 +79,10 @@ declare module Navigation {
* preserved when navigating
*/
trackTypes?: boolean;
/**
* Gets the additional state attributes
*/
[extras: string]: any;
}
/**
@@ -278,6 +286,24 @@ declare module Navigation {
*/
static build(dialogs: IDialog<string, IState<ITransition<string>[]>[]>[]): void;
}
/**
* Determines the effect on browser history after a successful navigation
*/
enum HistoryAction {
/**
* Creates a new browser history entry
*/
Add = 0,
/**
* Changes the current browser history entry
*/
Replace = 1,
/**
* Leaves browser history unchanged
*/
None = 2,
}
/**
* Defines a contract a class must implement in order to manage the browser
@@ -295,9 +321,17 @@ declare module Navigation {
/**
* Adds browser history
* @param state The State navigated to
* @param url The current url
* @param url The current url
*/
addHistory(state: State, url: string): void;
/**
* Adds browser history
* @param state The State navigated to
* @param url The current url
* @param replace A value indicating whether to replace the current
* browser history entry
*/
addHistory(state: State, url: string, replace: boolean): void;
/**
* Gets the current location
*/
@@ -339,6 +373,14 @@ declare module Navigation {
* @param url The current url
*/
addHistory(state: State, url: string): void;
/**
* Sets the browser Url's hash to the url
* @param state The State navigated to
* @param url The current url
* @param replace A value indicating whether to replace the current
* browser history entry
*/
addHistory(state: State, url: string, replace: boolean): void;
/**
* Gets the current location
*/
@@ -375,6 +417,14 @@ declare module Navigation {
* @param url The current url
*/
addHistory(state: State, url: string): void;
/**
* Sets the browser Url to the url using pushState
* @param state The State navigated to
* @param url The current url
* @param replace A value indicating whether to replace the current
* browser history entry
*/
addHistory(state: State, url: string, replace: boolean): void;
/**
* Gets the current location
*/
@@ -587,6 +637,11 @@ declare module Navigation {
* ReturnData should be part of the CrumbTrail
*/
combineCrumbTrail: boolean;
/**
* Gets or sets a value indicating whether to track PreviousData when
* navigating back or refreshing and combineCrumbTrail is false
*/
trackAllPreviousData: boolean;
}
/**
@@ -595,6 +650,18 @@ declare module Navigation {
* previous State (this is not the same as the previous Crumb)
*/
class StateContext {
/**
* Gets the last State displayed before the current State
*/
static oldState: State;
/**
* Gets the parent of the OldState property
*/
static oldDialog: Dialog;
/**
* Gets the NavigationData for the last displayed State
*/
static oldData: any;
/**
* Gets the State navigated away from to reach the current State
*/
@@ -603,6 +670,10 @@ declare module Navigation {
* Gets the parent of the PreviousState property
*/
static previousDialog: Dialog;
/**
* Gets the NavigationData for the navigated away from State
*/
static previousData: any;
/**
* Gets the current State
*/
@@ -612,14 +683,17 @@ declare module Navigation {
*/
static dialog: Dialog;
/**
* Gets the NavigationData for the current State. It can be accessed.
* Will become the data stored in a Crumb when part of a crumb trail
* Gets the NavigationData for the current State
*/
static data: any;
/**
* Gets the current Url
*/
static url: string;
/**
* Gets or sets the current title
*/
static title: string;
/**
* Combines the data with all the current NavigationData
* @param The data to add to the current NavigationData
@@ -660,6 +734,10 @@ declare module Navigation {
* @param url The current Url
*/
static setStateContext(state: State, url: string): void;
/**
* Clears the Context Data
*/
static clearStateContext(): void;
/**
* Registers a navigate event listener
* @param handler The navigate event listener
@@ -694,6 +772,20 @@ declare module Navigation {
* @throws A mandatory route parameter has not been supplied a value
*/
static navigate(action: string, toData: any): void;
/**
* Navigates to a State. Depending on the action will either navigate
* to the 'to' State of a Transition or the 'initial' State of a
* Dialog
* @param action The key of a child Transition or the key of a Dialog
* @param toData The NavigationData to be passed to the next State and
* stored in the StateContext
* @param A value determining the effect on browser history
* @throws action does not match the key of a child Transition or the
* key of a Dialog; or there is NavigationData that cannot be converted
* to a String
* @throws A mandatory route parameter has not been supplied a value
*/
static navigate(action: string, toData: any, historyAction: HistoryAction): void;
/**
* Gets a Url to navigate to a State. Depending on the action will
* either navigate to the 'to' State of a Transition or the 'initial'
@@ -733,6 +825,17 @@ declare module Navigation {
* @throws A mandatory route parameter has not been supplied a value
*/
static navigateBack(distance: number): void;
/**
* Navigates back to the Crumb contained in the crumb trail,
* represented by the Crumbs collection, as specified by the distance.
* In the crumb trail no two crumbs can have the same State but all
* must have the same Dialog
* @param distance Starting at 1, the number of Crumb steps to go back
* @param A value determining the effect on browser history
* @throws canNavigateBack returns false for this distance
* @throws A mandatory route parameter has not been supplied a value
*/
static navigateBack(distance: number, historyAction: HistoryAction): void;
/**
* Gets a Url to navigate to a Crumb contained in the crumb trail,
* represented by the Crumbs collection, as specified by the distance.
@@ -755,6 +858,15 @@ declare module Navigation {
* @throws A mandatory route parameter has not been supplied a value
*/
static refresh(toData: any): void;
/**
* Navigates to the current State
* @param toData The NavigationData to be passed to the current State
* and stored in the StateContext
* @param A value determining the effect on browser history
* @throws There is NavigationData that cannot be converted to a String
* @throws A mandatory route parameter has not been supplied a value
*/
static refresh(toData: any, historyAction: HistoryAction): void;
/**
* Gets a Url to navigate to the current State passing no
* NavigationData
@@ -779,6 +891,13 @@ declare module Navigation {
* @param history A value indicating whether browser history was used
*/
static navigateLink(url: string, history: boolean): void;
/**
* Navigates to the url
* @param url The target location
* @param history A value indicating whether browser history was used
* @param A value determining the effect on browser history
*/
static navigateLink(url: string, history: boolean, historyAction: HistoryAction): void;
/**
* Gets the next State. Depending on the action will either return the
* 'to' State of a Transition or the 'initial' State of a Dialog