fetch-observable
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -63,6 +63,2 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var _isomorphicFetch = __webpack_require__(3); | ||
var _isomorphicFetch2 = _interopRequireDefault(_isomorphicFetch); | ||
var _PausableObservable = __webpack_require__(2); | ||
@@ -74,9 +70,7 @@ | ||
/** | ||
* @copyright © 2015, Rick Wong. All rights reserved. | ||
*/ | ||
function isString(thing) { | ||
return typeof thing === "string"; | ||
} | ||
} /** | ||
* @copyright © 2015, Rick Wong. All rights reserved. | ||
*/ | ||
@@ -641,3 +635,3 @@ function isFunction(thing) { | ||
})(); | ||
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()), __webpack_require__(4))) | ||
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()), __webpack_require__(3))) | ||
@@ -757,14 +751,2 @@ /***/ }, | ||
/* 3 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
// the whatwg-fetch polyfill installs the fetch() function | ||
// on the global object (window or self) | ||
// | ||
// Return that as the export for use in Webpack, Browserify etc. | ||
__webpack_require__(5); | ||
module.exports = self.fetch.bind(self); | ||
/***/ }, | ||
/* 4 */ | ||
/***/ function(module, exports) { | ||
@@ -865,389 +847,2 @@ | ||
/***/ }, | ||
/* 5 */ | ||
/***/ function(module, exports) { | ||
(function() { | ||
'use strict'; | ||
if (self.fetch) { | ||
return | ||
} | ||
function normalizeName(name) { | ||
if (typeof name !== 'string') { | ||
name = String(name) | ||
} | ||
if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) { | ||
throw new TypeError('Invalid character in header field name') | ||
} | ||
return name.toLowerCase() | ||
} | ||
function normalizeValue(value) { | ||
if (typeof value !== 'string') { | ||
value = String(value) | ||
} | ||
return value | ||
} | ||
function Headers(headers) { | ||
this.map = {} | ||
if (headers instanceof Headers) { | ||
headers.forEach(function(value, name) { | ||
this.append(name, value) | ||
}, this) | ||
} else if (headers) { | ||
Object.getOwnPropertyNames(headers).forEach(function(name) { | ||
this.append(name, headers[name]) | ||
}, this) | ||
} | ||
} | ||
Headers.prototype.append = function(name, value) { | ||
name = normalizeName(name) | ||
value = normalizeValue(value) | ||
var list = this.map[name] | ||
if (!list) { | ||
list = [] | ||
this.map[name] = list | ||
} | ||
list.push(value) | ||
} | ||
Headers.prototype['delete'] = function(name) { | ||
delete this.map[normalizeName(name)] | ||
} | ||
Headers.prototype.get = function(name) { | ||
var values = this.map[normalizeName(name)] | ||
return values ? values[0] : null | ||
} | ||
Headers.prototype.getAll = function(name) { | ||
return this.map[normalizeName(name)] || [] | ||
} | ||
Headers.prototype.has = function(name) { | ||
return this.map.hasOwnProperty(normalizeName(name)) | ||
} | ||
Headers.prototype.set = function(name, value) { | ||
this.map[normalizeName(name)] = [normalizeValue(value)] | ||
} | ||
Headers.prototype.forEach = function(callback, thisArg) { | ||
Object.getOwnPropertyNames(this.map).forEach(function(name) { | ||
this.map[name].forEach(function(value) { | ||
callback.call(thisArg, value, name, this) | ||
}, this) | ||
}, this) | ||
} | ||
function consumed(body) { | ||
if (body.bodyUsed) { | ||
return Promise.reject(new TypeError('Already read')) | ||
} | ||
body.bodyUsed = true | ||
} | ||
function fileReaderReady(reader) { | ||
return new Promise(function(resolve, reject) { | ||
reader.onload = function() { | ||
resolve(reader.result) | ||
} | ||
reader.onerror = function() { | ||
reject(reader.error) | ||
} | ||
}) | ||
} | ||
function readBlobAsArrayBuffer(blob) { | ||
var reader = new FileReader() | ||
reader.readAsArrayBuffer(blob) | ||
return fileReaderReady(reader) | ||
} | ||
function readBlobAsText(blob) { | ||
var reader = new FileReader() | ||
reader.readAsText(blob) | ||
return fileReaderReady(reader) | ||
} | ||
var support = { | ||
blob: 'FileReader' in self && 'Blob' in self && (function() { | ||
try { | ||
new Blob(); | ||
return true | ||
} catch(e) { | ||
return false | ||
} | ||
})(), | ||
formData: 'FormData' in self, | ||
arrayBuffer: 'ArrayBuffer' in self | ||
} | ||
function Body() { | ||
this.bodyUsed = false | ||
this._initBody = function(body) { | ||
this._bodyInit = body | ||
if (typeof body === 'string') { | ||
this._bodyText = body | ||
} else if (support.blob && Blob.prototype.isPrototypeOf(body)) { | ||
this._bodyBlob = body | ||
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) { | ||
this._bodyFormData = body | ||
} else if (!body) { | ||
this._bodyText = '' | ||
} else if (support.arrayBuffer && ArrayBuffer.prototype.isPrototypeOf(body)) { | ||
// Only support ArrayBuffers for POST method. | ||
// Receiving ArrayBuffers happens via Blobs, instead. | ||
} else { | ||
throw new Error('unsupported BodyInit type') | ||
} | ||
} | ||
if (support.blob) { | ||
this.blob = function() { | ||
var rejected = consumed(this) | ||
if (rejected) { | ||
return rejected | ||
} | ||
if (this._bodyBlob) { | ||
return Promise.resolve(this._bodyBlob) | ||
} else if (this._bodyFormData) { | ||
throw new Error('could not read FormData body as blob') | ||
} else { | ||
return Promise.resolve(new Blob([this._bodyText])) | ||
} | ||
} | ||
this.arrayBuffer = function() { | ||
return this.blob().then(readBlobAsArrayBuffer) | ||
} | ||
this.text = function() { | ||
var rejected = consumed(this) | ||
if (rejected) { | ||
return rejected | ||
} | ||
if (this._bodyBlob) { | ||
return readBlobAsText(this._bodyBlob) | ||
} else if (this._bodyFormData) { | ||
throw new Error('could not read FormData body as text') | ||
} else { | ||
return Promise.resolve(this._bodyText) | ||
} | ||
} | ||
} else { | ||
this.text = function() { | ||
var rejected = consumed(this) | ||
return rejected ? rejected : Promise.resolve(this._bodyText) | ||
} | ||
} | ||
if (support.formData) { | ||
this.formData = function() { | ||
return this.text().then(decode) | ||
} | ||
} | ||
this.json = function() { | ||
return this.text().then(JSON.parse) | ||
} | ||
return this | ||
} | ||
// HTTP methods whose capitalization should be normalized | ||
var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'] | ||
function normalizeMethod(method) { | ||
var upcased = method.toUpperCase() | ||
return (methods.indexOf(upcased) > -1) ? upcased : method | ||
} | ||
function Request(input, options) { | ||
options = options || {} | ||
var body = options.body | ||
if (Request.prototype.isPrototypeOf(input)) { | ||
if (input.bodyUsed) { | ||
throw new TypeError('Already read') | ||
} | ||
this.url = input.url | ||
this.credentials = input.credentials | ||
if (!options.headers) { | ||
this.headers = new Headers(input.headers) | ||
} | ||
this.method = input.method | ||
this.mode = input.mode | ||
if (!body) { | ||
body = input._bodyInit | ||
input.bodyUsed = true | ||
} | ||
} else { | ||
this.url = input | ||
} | ||
this.credentials = options.credentials || this.credentials || 'omit' | ||
if (options.headers || !this.headers) { | ||
this.headers = new Headers(options.headers) | ||
} | ||
this.method = normalizeMethod(options.method || this.method || 'GET') | ||
this.mode = options.mode || this.mode || null | ||
this.referrer = null | ||
if ((this.method === 'GET' || this.method === 'HEAD') && body) { | ||
throw new TypeError('Body not allowed for GET or HEAD requests') | ||
} | ||
this._initBody(body) | ||
} | ||
Request.prototype.clone = function() { | ||
return new Request(this) | ||
} | ||
function decode(body) { | ||
var form = new FormData() | ||
body.trim().split('&').forEach(function(bytes) { | ||
if (bytes) { | ||
var split = bytes.split('=') | ||
var name = split.shift().replace(/\+/g, ' ') | ||
var value = split.join('=').replace(/\+/g, ' ') | ||
form.append(decodeURIComponent(name), decodeURIComponent(value)) | ||
} | ||
}) | ||
return form | ||
} | ||
function headers(xhr) { | ||
var head = new Headers() | ||
var pairs = xhr.getAllResponseHeaders().trim().split('\n') | ||
pairs.forEach(function(header) { | ||
var split = header.trim().split(':') | ||
var key = split.shift().trim() | ||
var value = split.join(':').trim() | ||
head.append(key, value) | ||
}) | ||
return head | ||
} | ||
Body.call(Request.prototype) | ||
function Response(bodyInit, options) { | ||
if (!options) { | ||
options = {} | ||
} | ||
this._initBody(bodyInit) | ||
this.type = 'default' | ||
this.status = options.status | ||
this.ok = this.status >= 200 && this.status < 300 | ||
this.statusText = options.statusText | ||
this.headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers) | ||
this.url = options.url || '' | ||
} | ||
Body.call(Response.prototype) | ||
Response.prototype.clone = function() { | ||
return new Response(this._bodyInit, { | ||
status: this.status, | ||
statusText: this.statusText, | ||
headers: new Headers(this.headers), | ||
url: this.url | ||
}) | ||
} | ||
Response.error = function() { | ||
var response = new Response(null, {status: 0, statusText: ''}) | ||
response.type = 'error' | ||
return response | ||
} | ||
var redirectStatuses = [301, 302, 303, 307, 308] | ||
Response.redirect = function(url, status) { | ||
if (redirectStatuses.indexOf(status) === -1) { | ||
throw new RangeError('Invalid status code') | ||
} | ||
return new Response(null, {status: status, headers: {location: url}}) | ||
} | ||
self.Headers = Headers; | ||
self.Request = Request; | ||
self.Response = Response; | ||
self.fetch = function(input, init) { | ||
return new Promise(function(resolve, reject) { | ||
var request | ||
if (Request.prototype.isPrototypeOf(input) && !init) { | ||
request = input | ||
} else { | ||
request = new Request(input, init) | ||
} | ||
var xhr = new XMLHttpRequest() | ||
function responseURL() { | ||
if ('responseURL' in xhr) { | ||
return xhr.responseURL | ||
} | ||
// Avoid security warnings on getResponseHeader when not allowed by CORS | ||
if (/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())) { | ||
return xhr.getResponseHeader('X-Request-URL') | ||
} | ||
return; | ||
} | ||
xhr.onload = function() { | ||
var status = (xhr.status === 1223) ? 204 : xhr.status | ||
if (status < 100 || status > 599) { | ||
reject(new TypeError('Network request failed')) | ||
return | ||
} | ||
var options = { | ||
status: status, | ||
statusText: xhr.statusText, | ||
headers: headers(xhr), | ||
url: responseURL() | ||
} | ||
var body = 'response' in xhr ? xhr.response : xhr.responseText; | ||
resolve(new Response(body, options)) | ||
} | ||
xhr.onerror = function() { | ||
reject(new TypeError('Network request failed')) | ||
} | ||
xhr.open(request.method, request.url, true) | ||
if (request.credentials === 'include') { | ||
xhr.withCredentials = true | ||
} | ||
if ('responseType' in xhr && support.blob) { | ||
xhr.responseType = 'blob' | ||
} | ||
request.headers.forEach(function(value, name) { | ||
xhr.setRequestHeader(name, value) | ||
}) | ||
xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit) | ||
}) | ||
} | ||
self.fetch.polyfill = true | ||
})(); | ||
/***/ } | ||
@@ -1254,0 +849,0 @@ /******/ ]) |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.fetchObservable=t():e.fetchObservable=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e){return"string"==typeof e}function i(e){return"function"==typeof e}function s(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=t.refreshDelay,n=void 0===r?!1:r,s=[],u=null,a=!1,c=0;(a=o(e))&&(e=[e]);var l=function p(){if(0!==s.length&&!h.paused()){var r=function(){n?u=setTimeout(p,i(n)?n(c++):n):(h.pause(),s.map(function(e){return e.complete()}),s=[])},o=e.map(function(e){return fetch(e,t)});Promise.all(o).then(function(e){s.map(function(t){return t.next(a?e[0]:e)}),r()})["catch"](function(e){s.map(function(t){return t.error(a?e[0]:e)}),r()})}},h=new f["default"](function(e){return s.push(e),s.length&&h.resume(),function(){s.splice(s.indexOf(e),1),s.length||h.pause()}},{onPause:function(){u&&(clearTimeout(u),u=null)},onResume:function(){u||l()}});return h.resume(),h}Object.defineProperty(t,"__esModule",{value:!0});var u=r(3),a=(n(u),r(2)),f=n(a);t["default"]=s},function(e,t,r){(function(e,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function i(e){Symbol[e]||Object.defineProperty(Symbol,e,{value:Symbol(e)})}function s(e){return Object.getOwnPropertyNames(e).forEach(function(t){Object.defineProperty(e,t,{enumerable:!1})}),e}function u(e,t){var r=e[t];if(null!=r){if("function"!=typeof r)throw new TypeError(r+" is not a function");return r}}function a(e){var t=e._cleanup;t&&(e._cleanup=void 0,t())}function f(e){return void 0===e._observer}function c(e){f(e)||(e._observer=void 0,a(e))}function l(e){return function(t){e.unsubscribe()}}function h(e,t){if(Object(e)!==e)throw new TypeError("Observer must be an object");var r=new p(e),n=new d(r),o=u(e,"start");if(o&&o.call(e,n),f(r))return n;try{var i=t.call(void 0,r);if(null!=i){if("function"==typeof i.unsubscribe)i=l(i);else if("function"!=typeof i)throw new TypeError(i+" is not a function");r._cleanup=i}}catch(s){return r.error(s),n}return f(r)&&a(r),n}function p(e){this._observer=e,this._cleanup=void 0}function d(e){this._observer=e}var y=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(t,"__esModule",{value:!0});var b=function(){if("undefined"!=typeof e&&"undefined"!=typeof r&&r.nextTick)return e.setImmediate?function(t){e.setImmediate(t)}:function(e){r.nextTick(e)};var t=self.MutationObserver||self.WebKitMutationObserver;if(t){var n=function(){var e=document.createElement("div"),r=function(t){return e.classList.toggle("x")},n=[],o=new t(function(e){for(n.length>1&&r();n.length>0;)n.shift()()});return o.observe(e,{attributes:!0}),{v:function(e){n.push(e),1===n.length&&r()}}}();if("object"===("undefined"==typeof n?"undefined":o(n)))return n.v}return function(e){setTimeout(e,0)}}();i("observable"),p.prototype=s({get closed(){return f(this)},next:function(e){if(!f(this)){var t=this._observer;try{var r=u(t,"next");if(!r)return;return r.call(t,e)}catch(n){try{c(this)}finally{throw n}}}},error:function(e){if(f(this))throw e;var t=this._observer;this._observer=void 0;try{var r=u(t,"error");if(!r)throw e;e=r.call(t,e)}catch(n){try{a(this)}finally{throw n}}return a(this),e},complete:function(e){if(!f(this)){var t=this._observer;this._observer=void 0;try{var r=u(t,"complete");e=r?r.call(t,e):void 0}catch(n){try{a(this)}finally{throw n}}return a(this),e}}}),d.prototype=s({unsubscribe:function(){c(this._observer)}});t.Observable=function(){function e(t){if(n(this,e),"function"!=typeof t)throw new TypeError("Observable initializer must be a function");this._subscriber=t}return y(e,[{key:"subscribe",value:function(e){return h(e,this._subscriber)}},{key:"forEach",value:function(e){var t=this;return new Promise(function(r,n){if("function"!=typeof e)throw new TypeError(e+" is not a function");t.subscribe({next:function(t){try{return e(t)}catch(r){n(r)}},error:n,complete:r})})}},{key:Symbol.observable,value:function(){return this}}],[{key:"from",value:function(t){var r="function"==typeof this?this:e;if(null==t)throw new TypeError(t+" is not an object");var n=u(t,Symbol.observable);if(n){var i=function(){var e=n.call(t);if(Object(e)!==e)throw new TypeError(e+" is not an object");return e.constructor===r?{v:e}:{v:new r(function(t){return e.subscribe(t)})}}();if("object"===("undefined"==typeof i?"undefined":o(i)))return i.v}return new r(function(e){b(function(r){if(!e.closed){try{var n=!0,o=!1,i=void 0;try{for(var s,u=t[Symbol.iterator]();!(n=(s=u.next()).done);n=!0){var a=s.value;if(e.next(a),e.closed)return}}catch(f){o=!0,i=f}finally{try{!n&&u["return"]&&u["return"]()}finally{if(o)throw i}}}catch(c){return void e.error(c)}e.complete()}})})}},{key:"of",value:function(){for(var t=arguments.length,r=Array(t),n=0;t>n;n++)r[n]=arguments[n];var o="function"==typeof this?this:e;return new o(function(e){b(function(t){if(!e.closed){for(var n=0;n<r.length;++n)if(e.next(r[n]),e.closed)return;e.complete()}})})}},{key:Symbol.species,get:function(){return this}}]),e}()}).call(t,function(){return this}(),r(4))},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var s=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),u=function c(e,t,r){null===e&&(e=Function.prototype);var n=Object.getOwnPropertyDescriptor(e,t);if(void 0===n){var o=Object.getPrototypeOf(e);return null===o?void 0:c(o,t,r)}if("value"in n)return n.value;var i=n.get;if(void 0!==i)return i.call(r)};Object.defineProperty(t,"__esModule",{value:!0});var a=r(1),f=function(e){function t(e){var r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];n(this,t);var i=o(this,Object.getPrototypeOf(t).call(this,e));return i.options=r,i.state="paused",i}return i(t,e),s(t,[{key:"pause",value:function(){if(this.state="paused",this.options.onPause){for(var e=arguments.length,t=Array(e),r=0;e>r;r++)t[r]=arguments[r];this.options.onPause.apply(this,t)}return this}},{key:"resume",value:function(){if(this.state="resumed",this.options.onResume){for(var e=arguments.length,t=Array(e),r=0;e>r;r++)t[r]=arguments[r];this.options.onResume.apply(this,t)}return this}},{key:"paused",value:function(){return"paused"===this.state}},{key:"subscribe",value:function(e){var r=u(Object.getPrototypeOf(t.prototype),"subscribe",this).call(this,e),n=this;return r.active=function(){return void 0!==this._observer&&!n.paused()},r.resubscribe=function(){return this.active()?!1:n.subscribe(e)},r}}]),t}(a.Observable);t["default"]=f},function(e,t,r){r(5),e.exports=self.fetch.bind(self)},function(e,t){function r(){f=!1,s.length?a=s.concat(a):c=-1,a.length&&n()}function n(){if(!f){var e=setTimeout(r);f=!0;for(var t=a.length;t;){for(s=a,a=[];++c<t;)s&&s[c].run();c=-1,t=a.length}s=null,f=!1,clearTimeout(e)}}function o(e,t){this.fun=e,this.array=t}function i(){}var s,u=e.exports={},a=[],f=!1,c=-1;u.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];a.push(new o(e,t)),1!==a.length||f||setTimeout(n,0)},o.prototype.run=function(){this.fun.apply(null,this.array)},u.title="browser",u.browser=!0,u.env={},u.argv=[],u.version="",u.versions={},u.on=i,u.addListener=i,u.once=i,u.off=i,u.removeListener=i,u.removeAllListeners=i,u.emit=i,u.binding=function(e){throw new Error("process.binding is not supported")},u.cwd=function(){return"/"},u.chdir=function(e){throw new Error("process.chdir is not supported")},u.umask=function(){return 0}},function(e,t){!function(){"use strict";function e(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function t(e){return"string"!=typeof e&&(e=String(e)),e}function r(e){this.map={},e instanceof r?e.forEach(function(e,t){this.append(t,e)},this):e&&Object.getOwnPropertyNames(e).forEach(function(t){this.append(t,e[t])},this)}function n(e){return e.bodyUsed?Promise.reject(new TypeError("Already read")):void(e.bodyUsed=!0)}function o(e){return new Promise(function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}})}function i(e){var t=new FileReader;return t.readAsArrayBuffer(e),o(t)}function s(e){var t=new FileReader;return t.readAsText(e),o(t)}function u(){return this.bodyUsed=!1,this._initBody=function(e){if(this._bodyInit=e,"string"==typeof e)this._bodyText=e;else if(p.blob&&Blob.prototype.isPrototypeOf(e))this._bodyBlob=e;else if(p.formData&&FormData.prototype.isPrototypeOf(e))this._bodyFormData=e;else if(e){if(!p.arrayBuffer||!ArrayBuffer.prototype.isPrototypeOf(e))throw new Error("unsupported BodyInit type")}else this._bodyText=""},p.blob?(this.blob=function(){var e=n(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this.blob().then(i)},this.text=function(){var e=n(this);if(e)return e;if(this._bodyBlob)return s(this._bodyBlob);if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)}):this.text=function(){var e=n(this);return e?e:Promise.resolve(this._bodyText)},p.formData&&(this.formData=function(){return this.text().then(c)}),this.json=function(){return this.text().then(JSON.parse)},this}function a(e){var t=e.toUpperCase();return d.indexOf(t)>-1?t:e}function f(e,t){t=t||{};var n=t.body;if(f.prototype.isPrototypeOf(e)){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new r(e.headers)),this.method=e.method,this.mode=e.mode,n||(n=e._bodyInit,e.bodyUsed=!0)}else this.url=e;if(this.credentials=t.credentials||this.credentials||"omit",(t.headers||!this.headers)&&(this.headers=new r(t.headers)),this.method=a(t.method||this.method||"GET"),this.mode=t.mode||this.mode||null,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(n)}function c(e){var t=new FormData;return e.trim().split("&").forEach(function(e){if(e){var r=e.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");t.append(decodeURIComponent(n),decodeURIComponent(o))}}),t}function l(e){var t=new r,n=e.getAllResponseHeaders().trim().split("\n");return n.forEach(function(e){var r=e.trim().split(":"),n=r.shift().trim(),o=r.join(":").trim();t.append(n,o)}),t}function h(e,t){t||(t={}),this._initBody(e),this.type="default",this.status=t.status,this.ok=this.status>=200&&this.status<300,this.statusText=t.statusText,this.headers=t.headers instanceof r?t.headers:new r(t.headers),this.url=t.url||""}if(!self.fetch){r.prototype.append=function(r,n){r=e(r),n=t(n);var o=this.map[r];o||(o=[],this.map[r]=o),o.push(n)},r.prototype["delete"]=function(t){delete this.map[e(t)]},r.prototype.get=function(t){var r=this.map[e(t)];return r?r[0]:null},r.prototype.getAll=function(t){return this.map[e(t)]||[]},r.prototype.has=function(t){return this.map.hasOwnProperty(e(t))},r.prototype.set=function(r,n){this.map[e(r)]=[t(n)]},r.prototype.forEach=function(e,t){Object.getOwnPropertyNames(this.map).forEach(function(r){this.map[r].forEach(function(n){e.call(t,n,r,this)},this)},this)};var p={blob:"FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch(e){return!1}}(),formData:"FormData"in self,arrayBuffer:"ArrayBuffer"in self},d=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];f.prototype.clone=function(){return new f(this)},u.call(f.prototype),u.call(h.prototype),h.prototype.clone=function(){return new h(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new r(this.headers),url:this.url})},h.error=function(){var e=new h(null,{status:0,statusText:""});return e.type="error",e};var y=[301,302,303,307,308];h.redirect=function(e,t){if(-1===y.indexOf(t))throw new RangeError("Invalid status code");return new h(null,{status:t,headers:{location:e}})},self.Headers=r,self.Request=f,self.Response=h,self.fetch=function(e,t){return new Promise(function(r,n){function o(){return"responseURL"in s?s.responseURL:/^X-Request-URL:/m.test(s.getAllResponseHeaders())?s.getResponseHeader("X-Request-URL"):void 0}var i;i=f.prototype.isPrototypeOf(e)&&!t?e:new f(e,t);var s=new XMLHttpRequest;s.onload=function(){var e=1223===s.status?204:s.status;if(100>e||e>599)return void n(new TypeError("Network request failed"));var t={status:e,statusText:s.statusText,headers:l(s),url:o()},i="response"in s?s.response:s.responseText;r(new h(i,t))},s.onerror=function(){n(new TypeError("Network request failed"))},s.open(i.method,i.url,!0),"include"===i.credentials&&(s.withCredentials=!0),"responseType"in s&&p.blob&&(s.responseType="blob"),i.headers.forEach(function(e,t){s.setRequestHeader(t,e)}),s.send("undefined"==typeof i._bodyInit?null:i._bodyInit)})},self.fetch.polyfill=!0}}()}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.fetchObservable=t():e.fetchObservable=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e){return"string"==typeof e}function i(e){return"function"==typeof e}function u(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],n=t.refreshDelay,r=void 0===n?!1:n,u=[],c=null,f=!1,a=0;(f=o(e))&&(e=[e]);var l=function v(){if(0!==u.length&&!p.paused()){var n=function(){r?c=setTimeout(v,i(r)?r(a++):r):(p.pause(),u.map(function(e){return e.complete()}),u=[])},o=e.map(function(e){return fetch(e,t)});Promise.all(o).then(function(e){u.map(function(t){return t.next(f?e[0]:e)}),n()})["catch"](function(e){u.map(function(t){return t.error(f?e[0]:e)}),n()})}},p=new s["default"](function(e){return u.push(e),u.length&&p.resume(),function(){u.splice(u.indexOf(e),1),u.length||p.pause()}},{onPause:function(){c&&(clearTimeout(c),c=null)},onResume:function(){c||l()}});return p.resume(),p}Object.defineProperty(t,"__esModule",{value:!0});var c=n(2),s=r(c);t["default"]=u},function(e,t,n){(function(e,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function i(e){Symbol[e]||Object.defineProperty(Symbol,e,{value:Symbol(e)})}function u(e){return Object.getOwnPropertyNames(e).forEach(function(t){Object.defineProperty(e,t,{enumerable:!1})}),e}function c(e,t){var n=e[t];if(null!=n){if("function"!=typeof n)throw new TypeError(n+" is not a function");return n}}function s(e){var t=e._cleanup;t&&(e._cleanup=void 0,t())}function f(e){return void 0===e._observer}function a(e){f(e)||(e._observer=void 0,s(e))}function l(e){return function(t){e.unsubscribe()}}function p(e,t){if(Object(e)!==e)throw new TypeError("Observer must be an object");var n=new v(e),r=new h(n),o=c(e,"start");if(o&&o.call(e,r),f(n))return r;try{var i=t.call(void 0,n);if(null!=i){if("function"==typeof i.unsubscribe)i=l(i);else if("function"!=typeof i)throw new TypeError(i+" is not a function");n._cleanup=i}}catch(u){return n.error(u),r}return f(n)&&s(n),r}function v(e){this._observer=e,this._cleanup=void 0}function h(e){this._observer=e}var b=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Object.defineProperty(t,"__esModule",{value:!0});var y=function(){if("undefined"!=typeof e&&"undefined"!=typeof n&&n.nextTick)return e.setImmediate?function(t){e.setImmediate(t)}:function(e){n.nextTick(e)};var t=self.MutationObserver||self.WebKitMutationObserver;if(t){var r=function(){var e=document.createElement("div"),n=function(t){return e.classList.toggle("x")},r=[],o=new t(function(e){for(r.length>1&&n();r.length>0;)r.shift()()});return o.observe(e,{attributes:!0}),{v:function(e){r.push(e),1===r.length&&n()}}}();if("object"===("undefined"==typeof r?"undefined":o(r)))return r.v}return function(e){setTimeout(e,0)}}();i("observable"),v.prototype=u({get closed(){return f(this)},next:function(e){if(!f(this)){var t=this._observer;try{var n=c(t,"next");if(!n)return;return n.call(t,e)}catch(r){try{a(this)}finally{throw r}}}},error:function(e){if(f(this))throw e;var t=this._observer;this._observer=void 0;try{var n=c(t,"error");if(!n)throw e;e=n.call(t,e)}catch(r){try{s(this)}finally{throw r}}return s(this),e},complete:function(e){if(!f(this)){var t=this._observer;this._observer=void 0;try{var n=c(t,"complete");e=n?n.call(t,e):void 0}catch(r){try{s(this)}finally{throw r}}return s(this),e}}}),h.prototype=u({unsubscribe:function(){a(this._observer)}});t.Observable=function(){function e(t){if(r(this,e),"function"!=typeof t)throw new TypeError("Observable initializer must be a function");this._subscriber=t}return b(e,[{key:"subscribe",value:function(e){return p(e,this._subscriber)}},{key:"forEach",value:function(e){var t=this;return new Promise(function(n,r){if("function"!=typeof e)throw new TypeError(e+" is not a function");t.subscribe({next:function(t){try{return e(t)}catch(n){r(n)}},error:r,complete:n})})}},{key:Symbol.observable,value:function(){return this}}],[{key:"from",value:function(t){var n="function"==typeof this?this:e;if(null==t)throw new TypeError(t+" is not an object");var r=c(t,Symbol.observable);if(r){var i=function(){var e=r.call(t);if(Object(e)!==e)throw new TypeError(e+" is not an object");return e.constructor===n?{v:e}:{v:new n(function(t){return e.subscribe(t)})}}();if("object"===("undefined"==typeof i?"undefined":o(i)))return i.v}return new n(function(e){y(function(n){if(!e.closed){try{var r=!0,o=!1,i=void 0;try{for(var u,c=t[Symbol.iterator]();!(r=(u=c.next()).done);r=!0){var s=u.value;if(e.next(s),e.closed)return}}catch(f){o=!0,i=f}finally{try{!r&&c["return"]&&c["return"]()}finally{if(o)throw i}}}catch(a){return void e.error(a)}e.complete()}})})}},{key:"of",value:function(){for(var t=arguments.length,n=Array(t),r=0;t>r;r++)n[r]=arguments[r];var o="function"==typeof this?this:e;return new o(function(e){y(function(t){if(!e.closed){for(var r=0;r<n.length;++r)if(e.next(n[r]),e.closed)return;e.complete()}})})}},{key:Symbol.species,get:function(){return this}}]),e}()}).call(t,function(){return this}(),n(3))},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var u=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),c=function a(e,t,n){null===e&&(e=Function.prototype);var r=Object.getOwnPropertyDescriptor(e,t);if(void 0===r){var o=Object.getPrototypeOf(e);return null===o?void 0:a(o,t,n)}if("value"in r)return r.value;var i=r.get;if(void 0!==i)return i.call(n)};Object.defineProperty(t,"__esModule",{value:!0});var s=n(1),f=function(e){function t(e){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];r(this,t);var i=o(this,Object.getPrototypeOf(t).call(this,e));return i.options=n,i.state="paused",i}return i(t,e),u(t,[{key:"pause",value:function(){if(this.state="paused",this.options.onPause){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];this.options.onPause.apply(this,t)}return this}},{key:"resume",value:function(){if(this.state="resumed",this.options.onResume){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];this.options.onResume.apply(this,t)}return this}},{key:"paused",value:function(){return"paused"===this.state}},{key:"subscribe",value:function(e){var n=c(Object.getPrototypeOf(t.prototype),"subscribe",this).call(this,e),r=this;return n.active=function(){return void 0!==this._observer&&!r.paused()},n.resubscribe=function(){return this.active()?!1:r.subscribe(e)},n}}]),t}(s.Observable);t["default"]=f},function(e,t){function n(){f=!1,u.length?s=u.concat(s):a=-1,s.length&&r()}function r(){if(!f){var e=setTimeout(n);f=!0;for(var t=s.length;t;){for(u=s,s=[];++a<t;)u&&u[a].run();a=-1,t=s.length}u=null,f=!1,clearTimeout(e)}}function o(e,t){this.fun=e,this.array=t}function i(){}var u,c=e.exports={},s=[],f=!1,a=-1;c.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];s.push(new o(e,t)),1!==s.length||f||setTimeout(r,0)},o.prototype.run=function(){this.fun.apply(null,this.array)},c.title="browser",c.browser=!0,c.env={},c.argv=[],c.version="",c.versions={},c.on=i,c.addListener=i,c.once=i,c.off=i,c.removeListener=i,c.removeAllListeners=i,c.emit=i,c.binding=function(e){throw new Error("process.binding is not supported")},c.cwd=function(){return"/"},c.chdir=function(e){throw new Error("process.chdir is not supported")},c.umask=function(){return 0}}])}); |
{ | ||
"name": "fetch-observable", | ||
"description": "Observable-based Fetch API", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"license": "BSD-3-Clause", | ||
@@ -25,3 +25,2 @@ "repository": { | ||
"dependencies": { | ||
"isomorphic-fetch": "2.2.0" | ||
}, | ||
@@ -35,2 +34,3 @@ "devDependencies": { | ||
"concurrently": "0.1.1", | ||
"isomorphic-fetch": "2.2.0", | ||
"json-loader": "0.5.3", | ||
@@ -37,0 +37,0 @@ "react": "0.14.2", |
@@ -9,3 +9,3 @@ # fetchObservable() | ||
- Uses Observable syntax from [ES Observable proposal](https://github.com/zenparsing/es-observable). | ||
- Runs in Node and browsers. (BYO Promises though) | ||
- Runs in Node and browsers. (BYO Fetch API and Promises polyfills though) | ||
@@ -12,0 +12,0 @@ ## Installation |
/** | ||
* @copyright © 2015, Rick Wong. All rights reserved. | ||
*/ | ||
import __fetch from "isomorphic-fetch"; | ||
import PausableObservable from "lib/PausableObservable"; | ||
@@ -6,0 +5,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
0
48473
12
1039
- Removedisomorphic-fetch@2.2.0
- Removedencoding@0.1.13(transitive)
- Removediconv-lite@0.6.3(transitive)
- Removedis-stream@1.1.0(transitive)
- Removedisomorphic-fetch@2.2.0(transitive)
- Removednode-fetch@1.7.3(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedwhatwg-fetch@3.6.20(transitive)