This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree 2 files changed +20
-2
lines changed
2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -137,9 +137,18 @@ interface Zone {
137
137
* [ZoneSpec.properties] to configure the set of properties associated with the current zone.
138
138
*
139
139
* @param key The key to retrieve.
140
- * @returns {any } Tha value for the key, or `undefined` if not found.
140
+ * @returns {any } The value for the key, or `undefined` if not found.
141
141
*/
142
142
get ( key : string ) : any ;
143
+ /**
144
+ * Returns a Zone which defines a `key`.
145
+ *
146
+ * Recursively search the parent Zone until a Zone which has a property `key` is found.
147
+ *
148
+ * @param key The key to use for identification of the returned zone.
149
+ * @returns {Zone } The Zone which defines the `key`, `null` if not found.
150
+ */
151
+ getZoneWith ( key : string ) : Zone ;
143
152
/**
144
153
* Used to create a child zone.
145
154
*
@@ -520,13 +529,19 @@ const Zone: ZoneType = (function(global: any) {
520
529
}
521
530
522
531
public get ( key : string ) : any {
532
+ const zone : Zone = this . getZoneWith ( key ) as Zone ;
533
+ if ( zone ) return zone . _properties [ key ] ;
534
+ }
535
+
536
+ public getZoneWith ( key : string ) : AmbientZone {
523
537
let current : Zone = this ;
524
538
while ( current ) {
525
539
if ( current . _properties . hasOwnProperty ( key ) ) {
526
- return current . _properties [ key ] ;
540
+ return current ;
527
541
}
528
542
current = current . _parent ;
529
543
}
544
+ return null ;
530
545
}
531
546
532
547
public fork ( zoneSpec : ZoneSpec ) : AmbientZone {
Original file line number Diff line number Diff line change @@ -60,9 +60,12 @@ describe('Zone', function () {
60
60
it ( 'should store properties' , function ( ) {
61
61
var testZone = Zone . current . fork ( { name : 'A' , properties : { key : 'value' } } ) ;
62
62
expect ( testZone . get ( 'key' ) ) . toEqual ( 'value' ) ;
63
+ expect ( testZone . getZoneWith ( 'key' ) ) . toEqual ( testZone ) ;
63
64
var childZone = testZone . fork ( { name : 'B' , properties : { key : 'override' } } ) ;
64
65
expect ( testZone . get ( 'key' ) ) . toEqual ( 'value' ) ;
66
+ expect ( testZone . getZoneWith ( 'key' ) ) . toEqual ( testZone ) ;
65
67
expect ( childZone . get ( 'key' ) ) . toEqual ( 'override' ) ;
68
+ expect ( childZone . getZoneWith ( 'key' ) ) . toEqual ( childZone ) ;
66
69
} ) ;
67
70
} ) ;
68
71
You can’t perform that action at this time.
0 commit comments