@@ -18,20 +18,19 @@ export function xhrImpl(url, { method, headers, body, onNext, onError, onComplet
18
18
19
19
const patchResolver = new PatchResolver ( { onResponse : r => onNext ( r ) } ) ;
20
20
21
- function onProgressEvent ( ) {
22
- if ( isDeferred ) {
23
- const chunk = xhr . response . substr ( index ) ;
24
- patchResolver . handleChunk ( chunk ) ;
25
- index = xhr . responseText . length ;
26
- }
27
- }
28
-
29
21
function onReadyStateChange ( ) {
30
22
if ( this . readyState === this . HEADERS_RECEIVED ) {
31
23
const contentType = xhr . getResponseHeader ( 'Content-Type' ) ;
32
24
if ( contentType . indexOf ( 'multipart/mixed' ) >= 0 ) {
33
25
isDeferred = true ;
34
26
}
27
+ } else if (
28
+ ( this . readyState === this . LOADING || this . readyState === this . DONE ) &&
29
+ isDeferred
30
+ ) {
31
+ const chunk = xhr . response . substr ( index ) ;
32
+ patchResolver . handleChunk ( chunk ) ;
33
+ index = xhr . responseText . length ;
35
34
} else if ( this . readyState === this . DONE && ! isDeferred ) {
36
35
onNext ( JSON . parse ( xhr . response ) ) ;
37
36
onComplete ( ) ;
@@ -57,7 +56,6 @@ export function xhrImpl(url, { method, headers, body, onNext, onError, onComplet
57
56
}
58
57
59
58
xhr . addEventListener ( 'readystatechange' , onReadyStateChange ) ;
60
- xhr . addEventListener ( 'progress' , onProgressEvent ) ;
61
59
xhr . addEventListener ( 'loaded' , onLoadEvent ) ;
62
60
xhr . addEventListener ( 'error' , onErrorEvent ) ;
63
61
xhr . send ( body ) ;
0 commit comments