Przeglądaj źródła

Change XMLHttpRequest event trigger timing

Ben Hsieh 8 lat temu
rodzic
commit
f19773f60a

+ 2
- 1
src/polyfill/Blob.js Wyświetl plik

6
 import fs from '../fs.js'
6
 import fs from '../fs.js'
7
 import getUUID from '../utils/uuid'
7
 import getUUID from '../utils/uuid'
8
 import Log from '../utils/log.js'
8
 import Log from '../utils/log.js'
9
+import EventTarget from './EventTarget'
9
 
10
 
10
 const log = new Log('Blob')
11
 const log = new Log('Blob')
11
 const blobCacheDir = fs.dirs.DocumentDir + '/RNFetchBlob-blobs/'
12
 const blobCacheDir = fs.dirs.DocumentDir + '/RNFetchBlob-blobs/'
16
  * A RNFetchBlob style Blob polyfill class, this is a Blob which compatible to
17
  * A RNFetchBlob style Blob polyfill class, this is a Blob which compatible to
17
  * Response object attain fron RNFetchBlob.fetch.
18
  * Response object attain fron RNFetchBlob.fetch.
18
  */
19
  */
19
-export default class Blob {
20
+export default class Blob extends EventTarget {
20
 
21
 
21
   cacheName:string;
22
   cacheName:string;
22
   type:string;
23
   type:string;

+ 4
- 2
src/polyfill/File.js Wyświetl plik

7
 
7
 
8
 export default class File extends Blob {
8
 export default class File extends Blob {
9
 
9
 
10
-  constructor() {
11
-    super()
10
+  name : string = '';
11
+
12
+  constructor(data:any , cType:string) {
13
+    super(data, cType)
12
   }
14
   }
13
 
15
 
14
 }
16
 }

+ 3
- 2
src/polyfill/XMLHttpRequest.js Wyświetl plik

123
     else if(typeof body === 'object') {
123
     else if(typeof body === 'object') {
124
       body = JSON.stringify(body)
124
       body = JSON.stringify(body)
125
     }
125
     }
126
+    else
127
+      body = body.toString()
126
 
128
 
127
     this._task = RNFetchBlob
129
     this._task = RNFetchBlob
128
                   .config({ auto: true, timeout : this._timeout })
130
                   .config({ auto: true, timeout : this._timeout })
208
   _headerReceived(e) {
210
   _headerReceived(e) {
209
     log.verbose('header received ', this._task.taskId, e)
211
     log.verbose('header received ', this._task.taskId, e)
210
     this.responseURL = this._url
212
     this.responseURL = this._url
211
-    this.upload.dispatchEvent('loadend')
212
-    this.dispatchEvent('load')
213
     if(e.state === "2") {
213
     if(e.state === "2") {
214
       this._responseHeaders = e.headers
214
       this._responseHeaders = e.headers
215
       this._statusText = e.status
215
       this._statusText = e.status
282
         break;
282
         break;
283
       }
283
       }
284
       this.dispatchEvent('loadend')
284
       this.dispatchEvent('loadend')
285
+      this.dispatchEvent('load')
285
       this._dispatchReadStateChange(XMLHttpRequest.DONE)
286
       this._dispatchReadStateChange(XMLHttpRequest.DONE)
286
     }
287
     }
287
     this.clearEventListeners()
288
     this.clearEventListeners()

+ 1
- 1
src/polyfill/index.js Wyświetl plik

5
 import ProgressEvent from './ProgressEvent'
5
 import ProgressEvent from './ProgressEvent'
6
 
6
 
7
 export default {
7
 export default {
8
-  Blob, File, XMLHttpRequest, FormData, ProgressEvent
8
+  Blob, File, XMLHttpRequest, FormData, ProgressEvent, Event
9
 }
9
 }