From 8bbf4084f0388a1bf61b4dc12a2562213bb52184 Mon Sep 17 00:00:00 2001 From: Santi Albo Date: Tue, 28 Jan 2014 11:34:13 +0000 Subject: [PATCH 1/5] (angular-ui-router) Set `toPath` argument to any The `toPath` argument on `IUrlRouterProvider.when` can also be a function that returns a string and an injected function (i.e. any[]). --- angular-ui/angular-ui-router.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/angular-ui/angular-ui-router.d.ts b/angular-ui/angular-ui-router.d.ts index bc3e27c2d..eec2cfcf3 100644 --- a/angular-ui/angular-ui-router.d.ts +++ b/angular-ui/angular-ui-router.d.ts @@ -42,9 +42,9 @@ declare module ng.ui { } interface IUrlRouterProvider extends IServiceProvider { - when(whenPath: string, toPath: string): IUrlRouterProvider; - when(whenPath: RegExp, toPath: string): IUrlRouterProvider; - when(whenPath: IUrlMatcher, toPath: string): IUrlRouterProvider; + when(whenPath: string, toPath: any): IUrlRouterProvider; + when(whenPath: RegExp, toPath: any): IUrlRouterProvider; + when(whenPath: IUrlMatcher, toPath: any): IUrlRouterProvider; otherwise(path: string): IUrlRouterProvider; otherwise(path: Function): IUrlRouterProvider; rule(handler: Function): IUrlRouterProvider; From adcb4a09b36a7a04b4564277f9f9b06ce09feaba Mon Sep 17 00:00:00 2001 From: Santi Albo Date: Tue, 28 Jan 2014 14:20:21 +0000 Subject: [PATCH 2/5] Explode all combinations --- angular-ui/angular-ui-router.d.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/angular-ui/angular-ui-router.d.ts b/angular-ui/angular-ui-router.d.ts index eec2cfcf3..eb3bca9ac 100644 --- a/angular-ui/angular-ui-router.d.ts +++ b/angular-ui/angular-ui-router.d.ts @@ -42,12 +42,20 @@ declare module ng.ui { } interface IUrlRouterProvider extends IServiceProvider { - when(whenPath: string, toPath: any): IUrlRouterProvider; - when(whenPath: RegExp, toPath: any): IUrlRouterProvider; - when(whenPath: IUrlMatcher, toPath: any): IUrlRouterProvider; + when(whenPath: string, toPath: string): IUrlRouterProvider; + when(whenPath: RegExp, toPath: string): IUrlRouterProvider; + when(whenPath: IUrlMatcher, toPath: string): IUrlRouterProvider; + when(whenPath: string, handler: ($injector?: ng.auto.IInjectorService, $location?: ng.ILocationService) => any): IUrlRouterProvider; + when(whenPath: RegExp, handler: ($injector?: ng.auto.IInjectorService, $location?: ng.ILocationService) => any): IUrlRouterProvider; + when(whenPath: IUrlMatcher, hanlder: ($injector?: ng.auto.IInjectorService, $location?: ng.ILocationService) => any): IUrlRouterProvider; + when(whenPath: string, handler: any[]): IUrlRouterProvider; + when(whenPath: RegExp, handler: any[]): IUrlRouterProvider; + when(whenPath: IUrlMatcher, handler: any[]): IUrlRouterProvider; otherwise(path: string): IUrlRouterProvider; - otherwise(path: Function): IUrlRouterProvider; - rule(handler: Function): IUrlRouterProvider; + otherwise(handler: ($injector?: ng.auto.IInjectorService, $location?: ng.ILocationService) => any): IUrlRouterProvider; + otherwise(handler: any[]): IUrlRouterProvider; + rule(handler: ($injector?: ng.auto.IInjectorService, $location?: ng.ILocationService) => any): IUrlRouterProvider; + rule(handler: any[]): IUrlRouterProvider; } interface IStateOptions { From 8867eb90b8e716520df0d1a0bbceb53d2e52d2ae Mon Sep 17 00:00:00 2001 From: Santi Albo Date: Tue, 28 Jan 2014 14:53:09 +0000 Subject: [PATCH 3/5] Add tests --- angular-ui/angular-ui-router-tests.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/angular-ui/angular-ui-router-tests.ts b/angular-ui/angular-ui-router-tests.ts index 38f8b5ca0..f52d35837 100644 --- a/angular-ui/angular-ui-router-tests.ts +++ b/angular-ui/angular-ui-router-tests.ts @@ -9,11 +9,21 @@ interface MyAppScope extends ng.IScope { myApp.config(( $stateProvider: ng.ui.IStateProvider, - $urlRouterProvider: ng.ui.IUrlRouterProvider) => { - // - // For any unmatched url, redirect to /state1 - $urlRouterProvider.otherwise("/state1"); - // + $urlRouterProvider: ng.ui.IUrlRouterProvider, + $urlMatcherFactory: ng.ui.IUrlMatcherFactory) => { + + var matcher: ng.ui.IUrlMatcher = $urlMatcherFactory.compile("/foo/:bar?param1"); + + $urlRouterProvider + .when('/test', '/list') + .when(/\/test\d/, ($injector: ng.auto.IInjectorService, $location: ng.ILocationService) => { + return '/list'; + }) + .when(matcher, ['$injector', '$location', ($injector: ng.auto.IInjectorService, $location: ng.ILocationService) => { + return false; + }]) + .otherwise("/state1"); + // Now set up the states $stateProvider .state('state1', { @@ -58,4 +68,4 @@ myApp.config(( "viewB": { template: "route2.viewB" } } }); -}); \ No newline at end of file +}); From f5ad5d5d010e018f7db912a0fe952a0e05dac386 Mon Sep 17 00:00:00 2001 From: Santi Albo Date: Tue, 28 Jan 2014 15:39:52 +0000 Subject: [PATCH 4/5] Fix tests --- angular-ui/angular-ui-router.d.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/angular-ui/angular-ui-router.d.ts b/angular-ui/angular-ui-router.d.ts index eb3bca9ac..da3d92e5e 100644 --- a/angular-ui/angular-ui-router.d.ts +++ b/angular-ui/angular-ui-router.d.ts @@ -42,19 +42,19 @@ declare module ng.ui { } interface IUrlRouterProvider extends IServiceProvider { - when(whenPath: string, toPath: string): IUrlRouterProvider; - when(whenPath: RegExp, toPath: string): IUrlRouterProvider; - when(whenPath: IUrlMatcher, toPath: string): IUrlRouterProvider; - when(whenPath: string, handler: ($injector?: ng.auto.IInjectorService, $location?: ng.ILocationService) => any): IUrlRouterProvider; - when(whenPath: RegExp, handler: ($injector?: ng.auto.IInjectorService, $location?: ng.ILocationService) => any): IUrlRouterProvider; - when(whenPath: IUrlMatcher, hanlder: ($injector?: ng.auto.IInjectorService, $location?: ng.ILocationService) => any): IUrlRouterProvider; - when(whenPath: string, handler: any[]): IUrlRouterProvider; + when(whenPath: RegExp, handler: Function): IUrlRouterProvider; when(whenPath: RegExp, handler: any[]): IUrlRouterProvider; + when(whenPath: RegExp, toPath: string): IUrlRouterProvider; + when(whenPath: IUrlMatcher, hanlder: Function): IUrlRouterProvider; when(whenPath: IUrlMatcher, handler: any[]): IUrlRouterProvider; - otherwise(path: string): IUrlRouterProvider; - otherwise(handler: ($injector?: ng.auto.IInjectorService, $location?: ng.ILocationService) => any): IUrlRouterProvider; + when(whenPath: IUrlMatcher, toPath: string): IUrlRouterProvider; + when(whenPath: string, handler: Function): IUrlRouterProvider; + when(whenPath: string, handler: any[]): IUrlRouterProvider; + when(whenPath: string, toPath: string): IUrlRouterProvider; + otherwise(handler: Function): IUrlRouterProvider; otherwise(handler: any[]): IUrlRouterProvider; - rule(handler: ($injector?: ng.auto.IInjectorService, $location?: ng.ILocationService) => any): IUrlRouterProvider; + otherwise(path: string): IUrlRouterProvider; + rule(handler: Function): IUrlRouterProvider; rule(handler: any[]): IUrlRouterProvider; } From 273728dedb148b762e0afb150a2003925dce5cf1 Mon Sep 17 00:00:00 2001 From: Santi Albo Date: Tue, 28 Jan 2014 15:40:39 +0000 Subject: [PATCH 5/5] More tests for angular-ui-router --- angular-ui/angular-ui-router-tests.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/angular-ui/angular-ui-router-tests.ts b/angular-ui/angular-ui-router-tests.ts index f52d35837..5a9c4ad6c 100644 --- a/angular-ui/angular-ui-router-tests.ts +++ b/angular-ui/angular-ui-router-tests.ts @@ -15,14 +15,16 @@ myApp.config(( var matcher: ng.ui.IUrlMatcher = $urlMatcherFactory.compile("/foo/:bar?param1"); $urlRouterProvider - .when('/test', '/list') - .when(/\/test\d/, ($injector: ng.auto.IInjectorService, $location: ng.ILocationService) => { - return '/list'; - }) - .when(matcher, ['$injector', '$location', ($injector: ng.auto.IInjectorService, $location: ng.ILocationService) => { - return false; - }]) - .otherwise("/state1"); + .when('/test', '/list') + .when('/test', '/list') + .when('/test', '/list') + .when(/\/test\d/, '/list') + .when(/\/test\d/, ($injector: ng.auto.IInjectorService, $location: ng.ILocationService) => '/list') + .when(/\/test\d/,['$injector', '$location', ($injector: ng.auto.IInjectorService, $location: ng.ILocationService) => '/list']) + .when(matcher, '/list') + .when(matcher, ($injector: ng.auto.IInjectorService, $location: ng.ILocationService) => '/list') + .when(matcher, ['$injector', '$location', ($injector: ng.auto.IInjectorService, $location: ng.ILocationService) => '/list']) + .otherwise("/state1"); // Now set up the states $stateProvider