use-abortable-fetch
Advanced tools
Comparing version 2.3.0-0 to 2.4.0
{ | ||
"name": "use-abortable-fetch", | ||
"version": "2.3.0-0", | ||
"version": "2.4.0", | ||
"main": "release/index.js", | ||
@@ -5,0 +5,0 @@ "umd:main": "release/index.umd.js", |
function n(n){return n&&"object"==typeof n&&"default"in n?n.default:n}var t=require("react"),e=n(require("media-typer")),r=n(require("content-type"));const o=function(){function n(){}return n.prototype.then=function(t,e){const r=new n,o=this.s;if(o){const n=1&o?t:e;if(n){try{u(r,1,n(this.v))}catch(n){u(r,2,n)}return r}return this}return this.o=function(n){try{const o=n.v;1&n.s?u(r,1,t?t(o):o):e?u(r,1,e(o)):u(r,2,o)}catch(n){u(r,2,n)}},r},n}();function u(n,t,e){if(!n.s){if(e instanceof o){if(!e.s)return void(e.o=u.bind(null,n,t));1&t&&(t=e.s),e=e.v}if(e&&e.then)return void e.then(u.bind(null,n,t),u.bind(null,n,2));n.s=t,n.v=e;const r=n.o;r&&r(n)}}const i={};!function(){function n(n){this._entry=n,this._pact=null,this._resolve=null,this._return=null,this._promise=null}function t(n){return{value:n,done:!0}}function e(n){return{value:n,done:!1}}n.prototype[Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator"))]=function(){return this},n.prototype._yield=function(n){return this._resolve(n&&n.then?n.then(e):e(n)),this._pact=new o},n.prototype.next=function(n){const e=this;return e._promise=new Promise(function(r){const l=e._pact;if(null===l){const n=e._entry;if(null===n)return r(e._promise);function s(n){e._resolve(n&&n.then?n.then(t):t(n)),e._pact=null,e._resolve=null}e._entry=null,e._resolve=r,n(e).then(s,function(n){if(n===i)s(e._return);else{const t=new o;e._resolve(t),e._pact=null,e._resolve=null,_resolve(t,2,n)}})}else e._pact=null,e._resolve=r,u(l,1,n)})},n.prototype.return=function(n){const e=this;return e._promise=new Promise(function(r){const o=e._pact;if(null===o)return null===e._entry?r(e._promise):(e._entry=null,r(n&&n.then?n.then(t):t(n)));e._return=n,e._resolve=r,e._pact=null,u(o,2,i)})},n.prototype.throw=function(n){const t=this;return t._promise=new Promise(function(e,r){const o=t._pact;if(null===o)return null===t._entry?e(t._promise):(t._entry=null,r(n));t._resolve=e,t._pact=null,u(o,2,n)})}}(),module.exports=function(n,o){void 0===o&&(o={});var u=t.useState({data:null,loading:0,error:null,controller:null}),i=u[0],l=u[1],s=t.useRef(!1);return t.useLayoutEffect(function(){return s.current=!0,function(){s.current=!1}},[]),t.useEffect(function(){var t=new AbortController;return n&&(l(function(n){return{data:null,loading:n.loading+1,error:null,controller:t}}),function(n,t,o,u){try{var i=Object.assign({},t,{signal:o});Promise.resolve(function(t,o){try{var l=Promise.resolve(fetch(n,i)).then(function(n){function t(){u(function(n){return Object.assign({},n,{data:i,loading:n.loading-1})})}if(!n.ok){var o=new Error(n.statusText);throw o.status=n.status,o}var i=null,l=function(n){if(n){var t=r.parse(n),o=e.parse(t.type);if("json"===o.subtype)return!0;if("json"===o.suffix)return!0;if(o.suffix&&/\bjson\b/i.test(o.suffix))return!0;if(o.subtype&&/\bjson\b/i.test(o.subtype))return!0}return!1}(n.headers.get("content-type"))?Promise.resolve(n.json()).then(function(n){i=n}):Promise.resolve(n.text()).then(function(n){i=n});return l&&l.then?l.then(t):t()})}catch(n){return o(n)}return l&&l.then?l.then(void 0,o):l}(0,function(n){var t="AbortError"!==n.name?n:null;u(function(n){return Object.assign({},n,{error:t,loading:n.loading-1})})}))}catch(n){return Promise.reject(n)}}(n,o,t.signal,function(n){s.current&&l(n)})),function(){return t.abort()}},[n]),{data:i.data,loading:!!i.loading,error:i.error,abort:function(){return i.controller&&i.controller.abort()}}}; | ||
//# sourceMappingURL=index.js.map |
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react"),require("media-typer"),require("content-type")):"function"==typeof define&&define.amd?define(["react","media-typer","content-type"],t):n.useAbortableFetch=t(n.react,n.mediaTyper,n.contentType)}(this,function(n,t,e){t=t&&t.hasOwnProperty("default")?t.default:t,e=e&&e.hasOwnProperty("default")?e.default:e;const r=function(){function n(){}return n.prototype.then=function(t,e){const r=new n,u=this.s;if(u){const n=1&u?t:e;if(n){try{o(r,1,n(this.v))}catch(n){o(r,2,n)}return r}return this}return this.o=function(n){try{const u=n.v;1&n.s?o(r,1,t?t(u):u):e?o(r,1,e(u)):o(r,2,u)}catch(n){o(r,2,n)}},r},n}();function o(n,t,e){if(!n.s){if(e instanceof r){if(!e.s)return void(e.o=o.bind(null,n,t));1&t&&(t=e.s),e=e.v}if(e&&e.then)return void e.then(o.bind(null,n,t),o.bind(null,n,2));n.s=t,n.v=e;const u=n.o;u&&u(n)}}const u={};return function(){function n(n){this._entry=n,this._pact=null,this._resolve=null,this._return=null,this._promise=null}function t(n){return{value:n,done:!0}}function e(n){return{value:n,done:!1}}n.prototype[Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator"))]=function(){return this},n.prototype._yield=function(n){return this._resolve(n&&n.then?n.then(e):e(n)),this._pact=new r},n.prototype.next=function(n){const e=this;return e._promise=new Promise(function(i){const l=e._pact;if(null===l){const n=e._entry;if(null===n)return i(e._promise);function s(n){e._resolve(n&&n.then?n.then(t):t(n)),e._pact=null,e._resolve=null}e._entry=null,e._resolve=i,n(e).then(s,function(n){if(n===u)s(e._return);else{const t=new r;e._resolve(t),e._pact=null,e._resolve=null,_resolve(t,2,n)}})}else e._pact=null,e._resolve=i,o(l,1,n)})},n.prototype.return=function(n){const e=this;return e._promise=new Promise(function(r){const i=e._pact;if(null===i)return null===e._entry?r(e._promise):(e._entry=null,r(n&&n.then?n.then(t):t(n)));e._return=n,e._resolve=r,e._pact=null,o(i,2,u)})},n.prototype.throw=function(n){const t=this;return t._promise=new Promise(function(e,r){const u=t._pact;if(null===u)return null===t._entry?e(t._promise):(t._entry=null,r(n));t._resolve=e,t._pact=null,o(u,2,n)})}}(),function(r,o){void 0===o&&(o={});var u=n.useState({data:null,loading:0,error:null,controller:null}),i=u[0],l=u[1],s=n.useRef(!1);return n.useLayoutEffect(function(){return s.current=!0,function(){s.current=!1}},[]),n.useEffect(function(){var n=new AbortController;return r&&(l(function(t){return{data:null,loading:t.loading+1,error:null,controller:n}}),function(n,r,o,u){try{var i=Object.assign({},r,{signal:o});Promise.resolve(function(r,o){try{var l=Promise.resolve(fetch(n,i)).then(function(n){function r(){u(function(n){return Object.assign({},n,{data:i,loading:n.loading-1})})}if(!n.ok){var o=new Error(n.statusText);throw o.status=n.status,o}var i=null,l=function(n){if(n){var r=e.parse(n),o=t.parse(r.type);if("json"===o.subtype)return!0;if("json"===o.suffix)return!0;if(o.suffix&&/\bjson\b/i.test(o.suffix))return!0;if(o.subtype&&/\bjson\b/i.test(o.subtype))return!0}return!1}(n.headers.get("content-type"))?Promise.resolve(n.json()).then(function(n){i=n}):Promise.resolve(n.text()).then(function(n){i=n});return l&&l.then?l.then(r):r()})}catch(n){return o(n)}return l&&l.then?l.then(void 0,o):l}(0,function(n){var t="AbortError"!==n.name?n:null;u(function(n){return Object.assign({},n,{error:t,loading:n.loading-1})})}))}catch(n){return Promise.reject(n)}}(r,o,n.signal,function(n){s.current&&l(n)})),function(){return n.abort()}},[r]),{data:i.data,loading:!!i.loading,error:i.error,abort:function(){return i.controller&&i.controller.abort()}}}}); | ||
//# sourceMappingURL=index.umd.js.map |
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
35531678
3