1
+ var $$UMFP ; // reference to $UrlMatcherFactoryProvider
2
+
1
3
/**
2
4
* @ngdoc object
3
5
* @name ui.router.util.type:UrlMatcher
@@ -80,12 +82,12 @@ function UrlMatcher(pattern, config) {
80
82
searchPlaceholder = / ( [: ] ? ) ( [ \w - ] + ) | \{ ( \w + ) (?: \: ( (?: [ ^ { } \\ ] + | \\ .| \{ (?: [ ^ { } \\ ] + | \\ .) * \} ) + ) ) ? \} / g,
81
83
compiled = '^' , last = 0 , m ,
82
84
segments = this . segments = [ ] ,
83
- params = this . params = new $$UrlMatcherFactoryProvider . ParamSet ( ) ;
85
+ params = this . params = new $$UMFP . ParamSet ( ) ;
84
86
85
87
function addParameter ( id , type , config ) {
86
88
if ( ! / ^ \w + ( - + \w + ) * $ / . test ( id ) ) throw new Error ( "Invalid parameter name '" + id + "' in pattern '" + pattern + "'" ) ;
87
89
if ( params [ id ] ) throw new Error ( "Duplicate parameter name '" + id + "' in pattern '" + pattern + "'" ) ;
88
- params [ id ] = new $$UrlMatcherFactoryProvider . Param ( id , type , config ) ;
90
+ params [ id ] = new $$UMFP . Param ( id , type , config ) ;
89
91
return params [ id ] ;
90
92
}
91
93
@@ -102,13 +104,12 @@ function UrlMatcher(pattern, config) {
102
104
// The number of segments is always 1 more than the number of parameters.
103
105
function matchDetails ( m , isSearch ) {
104
106
var id , regexp , segment , type , typeId , cfg ;
105
- var $types = UrlMatcher . prototype . $types ;
106
107
var defaultTypeId = ( isSearch ? "searchParam" : "pathParam" ) ;
107
108
id = m [ 2 ] || m [ 3 ] ; // IE[78] returns '' for unmatched groups instead of null
108
109
segment = pattern . substring ( last , m . index ) ;
109
110
regexp = isSearch ? m [ 4 ] : m [ 4 ] || ( m [ 1 ] == '*' ? '.*' : null ) ;
110
111
typeId = regexp || defaultTypeId ;
111
- type = $types [ typeId ] || extend ( { } , $types [ defaultTypeId ] , { pattern : new RegExp ( regexp ) } ) ;
112
+ type = $$UMFP . type ( typeId ) || extend ( { } , $$UMFP . type ( defaultTypeId ) , { pattern : new RegExp ( regexp ) } ) ;
112
113
cfg = config . params [ id ] ;
113
114
return {
114
115
id : id , regexp : regexp , segment : segment , type : type , cfg : cfg
@@ -182,7 +183,7 @@ UrlMatcher.prototype.concat = function (pattern, config) {
182
183
// Because order of search parameters is irrelevant, we can add our own search
183
184
// parameters to the end of the new pattern. Parse the new pattern by itself
184
185
// and then join the bits together, but it's much easier to do this on a string level.
185
- return $$UrlMatcherFactoryProvider . compile ( this . sourcePath + pattern + this . sourceSearch , config ) ;
186
+ return $$UMFP . compile ( this . sourcePath + pattern + this . sourceSearch , config ) ;
186
187
} ;
187
188
188
189
UrlMatcher . prototype . toString = function ( ) {
@@ -322,8 +323,6 @@ UrlMatcher.prototype.format = function (values) {
322
323
return result . replace ( '//' , '/' ) ;
323
324
} ;
324
325
325
- UrlMatcher . prototype . $types = { } ;
326
-
327
326
/**
328
327
* @ngdoc object
329
328
* @name ui.router.util.type:Type
@@ -427,7 +426,6 @@ Type.prototype.$subPattern = function() {
427
426
428
427
Type . prototype . pattern = / .* / ;
429
428
430
- var $$UrlMatcherFactoryProvider ;
431
429
/**
432
430
* @ngdoc object
433
431
* @name ui.router.util.$urlMatcherFactory
@@ -437,7 +435,7 @@ var $$UrlMatcherFactoryProvider;
437
435
* is also available to providers under the name `$urlMatcherFactoryProvider`.
438
436
*/
439
437
function $UrlMatcherFactory ( ) {
440
- $$UrlMatcherFactoryProvider = this ;
438
+ $$UMFP = this ;
441
439
442
440
var isCaseInsensitive = false , isStrictMode = true ;
443
441
@@ -456,7 +454,7 @@ function $UrlMatcherFactory() {
456
454
}
457
455
}
458
456
459
- var enqueue = true , typeQueue = [ ] , injector , defaultTypes = {
457
+ var $types , enqueue = true , typeQueue = [ ] , injector , defaultTypes = {
460
458
"searchParam" : {
461
459
encode : normalizeStringOrArray ,
462
460
decode : normalizeStringOrArray ,
@@ -707,7 +705,10 @@ function $UrlMatcherFactory() {
707
705
* </pre>
708
706
*/
709
707
this . type = function ( name , def ) {
710
- if ( ! isDefined ( def ) ) return UrlMatcher . prototype . $types [ name ] ;
708
+ if ( ! isDefined ( def ) ) {
709
+ if ( ! isDefined ( $types ) ) throw new Error ( "Please wait until runtime to retrieve types." ) ;
710
+ return $types [ name ] ;
711
+ }
711
712
typeQueue . push ( { name : name , def : def } ) ;
712
713
if ( ! enqueue ) flushTypeQueue ( ) ;
713
714
return this ;
@@ -717,11 +718,11 @@ function $UrlMatcherFactory() {
717
718
this . $get = [ '$injector' , function ( $injector ) {
718
719
injector = $injector ;
719
720
enqueue = false ;
720
- UrlMatcher . prototype . $types = { } ;
721
+ $types = { } ;
721
722
flushTypeQueue ( ) ;
722
723
723
724
forEach ( defaultTypes , function ( type , name ) {
724
- if ( ! UrlMatcher . prototype . $types [ name ] ) UrlMatcher . prototype . $types [ name ] = new Type ( type ) ;
725
+ if ( ! $types [ name ] ) $types [ name ] = new Type ( type ) ;
725
726
} ) ;
726
727
return this ;
727
728
} ] ;
@@ -731,11 +732,11 @@ function $UrlMatcherFactory() {
731
732
// before actually wiring up and assigning type definitions
732
733
function flushTypeQueue ( ) {
733
734
forEach ( typeQueue , function ( type ) {
734
- if ( UrlMatcher . prototype . $types [ type . name ] ) {
735
+ if ( $types [ type . name ] ) {
735
736
throw new Error ( "A type named '" + type . name + "' has already been defined." ) ;
736
737
}
737
738
var def = new Type ( isInjectable ( type . def ) ? injector . invoke ( type . def ) : type . def ) ;
738
- UrlMatcher . prototype . $types [ type . name ] = def ;
739
+ $types [ type . name ] = def ;
739
740
} ) ;
740
741
}
741
742
@@ -758,7 +759,7 @@ function $UrlMatcherFactory() {
758
759
function getType ( config , urlType ) {
759
760
if ( config . type && urlType ) throw new Error ( "Param '" + id + "' has two type configurations." ) ;
760
761
if ( urlType ) return urlType ;
761
- if ( ! config . type ) return UrlMatcher . prototype . $types . pathParam ;
762
+ if ( ! config . type ) return $types . pathParam ;
762
763
return config . type instanceof Type ? config . type : new Type ( config . type ) ;
763
764
}
764
765
0 commit comments