Update Ui Router Extra's. Added deepstate redirect and extended

stickystate.
This commit is contained in:
marcelk
2015-09-04 14:48:14 +02:00
parent 56a316c7fb
commit 2e31771e47
2 changed files with 107 additions and 14 deletions

View File

@@ -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);

View File

@@ -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 <https://github.com/mputters>
// Definitions by: Michael Putters <https://github.com/mputters/>, Marcel van de Kamp <https://github.com/marcel-k/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../angular-ui-router/angular-ui-router.d.ts" />
@@ -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
*/