From 2e31771e4701df0cfefb3a17e18d0fdbe4cb5453 Mon Sep 17 00:00:00 2001 From: marcelk Date: Fri, 4 Sep 2015 14:48:14 +0200 Subject: [PATCH] Update Ui Router Extra's. Added deepstate redirect and extended stickystate. --- ui-router-extras/ui-router-extras-tests.ts | 35 +++++++-- ui-router-extras/ui-router-extras.d.ts | 86 +++++++++++++++++++--- 2 files changed, 107 insertions(+), 14 deletions(-) diff --git a/ui-router-extras/ui-router-extras-tests.ts b/ui-router-extras/ui-router-extras-tests.ts index 22d9e4f733..a87b95863c 100644 --- a/ui-router-extras/ui-router-extras-tests.ts +++ b/ui-router-extras/ui-router-extras-tests.ts @@ -3,10 +3,24 @@ var myApp = angular.module('testModule') myApp.config(($stateProvider: angular.ui.IStateProvider, $stickyStateProvider: angular.ui.IStickyStateProvider) => { - var state: angular.ui.IStickyState = { + var state: angular.ui.IStickyState = { name: 'test', - sticky: true, - controller: ($previousState: angular.ui.IPreviousStateService) => { + sticky: true, + dsr: { + default: 'substate', + params: ['param1', 'param2'], + fn: function ($dsr$) { + + return $dsr$.to; + } + }, + onInactivate: function ($state: angular.ui.IState) { + var iAmInjectedByInjector = $state; + }, + onReactivate: function ($state: angular.ui.IState) { + var iAmInjectedByInjector = $state; + }, + controller: ($previousState: angular.ui.IPreviousStateService, $deepstateRedirect: angular.ui.IDeepStateRedirectService) => { $previousState.memo('test-memo1'); $previousState.memo('test-memo2', 'test-state-name2'); $previousState.memo('test-memo3', 'test-state-name3', {}); @@ -14,8 +28,19 @@ myApp.config(($stateProvider: angular.ui.IStateProvider, $stickyStateProvider: a $previousState.go('test-memo2', { location: true, notify: true - }); - } + }); + $previousState.get(); + $previousState.get('test-memo1'); + + $deepstateRedirect.reset('statename1', { + 'stateParam1': ['value1', 'value2'], + 'stateParam2': 'value' + }); + }, + views: { + //named views are mandatory + 'name1': {} + } }; $stickyStateProvider.enableDebug(true); diff --git a/ui-router-extras/ui-router-extras.d.ts b/ui-router-extras/ui-router-extras.d.ts index 8e0c42828e..df0d0aa3ed 100644 --- a/ui-router-extras/ui-router-extras.d.ts +++ b/ui-router-extras/ui-router-extras.d.ts @@ -1,6 +1,6 @@ // Type definitions for UI-Router Extras 0.0.14+ (ct.ui.router.extras module) // Project: https://github.com/christopherthielen/ui-router-extras -// Definitions by: Michael Putters +// Definitions by: Michael Putters , Marcel van de Kamp // Definitions: https://github.com/borisyankov/DefinitelyTyped /// @@ -13,12 +13,54 @@ declare module 'angular-ui-router-extras' { declare module angular.ui { - /** + + /* + * $deepStateRedirect + */ + interface IDeepStateRedirectService { + /* + * This method resets stored $deepStateRedirect data so following transitions will behave like there have not been previous transitions. + * @param stateParams Can be passed in to select specific states to reset: + * { + * 'paramName': 'paramvalue' | ['list', 'of', 'possible', 'paramvalues'] + * } + */ + reset(stateName: string, stateParams?: { [key: string]: string | string[] }): void; + } + + /* + * Docs: http://christopherthielen.github.io/ui-router-extras/#/dsr + */ + interface IDeepStateRedirectConfig { + /* + * If no deep state has been recorded, DSR will instead redirect to the default substate and params that you specify. + * If default is a string it is interpreted as the substate. + */ + default?: string | IRedirectParams; + /* + * Specify params: true if your DSR state takes parameters. + * If only a subset of the parameters should be included in the parameter grouping for recording deep states, + * specify an array of parameter names. + */ + params?: boolean | string[]; + /* + * A callback function that determines whether or not the redirect should actually occur, or changes the redirect to some other state. + * Return an object: IRedirectParams to change the redirect + */ + fn?($dsr$: { redirect: IRedirectParams; to: IRedirectParams }): boolean | IRedirectParams; + } + + interface IRedirectParams { + state: string; + params?: ui.IStateParamsService; + } + + /* * Previous state */ - interface IPreviousState { - state: IState; - params?: {}; + interface IPreviousState { + state: IState; + params?: ui.IStateParamsService; } /** @@ -54,16 +96,42 @@ declare module angular.ui { * @param memoName Memo name */ forget(memoName: string): void; - - } + } /** - * Sticky state - */ + * Sticky state + */ interface IStickyState extends angular.ui.IState { + /* + * When marking a state sticky, the state must target its own unique named ui-view. + * Docs: http://christopherthielen.github.io/ui-router-extras/#/sticky + */ sticky?: boolean; + /* + * The most-recently-activate substate of the DSR marked state is remembered. + * When the DSR marked state is transitioned to directly, UI-Router Extras will instead redirect to the remembered state and parameters. + * Docs: http://christopherthielen.github.io/ui-router-extras/#/dsr + */ + deepStateRedirect?: boolean | IDeepStateRedirectConfig; + /* + * Shortname deepStateRedirect prop + */ + dsr?: boolean | IDeepStateRedirectConfig; + /* + * Function (injectable). Called when a sticky state is navigated away from (inactivated). + */ + onInactivate?: Function; + /* + * Function (injectable). Called when an inactive sticky state is navigated to (reactivated). + */ + onReactivate?: Function; + /* + * Note: named views are mandatory when using sticky states! + */ + views?: {}; } + /** * Sticky state service */