11/** @packageDocumentation @publicapi @module url */
2+ import { StateDeclaration } from '../state' ;
23import { UrlMatcher } from './urlMatcher' ;
34import { isString , isDefined , isFunction } from '../common/predicates' ;
45import { UIRouter } from '../router' ;
56import { identity , extend } from '../common/common' ;
6- import { is , pattern } from '../common/hof' ;
7+ import { is , or , pattern } from '../common/hof' ;
78import { StateObject } from '../state/stateObject' ;
89import { RawParams } from '../params/interface' ;
910import {
@@ -29,7 +30,7 @@ import {
2930 * @internalapi
3031 */
3132export class UrlRuleFactory {
32- static isUrlRule = obj => obj && [ 'type' , 'match' , 'handler' ] . every ( key => isDefined ( obj [ key ] ) ) ;
33+ static isUrlRule = ( obj ) => obj && [ 'type' , 'match' , 'handler' ] . every ( ( key ) => isDefined ( obj [ key ] ) ) ;
3334
3435 constructor ( public router : UIRouter ) { }
3536
@@ -38,14 +39,14 @@ export class UrlRuleFactory {
3839 }
3940
4041 create (
41- what : string | UrlMatcher | StateObject | RegExp | UrlRuleMatchFn ,
42+ what : string | UrlMatcher | StateObject | StateDeclaration | RegExp | UrlRuleMatchFn ,
4243 handler ?: string | UrlRuleHandlerFn
4344 ) : UrlRule {
44- const isState = StateObject . isState ;
45+ const { isState, isStateDeclaration } = StateObject ;
4546 const makeRule = pattern ( [
4647 [ isString , ( _what : string ) => makeRule ( this . compile ( _what ) ) ] ,
4748 [ is ( UrlMatcher ) , ( _what : UrlMatcher ) => this . fromUrlMatcher ( _what , handler ) ] ,
48- [ isState , ( _what : StateObject ) => this . fromState ( _what , this . router ) ] ,
49+ [ or ( isState , isStateDeclaration ) , ( _what : StateObject | StateDeclaration ) => this . fromState ( _what , this . router ) ] ,
4950 [ is ( RegExp ) , ( _what : RegExp ) => this . fromRegExp ( _what , handler ) ] ,
5051 [ isFunction , ( _what : UrlRuleMatchFn ) => new BaseUrlRule ( _what , handler as UrlRuleHandlerFn ) ] ,
5152 ] ) ;
@@ -107,9 +108,9 @@ export class UrlRuleFactory {
107108 // - Some optional parameters, some matched
108109 // - Some optional parameters, all matched
109110 function matchPriority ( params : RawParams ) : number {
110- const optional = urlMatcher . parameters ( ) . filter ( param => param . isOptional ) ;
111+ const optional = urlMatcher . parameters ( ) . filter ( ( param ) => param . isOptional ) ;
111112 if ( ! optional . length ) return 0.000001 ;
112- const matched = optional . filter ( param => params [ param . id ] ) ;
113+ const matched = optional . filter ( ( param ) => params [ param . id ] ) ;
113114 return matched . length / optional . length ;
114115 }
115116
@@ -128,7 +129,9 @@ export class UrlRuleFactory {
128129 * // Starts a transition to 'foo' with params: { fooId: '123', barId: '456' }
129130 * ```
130131 */
131- fromState ( state : StateObject , router : UIRouter ) : StateRule {
132+ fromState ( stateOrDecl : StateObject | StateDeclaration , router : UIRouter ) : StateRule {
133+ const state = StateObject . isStateDeclaration ( stateOrDecl ) ? stateOrDecl . $$state ( ) : stateOrDecl ;
134+
132135 /**
133136 * Handles match by transitioning to matched state
134137 *
@@ -213,7 +216,7 @@ export class BaseUrlRule implements UrlRule {
213216 _group : number ;
214217 type : UrlRuleType = 'RAW' ;
215218 handler : UrlRuleHandlerFn ;
216- matchPriority = match => 0 - this . $id ;
219+ matchPriority = ( match ) => 0 - this . $id ;
217220
218221 constructor ( public match : UrlRuleMatchFn , handler ?: UrlRuleHandlerFn ) {
219222 this . handler = handler || identity ;
0 commit comments