@@ -8,13 +8,12 @@ export class NgZoneError {
88}
99
1010
11- export class NgZoneImpl implements ZoneSpec {
11+ export class NgZoneImpl {
1212 static isInAngularZone ( ) : boolean { return Zone . current . get ( 'isAngularZone' ) === true ; }
1313
14- public name : string = 'angular' ;
15- public properties : { [ k : string ] : string } = < any > { 'isAngularZone' : true } ;
16-
14+ /** @internal */
1715 private outer : Zone ;
16+ /** @internal */
1817 private inner : Zone ;
1918
2019 private onEnter : ( ) => void ;
@@ -37,60 +36,64 @@ export class NgZoneImpl implements ZoneSpec {
3736 this . setMacrotask = setMacrotask ;
3837 this . onError = onError ;
3938
40- if ( global . Zone ) {
39+ if ( Zone ) {
4140 this . outer = this . inner = Zone . current ;
4241 if ( Zone [ 'wtfZoneSpec' ] ) {
4342 this . inner = this . inner . fork ( Zone [ 'wtfZoneSpec' ] ) ;
4443 }
4544 if ( trace ) {
4645 this . inner = this . inner . fork ( Zone [ 'longStackTraceZoneSpec' ] ) ;
4746 }
48- this . inner = this . inner . fork ( this ) ;
49- } else {
50- throw new Error ( 'Angular2 needs to be run with Zone.js polyfill.' ) ;
51- }
52- }
47+ this . inner = this . inner . fork ( {
48+ name : 'angular' ,
49+ properties :< any > { 'isAngularZone' : true } ,
50+ onInvokeTask : ( delegate : ZoneDelegate , current : Zone , target : Zone , task : Task ,
51+ applyThis : any , applyArgs : any ) : any => {
52+ try {
53+ this . onEnter ( ) ;
54+ return delegate . invokeTask ( target , task , applyThis , applyArgs ) ;
55+ } finally {
56+ this . onLeave ( ) ;
57+ }
58+ } ,
5359
54- onInvokeTask ( delegate : ZoneDelegate , current : Zone , target : Zone , task : Task , applyThis : any ,
55- applyArgs : any ) : any {
56- try {
57- this . onEnter ( ) ;
58- return delegate . invokeTask ( target , task , applyThis , applyArgs ) ;
59- } finally {
60- this . onLeave ( ) ;
61- }
62- } ;
6360
61+ onInvoke : ( delegate : ZoneDelegate , current : Zone , target : Zone , callback : Function ,
62+ applyThis : any , applyArgs : any [ ] , source : string ) : any => {
63+ try {
64+ this . onEnter ( ) ;
65+ return delegate . invoke ( target , callback , applyThis , applyArgs , source ) ;
66+ } finally {
67+ this . onLeave ( ) ;
68+ }
69+ } ,
6470
65- onInvoke ( delegate : ZoneDelegate , current : Zone , target : Zone , callback : Function , applyThis : any ,
66- applyArgs : any [ ] , source : string ) : any {
67- try {
68- this . onEnter ( ) ;
69- return delegate . invoke ( target , callback , applyThis , applyArgs , source ) ;
70- } finally {
71- this . onLeave ( ) ;
72- }
73- }
71+ onHasTask :
72+ ( delegate : ZoneDelegate , current : Zone , target : Zone , hasTaskState : HasTaskState ) => {
73+ delegate . hasTask ( target , hasTaskState ) ;
74+ if ( current == target ) {
75+ // We are only interested in hasTask events which originate from our zone
76+ // (A child hasTask event is not interesting to us)
77+ if ( hasTaskState . change == 'microTask' ) {
78+ this . setMicrotask ( hasTaskState . microTask ) ;
79+ } else if ( hasTaskState . change == 'macroTask' ) {
80+ this . setMacrotask ( hasTaskState . macroTask ) ;
81+ }
82+ }
83+ } ,
7484
75- onHasTask ( delegate : ZoneDelegate , current : Zone , target : Zone , hasTaskState : HasTaskState ) {
76- delegate . hasTask ( target , hasTaskState ) ;
77- if ( current == target ) {
78- // We are only interested in hasTask events which originate from our zone
79- // (A child hasTask event is not interesting to us)
80- if ( hasTaskState . change == 'microTask' ) {
81- this . setMicrotask ( hasTaskState . microTask ) ;
82- } else if ( hasTaskState . change == 'macroTask' ) {
83- this . setMacrotask ( hasTaskState . macroTask ) ;
84- }
85+ onHandleError : ( delegate : ZoneDelegate , current : Zone , target : Zone , error : any ) :
86+ boolean => {
87+ delegate . handleError ( target , error ) ;
88+ this . onError ( new NgZoneError ( error , error . stack ) ) ;
89+ return false ;
90+ }
91+ } ) ;
92+ } else {
93+ throw new Error ( 'Angular2 needs to be run with Zone.js polyfill.' ) ;
8594 }
8695 }
8796
88- onHandleError ( delegate : ZoneDelegate , current : Zone , target : Zone , error : any ) : boolean {
89- delegate . handleError ( target , error ) ;
90- this . onError ( new NgZoneError ( error , error . stack ) ) ;
91- return false ;
92- }
93-
9497 runInner ( fn : ( ) => any ) : any { return this . inner . runGuarded ( fn ) ; } ;
9598 runOuter ( fn : ( ) => any ) : any { return this . outer . run ( fn ) ; } ;
9699}
0 commit comments