Skip to content

Commit

Permalink
fix fetch BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
RubyLouvre committed Aug 30, 2016
1 parent 6055905 commit 1977e09
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
22 changes: 13 additions & 9 deletions dist/index.js
Expand Up @@ -4,9 +4,9 @@
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["avalon"] = factory();
exports["fetch"] = factory();
else
root["avalon"] = factory();
root["fetch"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
Expand Down Expand Up @@ -135,7 +135,7 @@ return /******/ (function(modules) { // webpackBootstrap
reject(new TypeError('Network request failed'))
})
xhr.on('timeout', function () {
reject(new TypeError('Network request failed'))
reject(new TypeError('Network request timeout'))
})

xhr.open(request.method, request.url, true)
Expand Down Expand Up @@ -166,7 +166,7 @@ return /******/ (function(modules) { // webpackBootstrap
function Request(input, options) {
options = options || {}
var body = options.body
if (Request instanceof input) {
if (input instanceof Request) {
if (input.bodyUsed) {
throw new TypeError('Already read')
}
Expand All @@ -189,7 +189,7 @@ return /******/ (function(modules) { // webpackBootstrap
if (options.headers || !this.headers) {
this.headers = new Headers(options.headers)
}
this.method = (options.method || this.method || 'GET').upperCase()
this.method = (options.method || this.method || 'GET').toUpperCase()
this.mode = options.mode || this.mode || null
this.referrer = null

Expand All @@ -203,7 +203,9 @@ return /******/ (function(modules) { // webpackBootstrap
return new Request(this)
}

Body.call(Request.prototype)
var F = function(){}
F.prototype = Body.prototype
Request.prototype = new F()

module.exports = Request

Expand Down Expand Up @@ -394,7 +396,7 @@ return /******/ (function(modules) { // webpackBootstrap
} else if (map[to] && map[to][from]) {
return map[to][from](body)
} else {
return Promise.reject(new Error('Convertion from ' + from + '} to ' + to + ' not supported'))
return Promise.reject(new Error('Convertion from ' + from + ' to ' + to + ' not supported'))
}
}

Expand Down Expand Up @@ -533,7 +535,9 @@ return /******/ (function(modules) { // webpackBootstrap
this._initBody(bodyInit)
}

Body.call(Response.prototype)
var F = function(){}
F.prototype = Body.prototype
Response.prototype = new F()

Response.prototype.clone = function () {
return new Response(this._bodyInit, {
Expand Down Expand Up @@ -618,7 +622,7 @@ return /******/ (function(modules) { // webpackBootstrap
}
}


module.exports = Transport

/***/ },
/* 7 */
Expand Down
8 changes: 5 additions & 3 deletions src/Request.js
Expand Up @@ -4,7 +4,7 @@ var Body = require('./Body')
function Request(input, options) {
options = options || {}
var body = options.body
if (Request instanceof input) {
if (input instanceof Request) {
if (input.bodyUsed) {
throw new TypeError('Already read')
}
Expand All @@ -27,7 +27,7 @@ function Request(input, options) {
if (options.headers || !this.headers) {
this.headers = new Headers(options.headers)
}
this.method = (options.method || this.method || 'GET').upperCase()
this.method = (options.method || this.method || 'GET').toUpperCase()
this.mode = options.mode || this.mode || null
this.referrer = null

Expand All @@ -41,6 +41,8 @@ Request.prototype.clone = function () {
return new Request(this)
}

Body.call(Request.prototype)
var F = function(){}
F.prototype = Body.prototype
Request.prototype = new F()

module.exports = Request
4 changes: 3 additions & 1 deletion src/Response.js
Expand Up @@ -19,7 +19,9 @@ function Response(bodyInit, options) {
this._initBody(bodyInit)
}

Body.call(Response.prototype)
var F = function(){}
F.prototype = Body.prototype
Response.prototype = new F()

Response.prototype.clone = function () {
return new Response(this._bodyInit, {
Expand Down
1 change: 1 addition & 0 deletions src/Transport.js
Expand Up @@ -50,3 +50,4 @@ p.abort = function () {
}
}

module.exports = Transport
2 changes: 1 addition & 1 deletion src/fetch.js
Expand Up @@ -79,7 +79,7 @@ function fetch(input, init) {
reject(new TypeError('Network request failed'))
})
xhr.on('timeout', function () {
reject(new TypeError('Network request failed'))
reject(new TypeError('Network request timeout'))
})

xhr.open(request.method, request.url, true)
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Expand Up @@ -16,7 +16,7 @@ module.exports = {
path: path.join(__dirname, 'dist'),
filename: 'index.js',
libraryTarget: 'umd',
library: 'avalon'
library: 'fetch'
}, //页面引用的文件
resolve: {
extensions: ['.js', ''],
Expand Down

0 comments on commit 1977e09

Please sign in to comment.