12
12
13
13
import { findEventTasks } from '../common/events' ;
14
14
import { patchTimer } from '../common/timers' ;
15
- import { bindArguments , patchClass , patchMacroTask , patchMethod , patchOnProperties , patchPrototype , scheduleMacroTaskWithCurrentZone , ZONE_SYMBOL_ADD_EVENT_LISTENER , ZONE_SYMBOL_REMOVE_EVENT_LISTENER , zoneSymbol } from '../common/utils' ;
15
+ import { bindArguments , generateUnPatchAndRePatch , patchClass , patchMacroTask , patchMethod , patchOnProperties , patchPrototype , scheduleMacroTaskWithCurrentZone , ZONE_SYMBOL_ADD_EVENT_LISTENER , ZONE_SYMBOL_REMOVE_EVENT_LISTENER , zoneSymbol } from '../common/utils' ;
16
16
17
17
import { propertyPatch } from './define-property' ;
18
18
import { eventTargetPatch , patchEvent } from './event-target' ;
@@ -23,23 +23,30 @@ Zone.__load_patch('util', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
23
23
api . patchOnProperties = patchOnProperties ;
24
24
api . patchMethod = patchMethod ;
25
25
api . bindArguments = bindArguments ;
26
+ api . generateUnPatchAndRePatch = generateUnPatchAndRePatch ;
27
+ return undefined ;
26
28
} ) ;
27
29
28
- Zone . __load_patch ( 'timers' , ( global : any ) => {
29
- const set = 'set' ;
30
- const clear = ' clear';
31
- patchTimer ( global , set , clear , 'Timeout' ) ;
32
- patchTimer ( global , set , clear , 'Interval' ) ;
33
- patchTimer ( global , set , clear , 'Immediate' ) ;
30
+ Zone . __load_patch ( 'timers' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
31
+ const timerMethods = [ 'Timeout' , 'Interval' , 'Immediate' ] ;
32
+ timerMethods . forEach ( m => patchTimer ( global , 'set' , ' clear', m ) ) ;
33
+ const timerMethodsWithPrefix =
34
+ timerMethods . map ( m => ' set' + m ) . concat ( timerMethods . map ( m => 'clear' + m ) ) ;
35
+ return api . generateUnPatchAndRePatch ( [ { target : global , methods : timerMethodsWithPrefix } ] ) ;
34
36
} ) ;
35
37
36
- Zone . __load_patch ( 'requestAnimationFrame' , ( global : any ) => {
38
+ Zone . __load_patch ( 'requestAnimationFrame' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
39
+ const methodsToPatch = [
40
+ 'requestAnimationFrame' , 'cancelAnimationFrame' , 'mozRequestAnimationFrame' ,
41
+ 'mozCancelAnimationFrame' , 'webkitRequestAnimationFrame' , 'webkitCancelAnimationFrame'
42
+ ] ;
37
43
patchTimer ( global , 'request' , 'cancel' , 'AnimationFrame' ) ;
38
44
patchTimer ( global , 'mozRequest' , 'mozCancel' , 'AnimationFrame' ) ;
39
45
patchTimer ( global , 'webkitRequest' , 'webkitCancel' , 'AnimationFrame' ) ;
46
+ return api . generateUnPatchAndRePatch ( [ { target : global , methods : methodsToPatch } ] ) ;
40
47
} ) ;
41
48
42
- Zone . __load_patch ( 'blocking' , ( global : any , Zone : ZoneType ) => {
49
+ Zone . __load_patch ( 'blocking' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
43
50
const blockingMethods = [ 'alert' , 'prompt' , 'confirm' ] ;
44
51
for ( let i = 0 ; i < blockingMethods . length ; i ++ ) {
45
52
const name = blockingMethods [ i ] ;
@@ -49,6 +56,7 @@ Zone.__load_patch('blocking', (global: any, Zone: ZoneType) => {
49
56
} ;
50
57
} ) ;
51
58
}
59
+ return api . generateUnPatchAndRePatch ( [ { target : global , methods : blockingMethods } ] ) ;
52
60
} ) ;
53
61
54
62
Zone . __load_patch ( 'EventTarget' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
@@ -59,15 +67,31 @@ Zone.__load_patch('EventTarget', (global: any, Zone: ZoneType, api: _ZonePrivate
59
67
}
60
68
61
69
patchEvent ( global , api ) ;
62
- eventTargetPatch ( global , api ) ;
70
+ const apiTypes : any [ ] = eventTargetPatch ( global , api ) ;
63
71
// patch XMLHttpRequestEventTarget's addEventListener/removeEventListener
64
72
const XMLHttpRequestEventTarget = ( global as any ) [ 'XMLHttpRequestEventTarget' ] ;
65
73
if ( XMLHttpRequestEventTarget && XMLHttpRequestEventTarget . prototype ) {
66
74
api . patchEventTarget ( global , [ XMLHttpRequestEventTarget . prototype ] ) ;
67
75
}
76
+ const methods = [ 'addEventListener' , 'removeEventListener' ] ;
77
+ return api . generateUnPatchAndRePatch (
78
+ apiTypes . filter ( apiType => ! ! apiType )
79
+ . map ( apiType => {
80
+ return { target : apiType , methods : methods } ;
81
+ } )
82
+ . concat (
83
+ typeof Event !== 'undefined' ?
84
+ [ { target : Event . prototype , methods : [ 'stopImmediatePropagation' ] } ] :
85
+ [ ] ) ) ;
86
+ } ) ;
87
+
88
+ Zone . __load_patch ( 'Observer' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
68
89
patchClass ( 'MutationObserver' ) ;
69
90
patchClass ( 'WebKitMutationObserver' ) ;
70
91
patchClass ( 'IntersectionObserver' ) ;
92
+ } ) ;
93
+
94
+ Zone . __load_patch ( 'FileReader' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
71
95
patchClass ( 'FileReader' ) ;
72
96
} ) ;
73
97
0 commit comments