File tree 2 files changed +22
-2
lines changed
2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ patchXHR(_global);
48
48
49
49
const XHR_TASK = zoneSymbol ( 'xhrTask' ) ;
50
50
const XHR_SYNC = zoneSymbol ( 'xhrSync' ) ;
51
+ const XHR_LISTENER = zoneSymbol ( 'xhrListener' ) ;
51
52
52
53
interface XHROptions extends TaskData {
53
54
target : any ;
@@ -63,13 +64,20 @@ function patchXHR(window: any) {
63
64
64
65
function scheduleTask ( task : Task ) {
65
66
var data = < XHROptions > task . data ;
66
- data . target . addEventListener ( 'readystatechange' , ( ) => {
67
+ // remove existing event listener
68
+ var listener = data . target [ XHR_LISTENER ] ;
69
+ if ( listener ) {
70
+ data . target . removeEventListener ( 'readystatechange' , listener ) ;
71
+ }
72
+ var newListener = data . target [ XHR_LISTENER ] = ( ) => {
67
73
if ( data . target . readyState === data . target . DONE ) {
68
74
if ( ! data . aborted ) {
69
75
task . invoke ( ) ;
70
76
}
71
77
}
72
- } ) ;
78
+ } ;
79
+ data . target . addEventListener ( 'readystatechange' , newListener ) ;
80
+
73
81
var storedTask : Task = data . target [ XHR_TASK ] ;
74
82
if ( ! storedTask ) {
75
83
data . target [ XHR_TASK ] = task ;
Original file line number Diff line number Diff line change @@ -182,4 +182,16 @@ describe('XMLHttpRequest', function() {
182
182
expect ( XMLHttpRequest . LOADING ) . toEqual ( 3 ) ;
183
183
expect ( XMLHttpRequest . DONE ) . toEqual ( 4 ) ;
184
184
} ) ;
185
+
186
+ it ( 'should work properly when send request multiple times on single xmlRequest instance' , function ( ) {
187
+ testZone . run ( function ( ) {
188
+ var req = new XMLHttpRequest ( ) ;
189
+ req . open ( 'get' , '/' , true ) ;
190
+ req . send ( ) ;
191
+ req . onloadend = function ( ) {
192
+ req . open ( 'get' , '/' , true ) ;
193
+ req . send ( ) ;
194
+ }
195
+ } ) ;
196
+ } )
185
197
} ) ;
You can’t perform that action at this time.
0 commit comments