@effection/fetch
Advanced tools
Comparing version 0.1.1 to 0.1.2-19f9726
# @effection/fetch | ||
## 0.1.2 | ||
### Patch Changes | ||
- e767e69: convert response into a resource so that the request is only aborted | ||
when the response passes out of scope | ||
## 0.1.1 | ||
@@ -4,0 +11,0 @@ |
'use strict'; | ||
var abortController = require('abort-controller'); | ||
var effection = require('effection'); | ||
var crossFetch = require('cross-fetch'); | ||
function* fetch(resource, init) { | ||
function* fetch(info, init) { | ||
if (init === void 0) { | ||
@@ -13,7 +14,17 @@ init = {}; | ||
init.signal = controller.signal; | ||
var response; | ||
try { | ||
return yield crossFetch.fetch(resource, init); | ||
response = yield crossFetch.fetch(info, init); | ||
return yield effection.resource(response, function* () { | ||
try { | ||
yield; | ||
} finally { | ||
controller.abort(); | ||
} | ||
}); | ||
} finally { | ||
controller.abort(); | ||
if (!response) { | ||
controller.abort(); | ||
} | ||
} | ||
@@ -20,0 +31,0 @@ } |
@@ -1,2 +0,2 @@ | ||
"use strict";var r=require("abort-controller"),e=require("cross-fetch");Object.defineProperty(exports,"AbortController",{enumerable:!0,get:function(){return r.AbortController}}),exports.fetch=function*(t,o){void 0===o&&(o={});var n=new r.AbortController;o.signal=n.signal;try{return yield e.fetch(t,o)}finally{n.abort()}}; | ||
"use strict";var r=require("abort-controller"),e=require("effection"),t=require("cross-fetch");Object.defineProperty(exports,"AbortController",{enumerable:!0,get:function(){return r.AbortController}}),exports.fetch=function*(o,n){void 0===n&&(n={});var l,i=new r.AbortController;n.signal=i.signal;try{return l=yield t.fetch(o,n),yield e.resource(l,(function*(){try{yield}finally{i.abort()}}))}finally{l||i.abort()}}; | ||
//# sourceMappingURL=fetch.cjs.production.min.js.map |
import { Operation } from 'effection'; | ||
export declare function fetch(resource: RequestInfo, init?: RequestInit): Operation<Response>; | ||
export declare function fetch(info: RequestInfo, init?: RequestInit): Operation<Response>; |
import { AbortController } from 'abort-controller'; | ||
export { AbortController } from 'abort-controller'; | ||
import { resource } from 'effection'; | ||
import { fetch as fetch$1 } from 'cross-fetch'; | ||
function* fetch(resource, init) { | ||
function* fetch(info, init) { | ||
if (init === void 0) { | ||
@@ -12,7 +13,17 @@ init = {}; | ||
init.signal = controller.signal; | ||
var response; | ||
try { | ||
return yield fetch$1(resource, init); | ||
response = yield fetch$1(info, init); | ||
return yield resource(response, function* () { | ||
try { | ||
yield; | ||
} finally { | ||
controller.abort(); | ||
} | ||
}); | ||
} finally { | ||
controller.abort(); | ||
if (!response) { | ||
controller.abort(); | ||
} | ||
} | ||
@@ -19,0 +30,0 @@ } |
{ | ||
"name": "@effection/fetch", | ||
"version": "0.1.1", | ||
"version": "0.1.2-19f9726", | ||
"description": "Fetch operation for Effection", | ||
@@ -23,16 +23,15 @@ "main": "dist/index.js", | ||
"@frontside/tsconfig": "^0.0.1", | ||
"@types/express": "4.17.6", | ||
"@types/node": "^13.13.4", | ||
"expect": "26.0.1", | ||
"express": "4.17.1", | ||
"mocha": "7.2.0", | ||
"ts-node": "8.10.2", | ||
"tsdx": "0.13.2" | ||
"tsdx": "0.13.2", | ||
"typescript": "^3.9.5" | ||
}, | ||
"dependencies": { | ||
"effection": "^0.7.0", | ||
"abort-controller": "^3.0.0", | ||
"cross-fetch": "^3.0.4", | ||
"node-fetch": "^2.6.0" | ||
"effection": "^0.7.0", | ||
"node-fetch": "^2.6.1" | ||
} | ||
} |
@@ -1,13 +0,23 @@ | ||
import { Operation } from 'effection'; | ||
import { Operation, resource } from 'effection'; | ||
import { fetch as nativeFetch } from 'cross-fetch'; | ||
import { AbortController } from 'abort-controller'; | ||
export function* fetch(resource: RequestInfo, init: RequestInit = {}): Operation<Response> { | ||
export function* fetch(info: RequestInfo, init: RequestInit = {}): Operation<Response> { | ||
let controller = new AbortController(); | ||
init.signal = controller.signal; | ||
let response: Response | undefined; | ||
try { | ||
return yield nativeFetch(resource, init); | ||
response = yield nativeFetch(info, init); | ||
return yield resource(response as Response, function*() { | ||
try { | ||
yield; | ||
} finally { | ||
controller.abort(); | ||
} | ||
}); | ||
} finally { | ||
controller.abort(); | ||
if (!response) { | ||
controller.abort(); | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
8702
7
99
Updatednode-fetch@^2.6.1