wretch
Version:
A tiny wrapper built around fetch with an intuitive syntax.
3 lines (2 loc) • 806 B
JavaScript
var global,factory;global=this,factory=function(e){const t=(e,t)=>t.skipDedupe||"GET"!==t.method,o=(e,t)=>t.method+"@"+e,r=e=>e.clone();e.dedupe=({skip:e=t,key:n=o,resolver:f=r}={})=>{const a=new Map;return t=>(o,r)=>{if(e(o,r))return t(o,r);const c=n(o,r);if(a.has(c))return new Promise(((e,t)=>{a.get(c).push([e,t])}));a.set(c,[]);try{return t(o,r).then((e=>(a.get(c).forEach((([t])=>t(f(e)))),a.delete(c),e))).catch((e=>{throw a.get(c).forEach((([t,o])=>o(e))),a.delete(c),e}))}catch(e){return a.delete(c),Promise.reject(e)}}}},"object"==typeof exports&&"undefined"!=typeof module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory((global="undefined"!=typeof globalThis?globalThis:global||self).wretchDedupeMiddleware={});
//# sourceMappingURL=dedupe.min.js.map