fetch-observable
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -175,20 +175,16 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.Observable = Observable; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } | ||
/** | ||
* Observable.js from zenparsing/es-observable. | ||
* Observable.js from zenparsing/zen-observable | ||
* | ||
* @copyright © zenparsing | ||
* @homepage https://github.com/zenparsing/es-observable | ||
* @file https://github.com/zenparsing/es-observable/blob/bed0248bf84818bbda26c051f156e51ab9f7671e/src/Observable.js | ||
* @homepage https://github.com/zenparsing/zen-observable | ||
* @file https://github.com/zenparsing/zen-observable/blob/de80d63fb166421226bb3c918b111cac40bd672a/src/Observable.js | ||
*/ | ||
// === Non-Promise Job Queueing === | ||
@@ -254,18 +250,24 @@ | ||
if (!Symbol[name]) Object.defineProperty(Symbol, name, { value: Symbol(name) }); | ||
if (symbolsSupported() && !Symbol[name]) Object.defineProperty(Symbol, name, { value: Symbol(name) }); | ||
} | ||
polyfillSymbol("observable"); | ||
function symbolsSupported() { | ||
// === Abstract Operations === | ||
return typeof Symbol === "function"; | ||
} | ||
function nonEnum(obj) { | ||
function hasSymbol(name) { | ||
Object.getOwnPropertyNames(obj).forEach(function (k) { | ||
Object.defineProperty(obj, k, { enumerable: false }); | ||
}); | ||
return symbolsSupported() && Boolean(Symbol[name]); | ||
} | ||
return obj; | ||
function getSymbol(name) { | ||
return hasSymbol(name) ? Symbol[name] : "@@" + name; | ||
} | ||
polyfillSymbol("observable"); | ||
// === Abstract Operations === | ||
function getMethod(obj, key) { | ||
@@ -282,2 +284,18 @@ | ||
function getSpecies(ctor) { | ||
var symbol = getSymbol("species"); | ||
return symbol ? ctor[symbol] : ctor; | ||
} | ||
function addMethods(target, methods) { | ||
Object.keys(methods).forEach(function (k) { | ||
var desc = Object.getOwnPropertyDescriptor(methods, k); | ||
desc.enumerable = false; | ||
Object.defineProperty(target, k, desc); | ||
}); | ||
} | ||
function cleanupSubscription(observer) { | ||
@@ -313,2 +331,4 @@ | ||
function cleanupFromSubscription(subscription) { | ||
// TODO: Should we get the method out and apply it here, instead of | ||
// looking up the method at call time? | ||
return function (_) { | ||
@@ -326,2 +346,4 @@ subscription.unsubscribe(); | ||
// TODO: Should we check for a "next" method here? | ||
var subscriptionObserver = new SubscriptionObserver(observer), | ||
@@ -367,3 +389,3 @@ subscription = new Subscription(subscriptionObserver), | ||
SubscriptionObserver.prototype = nonEnum({ | ||
addMethods(SubscriptionObserver.prototype = {}, { | ||
@@ -462,3 +484,3 @@ get closed() { | ||
Subscription.prototype = nonEnum({ | ||
addMethods(Subscription.prototype = {}, { | ||
unsubscribe: function unsubscribe() { | ||
@@ -469,95 +491,144 @@ closeSubscription(this._observer); | ||
var Observable = exports.Observable = (function () { | ||
function Observable(subscriber) { | ||
// == Fundamental == | ||
// The stream subscriber must be a function | ||
if (typeof subscriber !== "function") throw new TypeError("Observable initializer must be a function"); | ||
function Observable(subscriber) { | ||
_classCallCheck(this, Observable); | ||
this._subscriber = subscriber; | ||
} | ||
// The stream subscriber must be a function | ||
if (typeof subscriber !== "function") throw new TypeError("Observable initializer must be a function"); | ||
addMethods(Observable.prototype, { | ||
subscribe: function subscribe(observer) { | ||
this._subscriber = subscriber; | ||
} | ||
return createSubscription(observer, this._subscriber); | ||
}, | ||
forEach: function forEach(fn) { | ||
var _this = this; | ||
_createClass(Observable, [{ | ||
key: "subscribe", | ||
value: function subscribe(observer) { | ||
return new Promise(function (resolve, reject) { | ||
return createSubscription(observer, this._subscriber); | ||
} | ||
}, { | ||
key: "forEach", | ||
value: function forEach(fn) { | ||
var _this = this; | ||
if (typeof fn !== "function") throw new TypeError(fn + " is not a function"); | ||
return new Promise(function (resolve, reject) { | ||
_this.subscribe({ | ||
next: function next(value) { | ||
if (typeof fn !== "function") throw new TypeError(fn + " is not a function"); | ||
try { | ||
return fn(value); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}, | ||
_this.subscribe({ | ||
next: function next(value) { | ||
error: reject, | ||
complete: resolve | ||
}); | ||
}); | ||
}, | ||
map: function map(fn) { | ||
var _this2 = this; | ||
try { | ||
return fn(value); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}, | ||
if (typeof fn !== "function") throw new TypeError(fn + " is not a function"); | ||
error: reject, | ||
complete: resolve | ||
}); | ||
var C = getSpecies(this.constructor); | ||
return new C(function (observer) { | ||
return _this2.subscribe({ | ||
next: function next(value) { | ||
try { | ||
value = fn(value); | ||
} catch (e) { | ||
return observer.error(e); | ||
} | ||
return observer.next(value); | ||
}, | ||
error: function error(value) { | ||
return observer.error(value); | ||
}, | ||
complete: function complete(value) { | ||
return observer.complete(value); | ||
} | ||
}); | ||
} | ||
}, { | ||
key: Symbol.observable, | ||
value: function value() { | ||
return this; | ||
} | ||
}], [{ | ||
key: "from", | ||
}); | ||
}, | ||
filter: function filter(fn) { | ||
var _this3 = this; | ||
// == Derived == | ||
if (typeof fn !== "function") throw new TypeError(fn + " is not a function"); | ||
value: function from(x) { | ||
var C = getSpecies(this.constructor); | ||
var C = typeof this === "function" ? this : Observable; | ||
return new C(function (observer) { | ||
return _this3.subscribe({ | ||
next: function next(value) { | ||
if (x == null) throw new TypeError(x + " is not an object"); | ||
try { | ||
if (!fn(value)) return undefined; | ||
} catch (e) { | ||
return observer.error(e); | ||
} | ||
var method = getMethod(x, Symbol.observable); | ||
return observer.next(value); | ||
}, | ||
error: function error(value) { | ||
return observer.error(value); | ||
}, | ||
complete: function complete(value) { | ||
return observer.complete(value); | ||
} | ||
}); | ||
}); | ||
} | ||
}); | ||
if (method) { | ||
var _ret2 = (function () { | ||
Object.defineProperty(Observable.prototype, getSymbol("observable"), { | ||
value: function value() { | ||
return this; | ||
}, | ||
writable: true, | ||
configurable: true | ||
}); | ||
var observable = method.call(x); | ||
addMethods(Observable, { | ||
from: function from(x) { | ||
if (Object(observable) !== observable) throw new TypeError(observable + " is not an object"); | ||
var C = typeof this === "function" ? this : Observable; | ||
if (observable.constructor === C) return { | ||
v: observable | ||
}; | ||
if (x == null) throw new TypeError(x + " is not an object"); | ||
return { | ||
v: new C(function (observer) { | ||
return observable.subscribe(observer); | ||
}) | ||
var method = getMethod(x, getSymbol("observable")); | ||
if (method) { | ||
var _ret2 = (function () { | ||
var observable = method.call(x); | ||
if (Object(observable) !== observable) throw new TypeError(observable + " is not an object"); | ||
if (observable.constructor === C) return { | ||
v: observable | ||
}; | ||
})(); | ||
if ((typeof _ret2 === "undefined" ? "undefined" : _typeof(_ret2)) === "object") return _ret2.v; | ||
} | ||
return { | ||
v: new C(function (observer) { | ||
return observable.subscribe(observer); | ||
}) | ||
}; | ||
})(); | ||
// TODO: Should we check for a Symbol.iterator method here? | ||
if ((typeof _ret2 === "undefined" ? "undefined" : _typeof(_ret2)) === "object") return _ret2.v; | ||
} | ||
return new C(function (observer) { | ||
return new C(function (observer) { | ||
enqueueJob(function (_) { | ||
enqueueJob(function (_) { | ||
if (observer.closed) return; | ||
if (observer.closed) return; | ||
// Assume that the object is iterable. If not, then the observer | ||
// will receive an error. | ||
try { | ||
// Assume that the object is iterable. If not, then the observer | ||
// will receive an error. | ||
try { | ||
if (hasSymbol("iterator")) { | ||
var _iteratorNormalCompletion = true; | ||
@@ -590,49 +661,58 @@ var _didIteratorError = false; | ||
} | ||
} catch (e) { | ||
} else { | ||
// If observer.next throws an error, then the subscription will | ||
// be closed and the error method will simply rethrow | ||
observer.error(e); | ||
return; | ||
if (!Array.isArray(x)) throw new Error(x + " is not an Array"); | ||
for (var i = 0; i < x.length; ++i) { | ||
observer.next(x[i]); | ||
if (observer.closed) return; | ||
} | ||
} | ||
} catch (e) { | ||
observer.complete(); | ||
}); | ||
// If observer.next throws an error, then the subscription will | ||
// be closed and the error method will simply rethrow | ||
observer.error(e); | ||
return; | ||
} | ||
observer.complete(); | ||
}); | ||
}); | ||
}, | ||
of: function of() { | ||
for (var _len = arguments.length, items = Array(_len), _key = 0; _key < _len; _key++) { | ||
items[_key] = arguments[_key]; | ||
} | ||
}, { | ||
key: "of", | ||
value: function of() { | ||
for (var _len = arguments.length, items = Array(_len), _key = 0; _key < _len; _key++) { | ||
items[_key] = arguments[_key]; | ||
} | ||
var C = typeof this === "function" ? this : Observable; | ||
var C = typeof this === "function" ? this : Observable; | ||
return new C(function (observer) { | ||
return new C(function (observer) { | ||
enqueueJob(function (_) { | ||
enqueueJob(function (_) { | ||
if (observer.closed) return; | ||
if (observer.closed) return; | ||
for (var i = 0; i < items.length; ++i) { | ||
for (var i = 0; i < items.length; ++i) { | ||
observer.next(items[i]); | ||
observer.next(items[i]); | ||
if (observer.closed) return; | ||
} | ||
if (observer.closed) return; | ||
} | ||
observer.complete(); | ||
}); | ||
observer.complete(); | ||
}); | ||
} | ||
}, { | ||
key: Symbol.species, | ||
get: function get() { | ||
return this; | ||
} | ||
}]); | ||
}); | ||
} | ||
}); | ||
return Observable; | ||
})(); | ||
Object.defineProperty(Observable, getSymbol("species"), { | ||
get: function get() { | ||
return this; | ||
}, | ||
configurable: true | ||
}); | ||
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()), __webpack_require__(3))) | ||
@@ -639,0 +719,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(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}var c=n(2),s=r(c);e.exports=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}}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.fetchObservable=e():t.fetchObservable=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return t[n].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function o(t){return"string"==typeof t}function i(t){return"function"==typeof t}function u(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=e.refreshDelay,n=void 0===r?!1:r,u=[],c=null,s=!1,a=0;(s=o(t))&&(t=[t]);var l=function h(){if(0!==u.length&&!p.paused()){var r=function(){n?c=setTimeout(h,i(n)?n(a++):n):(p.pause(),u.map(function(t){return t.complete()}),u=[])},o=t.map(function(t){return fetch(t,e)});Promise.all(o).then(function(t){u.map(function(e){return e.next(s?t[0]:t)}),r()})["catch"](function(t){u.map(function(e){return e.error(s?t[0]:t)}),r()})}},p=new f["default"](function(t){return u.push(t),u.length&&p.resume(),function(){u.splice(u.indexOf(t),1),u.length||p.pause()}},{onPause:function(){c&&(clearTimeout(c),c=null)},onResume:function(){c||l()}});return p.resume(),p}var c=r(2),f=n(c);t.exports=u},function(t,e,r){(function(t,r){"use strict";function n(t){return t&&"undefined"!=typeof Symbol&&t.constructor===Symbol?"symbol":typeof t}function o(t){i()&&!Symbol[t]&&Object.defineProperty(Symbol,t,{value:Symbol(t)})}function i(){return"function"==typeof Symbol}function u(t){return i()&&Boolean(Symbol[t])}function c(t){return u(t)?Symbol[t]:"@@"+t}function f(t,e){var r=t[e];if(null!=r){if("function"!=typeof r)throw new TypeError(r+" is not a function");return r}}function s(t){var e=c("species");return e?t[e]:t}function a(t,e){Object.keys(e).forEach(function(r){var n=Object.getOwnPropertyDescriptor(e,r);n.enumerable=!1,Object.defineProperty(t,r,n)})}function l(t){var e=t._cleanup;e&&(t._cleanup=void 0,e())}function p(t){return void 0===t._observer}function h(t){p(t)||(t._observer=void 0,l(t))}function v(t){return function(e){t.unsubscribe()}}function b(t,e){if(Object(t)!==t)throw new TypeError("Observer must be an object");var r=new y(t),n=new d(r),o=f(t,"start");if(o&&o.call(t,n),p(r))return n;try{var i=e.call(void 0,r);if(null!=i){if("function"==typeof i.unsubscribe)i=v(i);else if("function"!=typeof i)throw new TypeError(i+" is not a function");r._cleanup=i}}catch(u){return r.error(u),n}return p(r)&&l(r),n}function y(t){this._observer=t,this._cleanup=void 0}function d(t){this._observer=t}function m(t){if("function"!=typeof t)throw new TypeError("Observable initializer must be a function");this._subscriber=t}Object.defineProperty(e,"__esModule",{value:!0}),e.Observable=m;var g=function(){if("undefined"!=typeof t&&"undefined"!=typeof r&&r.nextTick)return t.setImmediate?function(e){t.setImmediate(e)}:function(t){r.nextTick(t)};var e=self.MutationObserver||self.WebKitMutationObserver;if(e){var o=function(){var t=document.createElement("div"),r=function(e){return t.classList.toggle("x")},n=[],o=new e(function(t){for(n.length>1&&r();n.length>0;)n.shift()()});return o.observe(t,{attributes:!0}),{v:function(t){n.push(t),1===n.length&&r()}}}();if("object"===("undefined"==typeof o?"undefined":n(o)))return o.v}return function(t){setTimeout(t,0)}}();o("observable"),a(y.prototype={},{get closed(){return p(this)},next:function(t){if(!p(this)){var e=this._observer;try{var r=f(e,"next");if(!r)return;return r.call(e,t)}catch(n){try{h(this)}finally{throw n}}}},error:function(t){if(p(this))throw t;var e=this._observer;this._observer=void 0;try{var r=f(e,"error");if(!r)throw t;t=r.call(e,t)}catch(n){try{l(this)}finally{throw n}}return l(this),t},complete:function(t){if(!p(this)){var e=this._observer;this._observer=void 0;try{var r=f(e,"complete");t=r?r.call(e,t):void 0}catch(n){try{l(this)}finally{throw n}}return l(this),t}}}),a(d.prototype={},{unsubscribe:function(){h(this._observer)}}),a(m.prototype,{subscribe:function(t){return b(t,this._subscriber)},forEach:function(t){var e=this;return new Promise(function(r,n){if("function"!=typeof t)throw new TypeError(t+" is not a function");e.subscribe({next:function(e){try{return t(e)}catch(r){n(r)}},error:n,complete:r})})},map:function(t){var e=this;if("function"!=typeof t)throw new TypeError(t+" is not a function");var r=s(this.constructor);return new r(function(r){return e.subscribe({next:function(e){try{e=t(e)}catch(n){return r.error(n)}return r.next(e)},error:function(t){return r.error(t)},complete:function(t){return r.complete(t)}})})},filter:function(t){var e=this;if("function"!=typeof t)throw new TypeError(t+" is not a function");var r=s(this.constructor);return new r(function(r){return e.subscribe({next:function(e){try{if(!t(e))return}catch(n){return r.error(n)}return r.next(e)},error:function(t){return r.error(t)},complete:function(t){return r.complete(t)}})})}}),Object.defineProperty(m.prototype,c("observable"),{value:function(){return this},writable:!0,configurable:!0}),a(m,{from:function(t){var e="function"==typeof this?this:m;if(null==t)throw new TypeError(t+" is not an object");var r=f(t,c("observable"));if(r){var o=function(){var n=r.call(t);if(Object(n)!==n)throw new TypeError(n+" is not an object");return n.constructor===e?{v:n}:{v:new e(function(t){return n.subscribe(t)})}}();if("object"===("undefined"==typeof o?"undefined":n(o)))return o.v}return new e(function(e){g(function(r){if(!e.closed){try{if(u("iterator")){var n=!0,o=!1,i=void 0;try{for(var c,f=t[Symbol.iterator]();!(n=(c=f.next()).done);n=!0){var s=c.value;if(e.next(s),e.closed)return}}catch(a){o=!0,i=a}finally{try{!n&&f["return"]&&f["return"]()}finally{if(o)throw i}}}else{if(!Array.isArray(t))throw new Error(t+" is not an Array");for(var l=0;l<t.length;++l)if(e.next(t[l]),e.closed)return}}catch(p){return void e.error(p)}e.complete()}})})},of:function(){for(var t=arguments.length,e=Array(t),r=0;t>r;r++)e[r]=arguments[r];var n="function"==typeof this?this:m;return new n(function(t){g(function(r){if(!t.closed){for(var n=0;n<e.length;++n)if(t.next(e[n]),t.closed)return;t.complete()}})})}}),Object.defineProperty(m,c("species"),{get:function(){return this},configurable:!0})}).call(e,function(){return this}(),r(3))},function(t,e,r){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var u=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),c=function a(t,e,r){null===t&&(t=Function.prototype);var n=Object.getOwnPropertyDescriptor(t,e);if(void 0===n){var o=Object.getPrototypeOf(t);return null===o?void 0:a(o,e,r)}if("value"in n)return n.value;var i=n.get;if(void 0!==i)return i.call(r)};Object.defineProperty(e,"__esModule",{value:!0});var f=r(1),s=function(t){function e(t){var r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];n(this,e);var i=o(this,Object.getPrototypeOf(e).call(this,t));return i.options=r,i.state="paused",i}return i(e,t),u(e,[{key:"pause",value:function(){if(this.state="paused",this.options.onPause){for(var t=arguments.length,e=Array(t),r=0;t>r;r++)e[r]=arguments[r];this.options.onPause.apply(this,e)}return this}},{key:"resume",value:function(){if(this.state="resumed",this.options.onResume){for(var t=arguments.length,e=Array(t),r=0;t>r;r++)e[r]=arguments[r];this.options.onResume.apply(this,e)}return this}},{key:"paused",value:function(){return"paused"===this.state}},{key:"subscribe",value:function(t){var r=c(Object.getPrototypeOf(e.prototype),"subscribe",this).call(this,t),n=this;return r.active=function(){return void 0!==this._observer&&!n.paused()},r.resubscribe=function(){return this.active()?!1:n.subscribe(t)},r}}]),e}(f.Observable);e["default"]=s},function(t,e){function r(){s=!1,u.length?f=u.concat(f):a=-1,f.length&&n()}function n(){if(!s){var t=setTimeout(r);s=!0;for(var e=f.length;e;){for(u=f,f=[];++a<e;)u&&u[a].run();a=-1,e=f.length}u=null,s=!1,clearTimeout(t)}}function o(t,e){this.fun=t,this.array=e}function i(){}var u,c=t.exports={},f=[],s=!1,a=-1;c.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];f.push(new o(t,e)),1!==f.length||s||setTimeout(n,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(t){throw new Error("process.binding is not supported")},c.cwd=function(){return"/"},c.chdir=function(t){throw new Error("process.chdir is not supported")},c.umask=function(){return 0}}])}); |
{ | ||
"name": "fetch-observable", | ||
"description": "Observable-based Fetch API", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"license": "BSD-3-Clause", | ||
@@ -6,0 +6,0 @@ "repository": { |
/** | ||
* Observable.js from zenparsing/es-observable. | ||
* Observable.js from zenparsing/zen-observable | ||
* | ||
* @copyright © zenparsing | ||
* @homepage https://github.com/zenparsing/es-observable | ||
* @file https://github.com/zenparsing/es-observable/blob/bed0248bf84818bbda26c051f156e51ab9f7671e/src/Observable.js | ||
* @homepage https://github.com/zenparsing/zen-observable | ||
* @file https://github.com/zenparsing/zen-observable/blob/de80d63fb166421226bb3c918b111cac40bd672a/src/Observable.js | ||
*/ | ||
// === Non-Promise Job Queueing === | ||
@@ -61,19 +60,25 @@ | ||
if (!Symbol[name]) | ||
if (symbolsSupported() && !Symbol[name]) | ||
Object.defineProperty(Symbol, name, { value: Symbol(name) }); | ||
} | ||
polyfillSymbol("observable"); | ||
function symbolsSupported() { | ||
// === Abstract Operations === | ||
return typeof Symbol === "function"; | ||
} | ||
function nonEnum(obj) { | ||
function hasSymbol(name) { | ||
Object.getOwnPropertyNames(obj).forEach(k => { | ||
Object.defineProperty(obj, k, { enumerable: false }); | ||
}); | ||
return symbolsSupported() && Boolean(Symbol[name]); | ||
} | ||
return obj; | ||
function getSymbol(name) { | ||
return hasSymbol(name) ? Symbol[name] : "@@" + name; | ||
} | ||
polyfillSymbol("observable"); | ||
// === Abstract Operations === | ||
function getMethod(obj, key) { | ||
@@ -92,2 +97,18 @@ | ||
function getSpecies(ctor) { | ||
let symbol = getSymbol("species"); | ||
return symbol ? ctor[symbol] : ctor; | ||
} | ||
function addMethods(target, methods) { | ||
Object.keys(methods).forEach(k => { | ||
let desc = Object.getOwnPropertyDescriptor(methods, k); | ||
desc.enumerable = false; | ||
Object.defineProperty(target, k, desc); | ||
}); | ||
} | ||
function cleanupSubscription(observer) { | ||
@@ -125,2 +146,4 @@ | ||
function cleanupFromSubscription(subscription) { | ||
// TODO: Should we get the method out and apply it here, instead of | ||
// looking up the method at call time? | ||
return _=> { subscription.unsubscribe() }; | ||
@@ -137,2 +160,4 @@ } | ||
// TODO: Should we check for a "next" method here? | ||
let subscriptionObserver = new SubscriptionObserver(observer), | ||
@@ -185,3 +210,3 @@ subscription = new Subscription(subscriptionObserver), | ||
SubscriptionObserver.prototype = nonEnum({ | ||
addMethods(SubscriptionObserver.prototype = {}, { | ||
@@ -280,23 +305,21 @@ get closed() { return subscriptionClosed(this) }, | ||
Subscription.prototype = nonEnum({ | ||
addMethods(Subscription.prototype = {}, { | ||
unsubscribe() { closeSubscription(this._observer) } | ||
}); | ||
export class Observable { | ||
export function Observable(subscriber) { | ||
// == Fundamental == | ||
// The stream subscriber must be a function | ||
if (typeof subscriber !== "function") | ||
throw new TypeError("Observable initializer must be a function"); | ||
constructor(subscriber) { | ||
this._subscriber = subscriber; | ||
} | ||
// The stream subscriber must be a function | ||
if (typeof subscriber !== "function") | ||
throw new TypeError("Observable initializer must be a function"); | ||
addMethods(Observable.prototype, { | ||
this._subscriber = subscriber; | ||
} | ||
subscribe(observer) { | ||
return createSubscription(observer, this._subscriber); | ||
} | ||
}, | ||
@@ -322,12 +345,60 @@ forEach(fn) { | ||
}); | ||
} | ||
}, | ||
[Symbol.observable]() { return this } | ||
map(fn) { | ||
static get [Symbol.species]() { return this } | ||
if (typeof fn !== "function") | ||
throw new TypeError(fn + " is not a function"); | ||
// == Derived == | ||
let C = getSpecies(this.constructor); | ||
static from(x) { | ||
return new C(observer => this.subscribe({ | ||
next(value) { | ||
try { value = fn(value) } | ||
catch (e) { return observer.error(e) } | ||
return observer.next(value); | ||
}, | ||
error(value) { return observer.error(value) }, | ||
complete(value) { return observer.complete(value) }, | ||
})); | ||
}, | ||
filter(fn) { | ||
if (typeof fn !== "function") | ||
throw new TypeError(fn + " is not a function"); | ||
let C = getSpecies(this.constructor); | ||
return new C(observer => this.subscribe({ | ||
next(value) { | ||
try { if (!fn(value)) return undefined; } | ||
catch (e) { return observer.error(e) } | ||
return observer.next(value); | ||
}, | ||
error(value) { return observer.error(value) }, | ||
complete(value) { return observer.complete(value) }, | ||
})); | ||
}, | ||
}); | ||
Object.defineProperty(Observable.prototype, getSymbol("observable"), { | ||
value: function() { return this }, | ||
writable: true, | ||
configurable: true, | ||
}); | ||
addMethods(Observable, { | ||
from(x) { | ||
let C = typeof this === "function" ? this : Observable; | ||
@@ -338,3 +409,3 @@ | ||
let method = getMethod(x, Symbol.observable); | ||
let method = getMethod(x, getSymbol("observable")); | ||
@@ -354,4 +425,2 @@ if (method) { | ||
// TODO: Should we check for a Symbol.iterator method here? | ||
return new C(observer => { | ||
@@ -368,8 +437,24 @@ | ||
for (let item of x) { | ||
if (hasSymbol("iterator")) { | ||
observer.next(item); | ||
for (let item of x) { | ||
if (observer.closed) | ||
return; | ||
observer.next(item); | ||
if (observer.closed) | ||
return; | ||
} | ||
} else { | ||
if (!Array.isArray(x)) | ||
throw new Error(x + " is not an Array"); | ||
for (let i = 0; i < x.length; ++i) { | ||
observer.next(x[i]); | ||
if (observer.closed) | ||
return; | ||
} | ||
} | ||
@@ -388,5 +473,5 @@ | ||
}); | ||
} | ||
}, | ||
static of(...items) { | ||
of(...items) { | ||
@@ -413,4 +498,9 @@ let C = typeof this === "function" ? this : Observable; | ||
}); | ||
} | ||
}, | ||
} | ||
}); | ||
Object.defineProperty(Observable, getSymbol("species"), { | ||
get() { return this }, | ||
configurable: true, | ||
}); |
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
52210
1157