@marianmeres/fetch-store 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.umd.js +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=e=>"function"==typeof e,t=(t,r="")=>{if(!e(t))throw new TypeError(`${r} Expecting function arg`.trim())},r=t=>e(t.subscribe),s=(r=void 0,s=null)=>{const n=t=>e(s?.persist)&&s.persist(t);let c=(()=>{const e=new Map,t=t=>(e.has(t)||e.set(t,new Set),e.get(t)),r=(e,r)=>{if("function"!=typeof r)throw new TypeError("Expecting callback function as second argument");return t(e).add(r),()=>t(e).delete(r)};return{publish:(e,r
|
|
1
|
+
"use strict";const e=e=>"function"==typeof e,t=(t,r="")=>{if(!e(t))throw new TypeError(`${r} Expecting function arg`.trim())},r=t=>e(t.subscribe),s=(r=void 0,s=null)=>{const n=t=>e(s?.persist)&&s.persist(t);let c=(()=>{const e=new Map,t=t=>(e.has(t)||e.set(t,new Set),e.get(t)),r=(e,r)=>{if("function"!=typeof r)throw new TypeError("Expecting callback function as second argument");return t(e).add(r),()=>t(e).delete(r)};return{publish:(e,r)=>{t(e).forEach((e=>e(r)))},subscribe:r,subscribeOnce:(e,t)=>{const s=r(e,(e=>{t(e),s()}));return s},unsubscribeAll:t=>e.delete(t)}})(),a=r;n(a);const l=()=>a,o=e=>{a!==e&&(a=e,n(a),c.publish("change",a))};return{set:o,get:l,update:e=>{t(e,"[update]"),o(e(l()))},subscribe:e=>(t(e,"[subscribe]"),e(a),c.subscribe("change",e))}},n={fetchOnceDefaultThresholdMs:3e5},c=e=>"function"==typeof e;exports.createFetchStore=(a,l=null,o=null,i=null)=>{const{logger:u,onError:h,onSilentError:b,afterCreate:g,fetchOnceDefaultThresholdMs:f}={...n,...i||{}},p=(e,t)=>c(o)?o(e,t):e,d=s(p(l)),E=s({isFetching:!1,lastFetchStart:null,lastFetchEnd:null,lastFetchError:null,successCounter:0}),{subscribe:w,get:F}=((n,c,a=null)=>{const l=t=>e(a?.persist)&&a.persist(t),o=s(a?.initialValue),i=[];if(n.forEach((e=>{if(!r(e))throw new TypeError("Expecting array of StoreLike objects");e.subscribe((e=>i.push(e)))()})),!e(c))throw new TypeError("Expecting second argument to be the derivative function");if(!c.length||c.length>2)throw new TypeError("Expecting the derivative function to have exactly 1 or 2 arguments");let u=0,h=[];return{get:o.get,subscribe:e=>{t(e,"[derived.subscribe]"),u++||n.forEach(((e,t)=>{h.push(e.subscribe((e=>{i[t]=e,1===c.length?(o.set(c(i)),l(o.get())):c(i,(e=>{o.set(e),l(o.get())}))})))}));const r=o.subscribe(e);return()=>{--u||(h.forEach((e=>e())),h=[]),r()}}}})([d,E],(([e,t])=>({data:e,...t})));w((()=>null));const y=async(...e)=>{let t=d.get(),r=E.get();const s=new Date;let n=null;E.set({...r,isFetching:!0,lastFetchStart:s,lastFetchEnd:null,lastFetchError:n});try{t=p(await a(...e),t),r.successCounter++}catch(e){n=e}return d.set(t),E.set({...r,isFetching:!1,lastFetchStart:s,lastFetchEnd:new Date,lastFetchError:n}),n&&c(h)&&h(n),t},S={subscribe:w,get:F,fetch:y,fetchSilent:async(...e)=>{try{let t=p(await a(...e),d.get());return d.set(t),t}catch(e){((...e)=>{c(u)&&u.apply(null,e)})("silent fetch error",e),c(b)&&b(e)}},fetchOnce:async(e=[],t=f)=>{const{successCounter:r,isFetching:s,lastFetchStart:n}=E.get();return Array.isArray(e)||(e=[e]),r||s?t&&!s&&n&&Date.now()-new Date(n).valueOf()>t?await y(...e):void 0:await y(...e)},reset:()=>{d.set(p(l)),E.set({isFetching:!1,lastFetchStart:null,lastFetchEnd:null,lastFetchError:null,successCounter:0})},resetError:()=>E.update((e=>({...e,lastFetchError:null}))),getInternalDataStore:()=>d};return c(g)&&(console?.warn?.("`afterCreate` option is deprecated and will be removed"),g(S)),S};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=e=>"function"==typeof e,t=(t,r="")=>{if(!e(t))throw new TypeError(`${r} Expecting function arg`.trim())},r=t=>e(t.subscribe),s=(r=void 0,s=null)=>{const n=t=>e(s?.persist)&&s.persist(t);let c=(()=>{const e=new Map,t=t=>(e.has(t)||e.set(t,new Set),e.get(t)),r=(e,r)=>{if("function"!=typeof r)throw new TypeError("Expecting callback function as second argument");return t(e).add(r),()=>t(e).delete(r)};return{publish:(e,r
|
|
1
|
+
const e=e=>"function"==typeof e,t=(t,r="")=>{if(!e(t))throw new TypeError(`${r} Expecting function arg`.trim())},r=t=>e(t.subscribe),s=(r=void 0,s=null)=>{const n=t=>e(s?.persist)&&s.persist(t);let c=(()=>{const e=new Map,t=t=>(e.has(t)||e.set(t,new Set),e.get(t)),r=(e,r)=>{if("function"!=typeof r)throw new TypeError("Expecting callback function as second argument");return t(e).add(r),()=>t(e).delete(r)};return{publish:(e,r)=>{t(e).forEach((e=>e(r)))},subscribe:r,subscribeOnce:(e,t)=>{const s=r(e,(e=>{t(e),s()}));return s},unsubscribeAll:t=>e.delete(t)}})(),a=r;n(a);const l=()=>a,o=e=>{a!==e&&(a=e,n(a),c.publish("change",a))};return{set:o,get:l,update:e=>{t(e,"[update]"),o(e(l()))},subscribe:e=>(t(e,"[subscribe]"),e(a),c.subscribe("change",e))}},n={fetchOnceDefaultThresholdMs:3e5},c=e=>"function"==typeof e,a=(a,l=null,o=null,i=null)=>{const{logger:u,onError:h,onSilentError:b,afterCreate:g,fetchOnceDefaultThresholdMs:f}={...n,...i||{}},p=(e,t)=>c(o)?o(e,t):e,d=s(p(l)),E=s({isFetching:!1,lastFetchStart:null,lastFetchEnd:null,lastFetchError:null,successCounter:0}),{subscribe:w,get:F}=((n,c,a=null)=>{const l=t=>e(a?.persist)&&a.persist(t),o=s(a?.initialValue),i=[];if(n.forEach((e=>{if(!r(e))throw new TypeError("Expecting array of StoreLike objects");e.subscribe((e=>i.push(e)))()})),!e(c))throw new TypeError("Expecting second argument to be the derivative function");if(!c.length||c.length>2)throw new TypeError("Expecting the derivative function to have exactly 1 or 2 arguments");let u=0,h=[];return{get:o.get,subscribe:e=>{t(e,"[derived.subscribe]"),u++||n.forEach(((e,t)=>{h.push(e.subscribe((e=>{i[t]=e,1===c.length?(o.set(c(i)),l(o.get())):c(i,(e=>{o.set(e),l(o.get())}))})))}));const r=o.subscribe(e);return()=>{--u||(h.forEach((e=>e())),h=[]),r()}}}})([d,E],(([e,t])=>({data:e,...t})));w((()=>null));const y=async(...e)=>{let t=d.get(),r=E.get();const s=new Date;let n=null;E.set({...r,isFetching:!0,lastFetchStart:s,lastFetchEnd:null,lastFetchError:n});try{t=p(await a(...e),t),r.successCounter++}catch(e){n=e}return d.set(t),E.set({...r,isFetching:!1,lastFetchStart:s,lastFetchEnd:new Date,lastFetchError:n}),n&&c(h)&&h(n),t},v={subscribe:w,get:F,fetch:y,fetchSilent:async(...e)=>{try{let t=p(await a(...e),d.get());return d.set(t),t}catch(e){((...e)=>{c(u)&&u.apply(null,e)})("silent fetch error",e),c(b)&&b(e)}},fetchOnce:async(e=[],t=f)=>{const{successCounter:r,isFetching:s,lastFetchStart:n}=E.get();return Array.isArray(e)||(e=[e]),r||s?t&&!s&&n&&Date.now()-new Date(n).valueOf()>t?await y(...e):void 0:await y(...e)},reset:()=>{d.set(p(l)),E.set({isFetching:!1,lastFetchStart:null,lastFetchEnd:null,lastFetchError:null,successCounter:0})},resetError:()=>E.update((e=>({...e,lastFetchError:null}))),getInternalDataStore:()=>d};return c(g)&&(console?.warn?.("`afterCreate` option is deprecated and will be removed"),g(v)),v};export{a as createFetchStore};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["fetch-store"]={})}(this,(function(e){"use strict";const t=e=>"function"==typeof e,r=(e,r="")=>{if(!t(e))throw new TypeError(`${r} Expecting function arg`.trim())},n=e=>t(e.subscribe),s=(e=void 0,n=null)=>{const s=e=>t(n?.persist)&&n.persist(e);let c=(()=>{const e=new Map,t=t=>(e.has(t)||e.set(t,new Set),e.get(t)),r=(e,r)=>{if("function"!=typeof r)throw new TypeError("Expecting callback function as second argument");return t(e).add(r),()=>t(e).delete(r)};return{publish:(e,r
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["fetch-store"]={})}(this,(function(e){"use strict";const t=e=>"function"==typeof e,r=(e,r="")=>{if(!t(e))throw new TypeError(`${r} Expecting function arg`.trim())},n=e=>t(e.subscribe),s=(e=void 0,n=null)=>{const s=e=>t(n?.persist)&&n.persist(e);let c=(()=>{const e=new Map,t=t=>(e.has(t)||e.set(t,new Set),e.get(t)),r=(e,r)=>{if("function"!=typeof r)throw new TypeError("Expecting callback function as second argument");return t(e).add(r),()=>t(e).delete(r)};return{publish:(e,r)=>{t(e).forEach((e=>e(r)))},subscribe:r,subscribeOnce:(e,t)=>{const n=r(e,(e=>{t(e),n()}));return n},unsubscribeAll:t=>e.delete(t)}})(),o=e;s(o);const a=()=>o,l=e=>{o!==e&&(o=e,s(o),c.publish("change",o))};return{set:l,get:a,update:e=>{r(e,"[update]"),l(e(a()))},subscribe:e=>(r(e,"[subscribe]"),e(o),c.subscribe("change",e))}},c={fetchOnceDefaultThresholdMs:3e5},o=e=>"function"==typeof e;e.createFetchStore=(e,a=null,l=null,i=null)=>{const{logger:u,onError:h,onSilentError:f,afterCreate:b,fetchOnceDefaultThresholdMs:g}={...c,...i||{}},p=(e,t)=>o(l)?l(e,t):e,d=s(p(a)),E=s({isFetching:!1,lastFetchStart:null,lastFetchEnd:null,lastFetchError:null,successCounter:0}),{subscribe:w,get:y}=((e,c,o=null)=>{const a=e=>t(o?.persist)&&o.persist(e),l=s(o?.initialValue),i=[];if(e.forEach((e=>{if(!n(e))throw new TypeError("Expecting array of StoreLike objects");e.subscribe((e=>i.push(e)))()})),!t(c))throw new TypeError("Expecting second argument to be the derivative function");if(!c.length||c.length>2)throw new TypeError("Expecting the derivative function to have exactly 1 or 2 arguments");let u=0,h=[];return{get:l.get,subscribe:t=>{r(t,"[derived.subscribe]"),u++||e.forEach(((e,t)=>{h.push(e.subscribe((e=>{i[t]=e,1===c.length?(l.set(c(i)),a(l.get())):c(i,(e=>{l.set(e),a(l.get())}))})))}));const n=l.subscribe(t);return()=>{--u||(h.forEach((e=>e())),h=[]),n()}}}})([d,E],(([e,t])=>({data:e,...t})));w((()=>null));const F=async(...t)=>{let r=d.get(),n=E.get();const s=new Date;let c=null;E.set({...n,isFetching:!0,lastFetchStart:s,lastFetchEnd:null,lastFetchError:c});try{r=p(await e(...t),r),n.successCounter++}catch(e){c=e}return d.set(r),E.set({...n,isFetching:!1,lastFetchStart:s,lastFetchEnd:new Date,lastFetchError:c}),c&&o(h)&&h(c),r},S={subscribe:w,get:y,fetch:F,fetchSilent:async(...t)=>{try{let r=p(await e(...t),d.get());return d.set(r),r}catch(e){((...e)=>{o(u)&&u.apply(null,e)})("silent fetch error",e),o(f)&&f(e)}},fetchOnce:async(e=[],t=g)=>{const{successCounter:r,isFetching:n,lastFetchStart:s}=E.get();return Array.isArray(e)||(e=[e]),r||n?t&&!n&&s&&Date.now()-new Date(s).valueOf()>t?await F(...e):void 0:await F(...e)},reset:()=>{d.set(p(a)),E.set({isFetching:!1,lastFetchStart:null,lastFetchEnd:null,lastFetchError:null,successCounter:0})},resetError:()=>E.update((e=>({...e,lastFetchError:null}))),getInternalDataStore:()=>d};return o(b)&&(console?.warn?.("`afterCreate` option is deprecated and will be removed"),b(S)),S}}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marianmeres/fetch-store",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -56,6 +56,6 @@
|
|
|
56
56
|
"typescript": "^4.9.5"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@marianmeres/store": "^1.
|
|
59
|
+
"@marianmeres/store": "^1.3.0"
|
|
60
60
|
}
|
|
61
61
|
}
|