@depup/jotai 2.18.0-depup.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/LICENSE +21 -0
- package/README.md +25 -0
- package/babel/plugin-debug-label.d.ts +5 -0
- package/babel/plugin-debug-label.js +54 -0
- package/babel/plugin-react-refresh.d.ts +5 -0
- package/babel/plugin-react-refresh.js +72 -0
- package/babel/preset.d.ts +6 -0
- package/babel/preset.js +110 -0
- package/babel/utils.d.ts +5 -0
- package/benchmarks/simple-read.d.ts +2 -0
- package/benchmarks/simple-write.d.ts +2 -0
- package/benchmarks/subscribe-write.d.ts +2 -0
- package/changes.json +5 -0
- package/esm/babel/plugin-debug-label.d.mts +5 -0
- package/esm/babel/plugin-debug-label.mjs +103 -0
- package/esm/babel/plugin-react-refresh.d.mts +5 -0
- package/esm/babel/plugin-react-refresh.mjs +121 -0
- package/esm/babel/preset.d.mts +6 -0
- package/esm/babel/preset.mjs +179 -0
- package/esm/babel/utils.d.mts +5 -0
- package/esm/index.d.mts +2 -0
- package/esm/index.mjs +2 -0
- package/esm/react/Provider.d.mts +16 -0
- package/esm/react/useAtom.d.mts +13 -0
- package/esm/react/useAtomValue.d.mts +9 -0
- package/esm/react/useSetAtom.d.mts +7 -0
- package/esm/react/utils/useAtomCallback.d.mts +5 -0
- package/esm/react/utils/useHydrateAtoms.d.mts +14 -0
- package/esm/react/utils/useReducerAtom.d.mts +14 -0
- package/esm/react/utils/useResetAtom.d.mts +6 -0
- package/esm/react/utils.d.mts +4 -0
- package/esm/react/utils.mjs +57 -0
- package/esm/react.d.mts +4 -0
- package/esm/react.mjs +182 -0
- package/esm/utils.d.mts +2 -0
- package/esm/utils.mjs +2 -0
- package/esm/vanilla/atom.d.mts +47 -0
- package/esm/vanilla/internals.d.mts +164 -0
- package/esm/vanilla/internals.mjs +715 -0
- package/esm/vanilla/store.d.mts +5 -0
- package/esm/vanilla/typeUtils.d.mts +7 -0
- package/esm/vanilla/utils/atomFamily.d.mts +55 -0
- package/esm/vanilla/utils/atomWithDefault.d.mts +6 -0
- package/esm/vanilla/utils/atomWithLazy.d.mts +2 -0
- package/esm/vanilla/utils/atomWithObservable.d.mts +32 -0
- package/esm/vanilla/utils/atomWithReducer.d.mts +3 -0
- package/esm/vanilla/utils/atomWithRefresh.d.mts +6 -0
- package/esm/vanilla/utils/atomWithReset.d.mts +8 -0
- package/esm/vanilla/utils/atomWithStorage.d.mts +50 -0
- package/esm/vanilla/utils/constants.d.mts +1 -0
- package/esm/vanilla/utils/freezeAtom.d.mts +6 -0
- package/esm/vanilla/utils/loadable.d.mts +33 -0
- package/esm/vanilla/utils/selectAtom.d.mts +2 -0
- package/esm/vanilla/utils/splitAtom.d.mts +16 -0
- package/esm/vanilla/utils/unwrap.d.mts +5 -0
- package/esm/vanilla/utils.d.mts +14 -0
- package/esm/vanilla/utils.mjs +736 -0
- package/esm/vanilla.d.mts +4 -0
- package/esm/vanilla.mjs +59 -0
- package/index.d.ts +2 -0
- package/index.js +19 -0
- package/package.json +125 -0
- package/react/Provider.d.ts +16 -0
- package/react/useAtom.d.ts +13 -0
- package/react/useAtomValue.d.ts +9 -0
- package/react/useSetAtom.d.ts +7 -0
- package/react/utils/useAtomCallback.d.ts +5 -0
- package/react/utils/useHydrateAtoms.d.ts +14 -0
- package/react/utils/useReducerAtom.d.ts +14 -0
- package/react/utils/useResetAtom.d.ts +6 -0
- package/react/utils.d.ts +4 -0
- package/react/utils.js +100 -0
- package/react.d.ts +4 -0
- package/react.js +182 -0
- package/system/babel/plugin-debug-label.development.js +113 -0
- package/system/babel/plugin-debug-label.production.js +4 -0
- package/system/babel/plugin-react-refresh.development.js +131 -0
- package/system/babel/plugin-react-refresh.production.js +11 -0
- package/system/babel/preset.development.js +189 -0
- package/system/babel/preset.production.js +14 -0
- package/system/index.development.js +27 -0
- package/system/index.production.js +1 -0
- package/system/react/utils.development.js +79 -0
- package/system/react/utils.production.js +2 -0
- package/system/react.development.js +210 -0
- package/system/react.production.js +2 -0
- package/system/utils.development.js +27 -0
- package/system/utils.production.js +1 -0
- package/system/vanilla/internals.development.js +735 -0
- package/system/vanilla/internals.production.js +1 -0
- package/system/vanilla/utils.development.js +764 -0
- package/system/vanilla/utils.production.js +1 -0
- package/system/vanilla.development.js +75 -0
- package/system/vanilla.production.js +1 -0
- package/ts3.8/babel/plugin-debug-label.d.ts +6 -0
- package/ts3.8/babel/plugin-react-refresh.d.ts +6 -0
- package/ts3.8/babel/preset.d.ts +7 -0
- package/ts3.8/babel/utils.d.ts +6 -0
- package/ts3.8/benchmarks/simple-read.d.ts +3 -0
- package/ts3.8/benchmarks/simple-write.d.ts +3 -0
- package/ts3.8/benchmarks/subscribe-write.d.ts +3 -0
- package/ts3.8/esm/babel/plugin-debug-label.d.ts +6 -0
- package/ts3.8/esm/babel/plugin-react-refresh.d.ts +6 -0
- package/ts3.8/esm/babel/preset.d.ts +7 -0
- package/ts3.8/esm/babel/utils.d.ts +6 -0
- package/ts3.8/esm/index.d.ts +3 -0
- package/ts3.8/esm/react/Provider.d.ts +17 -0
- package/ts3.8/esm/react/useAtom.d.ts +28 -0
- package/ts3.8/esm/react/useAtomValue.d.ts +10 -0
- package/ts3.8/esm/react/useSetAtom.d.ts +8 -0
- package/ts3.8/esm/react/utils/useAtomCallback.d.ts +6 -0
- package/ts3.8/esm/react/utils/useHydrateAtoms.d.ts +27 -0
- package/ts3.8/esm/react/utils/useReducerAtom.d.ts +21 -0
- package/ts3.8/esm/react/utils/useResetAtom.d.ts +9 -0
- package/ts3.8/esm/react/utils.d.ts +5 -0
- package/ts3.8/esm/react.d.ts +5 -0
- package/ts3.8/esm/utils.d.ts +3 -0
- package/ts3.8/esm/vanilla/atom.d.ts +48 -0
- package/ts3.8/esm/vanilla/internals.d.ts +165 -0
- package/ts3.8/esm/vanilla/store.d.ts +6 -0
- package/ts3.8/esm/vanilla/typeUtils.d.ts +8 -0
- package/ts3.8/esm/vanilla/utils/atomFamily.d.ts +56 -0
- package/ts3.8/esm/vanilla/utils/atomWithDefault.d.ts +11 -0
- package/ts3.8/esm/vanilla/utils/atomWithLazy.d.ts +3 -0
- package/ts3.8/esm/vanilla/utils/atomWithObservable.d.ts +37 -0
- package/ts3.8/esm/vanilla/utils/atomWithReducer.d.ts +8 -0
- package/ts3.8/esm/vanilla/utils/atomWithRefresh.d.ts +10 -0
- package/ts3.8/esm/vanilla/utils/atomWithReset.d.ts +11 -0
- package/ts3.8/esm/vanilla/utils/atomWithStorage.d.ts +53 -0
- package/ts3.8/esm/vanilla/utils/constants.d.ts +2 -0
- package/ts3.8/esm/vanilla/utils/freezeAtom.d.ts +7 -0
- package/ts3.8/esm/vanilla/utils/loadable.d.ts +34 -0
- package/ts3.8/esm/vanilla/utils/selectAtom.d.ts +3 -0
- package/ts3.8/esm/vanilla/utils/splitAtom.d.ts +21 -0
- package/ts3.8/esm/vanilla/utils/unwrap.d.ts +6 -0
- package/ts3.8/esm/vanilla/utils.d.ts +15 -0
- package/ts3.8/esm/vanilla.d.ts +5 -0
- package/ts3.8/index.d.ts +3 -0
- package/ts3.8/react/Provider.d.ts +17 -0
- package/ts3.8/react/useAtom.d.ts +28 -0
- package/ts3.8/react/useAtomValue.d.ts +10 -0
- package/ts3.8/react/useSetAtom.d.ts +8 -0
- package/ts3.8/react/utils/useAtomCallback.d.ts +6 -0
- package/ts3.8/react/utils/useHydrateAtoms.d.ts +27 -0
- package/ts3.8/react/utils/useReducerAtom.d.ts +21 -0
- package/ts3.8/react/utils/useResetAtom.d.ts +9 -0
- package/ts3.8/react/utils.d.ts +5 -0
- package/ts3.8/react.d.ts +5 -0
- package/ts3.8/utils.d.ts +3 -0
- package/ts3.8/vanilla/atom.d.ts +48 -0
- package/ts3.8/vanilla/internals.d.ts +165 -0
- package/ts3.8/vanilla/store.d.ts +6 -0
- package/ts3.8/vanilla/typeUtils.d.ts +8 -0
- package/ts3.8/vanilla/utils/atomFamily.d.ts +56 -0
- package/ts3.8/vanilla/utils/atomWithDefault.d.ts +11 -0
- package/ts3.8/vanilla/utils/atomWithLazy.d.ts +3 -0
- package/ts3.8/vanilla/utils/atomWithObservable.d.ts +37 -0
- package/ts3.8/vanilla/utils/atomWithReducer.d.ts +8 -0
- package/ts3.8/vanilla/utils/atomWithRefresh.d.ts +10 -0
- package/ts3.8/vanilla/utils/atomWithReset.d.ts +11 -0
- package/ts3.8/vanilla/utils/atomWithStorage.d.ts +53 -0
- package/ts3.8/vanilla/utils/constants.d.ts +2 -0
- package/ts3.8/vanilla/utils/freezeAtom.d.ts +7 -0
- package/ts3.8/vanilla/utils/loadable.d.ts +34 -0
- package/ts3.8/vanilla/utils/selectAtom.d.ts +3 -0
- package/ts3.8/vanilla/utils/splitAtom.d.ts +21 -0
- package/ts3.8/vanilla/utils/unwrap.d.ts +6 -0
- package/ts3.8/vanilla/utils.d.ts +15 -0
- package/ts3.8/vanilla.d.ts +5 -0
- package/ts_version_3.8_and_above_is_required.d.ts +0 -0
- package/umd/babel/plugin-debug-label.development.js +58 -0
- package/umd/babel/plugin-debug-label.production.js +1 -0
- package/umd/babel/plugin-react-refresh.development.js +76 -0
- package/umd/babel/plugin-react-refresh.production.js +1 -0
- package/umd/babel/preset.development.js +114 -0
- package/umd/babel/preset.production.js +1 -0
- package/umd/index.development.js +20 -0
- package/umd/index.production.js +1 -0
- package/umd/react/utils.development.js +101 -0
- package/umd/react/utils.production.js +1 -0
- package/umd/react.development.js +184 -0
- package/umd/react.production.js +1 -0
- package/umd/utils.development.js +20 -0
- package/umd/utils.production.js +1 -0
- package/umd/vanilla/internals.development.js +785 -0
- package/umd/vanilla/internals.production.js +1 -0
- package/umd/vanilla/utils.development.js +858 -0
- package/umd/vanilla/utils.production.js +1 -0
- package/umd/vanilla.development.js +64 -0
- package/umd/vanilla.production.js +1 -0
- package/utils.d.ts +2 -0
- package/utils.js +19 -0
- package/vanilla/atom.d.ts +47 -0
- package/vanilla/internals.d.ts +164 -0
- package/vanilla/internals.js +779 -0
- package/vanilla/store.d.ts +5 -0
- package/vanilla/typeUtils.d.ts +7 -0
- package/vanilla/utils/atomFamily.d.ts +55 -0
- package/vanilla/utils/atomWithDefault.d.ts +6 -0
- package/vanilla/utils/atomWithLazy.d.ts +2 -0
- package/vanilla/utils/atomWithObservable.d.ts +32 -0
- package/vanilla/utils/atomWithReducer.d.ts +3 -0
- package/vanilla/utils/atomWithRefresh.d.ts +6 -0
- package/vanilla/utils/atomWithReset.d.ts +8 -0
- package/vanilla/utils/atomWithStorage.d.ts +50 -0
- package/vanilla/utils/constants.d.ts +1 -0
- package/vanilla/utils/freezeAtom.d.ts +6 -0
- package/vanilla/utils/loadable.d.ts +33 -0
- package/vanilla/utils/selectAtom.d.ts +2 -0
- package/vanilla/utils/splitAtom.d.ts +16 -0
- package/vanilla/utils/unwrap.d.ts +5 -0
- package/vanilla/utils.d.ts +14 -0
- package/vanilla/utils.js +854 -0
- package/vanilla.d.ts +4 -0
- package/vanilla.js +60 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
System.register(["jotai/vanilla"],(function(x){"use strict";var m;return{setters:[function(O){m=O.atom}],execute:(function(){x({atomFamily:$,atomWithDefault:X,atomWithLazy:lt,atomWithObservable:nt,atomWithReducer:D,atomWithRefresh:at,atomWithReset:P,atomWithStorage:tt,createJSONStorage:V,freezeAtom:T,freezeAtomCreator:q,loadable:ct,selectAtom:K,splitAtom:U,unstable_withStorageValidator:Y,unwrap:_});const O=x("RESET",Symbol(""));function P(t){const e=m(t,(s,u,c)=>{const a=typeof c=="function"?c(s(e)):c;u(e,a===O?t:a)});return e}function D(t,e){return m(t,function(s,u,c){u(this,e(s(this),c))})}function $(t,e){let s=null;const u=new Map,c=new Set,a=i=>{let n;if(e===void 0)n=u.get(i);else for(const[l,f]of u)if(e(l,i)){n=f;break}if(n!==void 0)if(s!=null&&s(n[1],i))a.remove(i);else return n[0];const r=t(i);return u.set(i,[r,Date.now()]),o("CREATE",i,r),r},o=(i,n,r)=>{for(const l of c)l({type:i,param:n,atom:r})};return a.unstable_listen=i=>(c.add(i),()=>{c.delete(i)}),a.getParams=()=>u.keys(),a.remove=i=>{if(e===void 0){if(!u.has(i))return;const[n]=u.get(i);u.delete(i),o("REMOVE",i,n)}else for(const[n,[r]]of u)if(e(n,i)){u.delete(n),o("REMOVE",n,r);break}},a.setShouldRemove=i=>{if(s=i,!!s)for(const[n,[r,l]]of u)s(l,n)&&(u.delete(n),o("REMOVE",n,r))},a}const I=(t,e,s)=>(e.has(s)?e:e.set(s,t())).get(s),C=new WeakMap,F=(t,e,s,u)=>{const c=I(()=>new WeakMap,C,e),a=I(()=>new WeakMap,c,s);return I(t,a,u)};function K(t,e,s=Object.is){return F(()=>{const u=Symbol(),c=([o,i])=>{if(i===u)return e(o);const n=e(o,i);return s(i,n)?i:n},a=m(o=>{const i=o(a),n=o(t);return c([n,i])});return a.init=u,a},t,e,s)}const A=new WeakSet,L=t=>{if(typeof t!="object"||t===null)return t;Object.freeze(t);const e=Object.getOwnPropertyNames(t);for(const s of e)L(t[s]);return t};function T(t){if(A.has(t))return t;A.add(t);const e=t.read;if(t.read=function(s,u){return L(e.call(this,s,u))},"write"in t){const s=t.write;t.write=function(u,c,...a){return s.call(this,u,(...o)=>(o[0]===t&&(o[1]=L(o[1])),c(...o)),...a)}}return t}function q(t){return((...e)=>T(t(...e)))}const j=(t,e,s)=>(e.has(s)?e:e.set(s,t())).get(s),B=new WeakMap,G=(t,e,s)=>{const u=j(()=>new WeakMap,B,e);return j(t,u,s)},H={},N=t=>!!t.write,Q=t=>typeof t=="function";function U(t,e){return G(()=>{const s=new WeakMap,u=(o,i)=>{let n=s.get(o);if(n)return n;const r=i&&s.get(i),l=[],f=[];return o.forEach((b,v)=>{const d=e?e(b):v;f[v]=d;const g=r&&r.atomList[r.keyList.indexOf(d)];if(g){l[v]=g;return}const W=w=>{const y=w(c),h=w(t),k=u(h,y==null?void 0:y.arr).keyList.indexOf(d);if(k<0||k>=h.length){const p=o[u(o).keyList.indexOf(d)];if(p)return p;throw new Error("splitAtom: index out of bounds for read")}return h[k]},E=(w,y,h)=>{const k=w(c),p=w(t),S=u(p,k==null?void 0:k.arr).keyList.indexOf(d);if(S<0||S>=p.length)throw new Error("splitAtom: index out of bounds for write");const J=Q(h)?h(p[S]):h;Object.is(p[S],J)||y(t,[...p.slice(0,S),J,...p.slice(S+1)])};l[v]=N(t)?m(W,E):m(W)}),r&&r.keyList.length===f.length&&r.keyList.every((b,v)=>b===f[v])?n=r:n={arr:o,atomList:l,keyList:f},s.set(o,n),n},c=m(o=>{const i=o(c),n=o(t);return u(n,i==null?void 0:i.arr)});c.init=void 0;const a=N(t)?m(o=>o(c).atomList,(o,i,n)=>{switch(n.type){case"remove":{const r=o(a).indexOf(n.atom);if(r>=0){const l=o(t);i(t,[...l.slice(0,r),...l.slice(r+1)])}break}case"insert":{const r=n.before?o(a).indexOf(n.before):o(a).length;if(r>=0){const l=o(t);i(t,[...l.slice(0,r),n.value,...l.slice(r)])}break}case"move":{const r=o(a).indexOf(n.atom),l=n.before?o(a).indexOf(n.before):o(a).length;if(r>=0&&l>=0){const f=o(t);r<l?i(t,[...f.slice(0,r),...f.slice(r+1,l),f[r],...f.slice(l)]):i(t,[...f.slice(0,l),f[r],...f.slice(l,r),...f.slice(r+1)])}break}}}):m(o=>o(c).atomList);return a},t,e||H)}function X(t){const e=Symbol(),s=m(e),u=m((c,a)=>{const o=c(s);return o!==e?o:t(c,a)},(c,a,o)=>{const i=typeof o=="function"?o(c(u)):o;a(s,i===O?e:i)});return u}const M=t=>typeof(t==null?void 0:t.then)=="function";function Y(t){return e=>({...e,getItem:(s,u)=>{const c=o=>t(o)?o:u,a=e.getItem(s,u);return M(a)?a.then(c):c(a)}})}function V(t=()=>{try{return window.localStorage}catch(s){return}},e){var s;let u,c;const a={getItem:(n,r)=>{var l,f;const b=d=>{if(d=d||"",u!==d){try{c=JSON.parse(d,e==null?void 0:e.reviver)}catch(g){return r}u=d}return c},v=(f=(l=t())==null?void 0:l.getItem(n))!=null?f:null;return M(v)?v.then(b):b(v)},setItem:(n,r)=>{var l;return(l=t())==null?void 0:l.setItem(n,JSON.stringify(r,e==null?void 0:e.replacer))},removeItem:n=>{var r;return(r=t())==null?void 0:r.removeItem(n)}},o=n=>(r,l,f)=>n(r,b=>{let v;try{v=JSON.parse(b||"")}catch(d){v=f}l(v)});let i;try{i=(s=t())==null?void 0:s.subscribe}catch(n){}return!i&&typeof window!="undefined"&&typeof window.addEventListener=="function"&&window.Storage&&(i=(n,r)=>{if(!(t()instanceof window.Storage))return()=>{};const l=f=>{f.storageArea===t()&&f.key===n&&r(f.newValue)};return window.addEventListener("storage",l),()=>{window.removeEventListener("storage",l)}}),i&&(a.subscribe=o(i)),a}const Z=V();function tt(t,e,s=Z,u){const c=u==null?void 0:u.getOnInit,a=m(c?s.getItem(t,e):e);return a.onMount=o=>{o(s.getItem(t,e));let i;return s.subscribe&&(i=s.subscribe(t,o,e)),i},m(o=>o(a),(o,i,n)=>{const r=typeof n=="function"?n(o(a)):n;return r===O?(i(a,e),s.removeItem(t)):M(r)?r.then(l=>(i(a,l),s.setItem(t,l))):(i(a,r),s.setItem(t,r))})}const et=t=>typeof(t==null?void 0:t.then)=="function";function nt(t,e){const s=c=>{if("e"in c)throw c.e;return c.d},u=m(c=>{var a;let o=t(c);const i=(a=o[Symbol.observable])==null?void 0:a.call(o);i&&(o=i);let n;const r=()=>new Promise(h=>{n=h}),l=e&&"initialValue"in e?{d:typeof e.initialValue=="function"?e.initialValue():e.initialValue}:r();let f,b;const v=h=>{b=h,n==null||n(h),f==null||f(h)};let d,g;const W=()=>!f,E=()=>{d&&(d.unsubscribe(),d=void 0)},w=()=>{d&&(clearTimeout(g),d.unsubscribe()),d=o.subscribe({next:h=>v({d:h}),error:h=>v({e:h}),complete:()=>{}}),W()&&e!=null&&e.unstable_timeout&&(g=setTimeout(E,e.unstable_timeout))};w();const y=m(b||l);return y.onMount=h=>(f=h,b&&h(b),d?clearTimeout(g):w(),()=>{f=void 0,e!=null&&e.unstable_timeout?g=setTimeout(E,e.unstable_timeout):E()}),[y,o,r,w,W]});return m(c=>{const[a]=c(u),o=c(a);return et(o)?o.then(s):s(o)},(c,a,o)=>{const[i,n,r,l,f]=c(u);if("next"in n)f()&&(a(i,r()),l()),n.next(o);else throw new Error("observable is not subject")})}const z=(t,e,s)=>(e.has(s)?e:e.set(s,t())).get(s),ot=new WeakMap,rt=(t,e,s)=>{const u=z(()=>new WeakMap,ot,e);return z(t,u,s)},it=t=>typeof(t==null?void 0:t.then)=="function",st=()=>{};function _(t,e=st){return rt(()=>{const s=new WeakMap,u=new WeakMap,c=m(0),a=m([]);a.INTERNAL_onInit=i=>{i.set(a,[()=>i.set(c,n=>n+1)])};const o=m(i=>{i(c);let n;try{n=i(o)}catch(l){}const r=i(t);if(!it(r))return{v:r};if(r!==(n==null?void 0:n.p)&&r.then(l=>{u.set(r,l);const[f]=i(a);f()},l=>{s.set(r,l);const[f]=i(a);f()}),s.has(r))throw s.get(r);return u.has(r)?{p:r,v:u.get(r)}:n&&"v"in n?{p:r,f:e(n.v),v:n.v}:{p:r,f:e()}});return o.init=void 0,m(i=>{const n=i(o);return"f"in n?n.f:n.v},(i,n,...r)=>n(t,...r))},t,e)}const R=new WeakMap,ut=(t,e)=>(R.has(e)?R:R.set(e,t())).get(e);function ct(t){return ut(()=>{const e={state:"loading"},s=_(t,()=>e);return m(u=>{try{const c=u(s);return c===e?e:{state:"hasData",data:c}}catch(c){return{state:"hasError",error:c}}})},t)}function at(t,e){const s=m(0);return m((u,c)=>(u(s),t(u,c)),(u,c,...a)=>{if(a.length===0)c(s,o=>o+1);else if(e)return e(u,c,...a)})}function lt(t){const e=m(void 0);return delete e.init,Object.defineProperty(e,"init",{get(){return t()}}),e}})}}));
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
System.register(['jotai/vanilla/internals'], (function (exports) {
|
|
2
|
+
'use strict';
|
|
3
|
+
var INTERNAL_buildStoreRev2;
|
|
4
|
+
return {
|
|
5
|
+
setters: [function (module) {
|
|
6
|
+
INTERNAL_buildStoreRev2 = module.INTERNAL_buildStoreRev2;
|
|
7
|
+
}],
|
|
8
|
+
execute: (function () {
|
|
9
|
+
|
|
10
|
+
exports({
|
|
11
|
+
INTERNAL_overrideCreateStore: INTERNAL_overrideCreateStore,
|
|
12
|
+
atom: atom,
|
|
13
|
+
createStore: createStore,
|
|
14
|
+
getDefaultStore: getDefaultStore
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
let keyCount = 0;
|
|
18
|
+
function atom(read, write) {
|
|
19
|
+
const key = `atom${++keyCount}`;
|
|
20
|
+
const config = {
|
|
21
|
+
toString() {
|
|
22
|
+
return this.debugLabel ? key + ":" + this.debugLabel : key;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
if (typeof read === "function") {
|
|
26
|
+
config.read = read;
|
|
27
|
+
} else {
|
|
28
|
+
config.init = read;
|
|
29
|
+
config.read = defaultRead;
|
|
30
|
+
config.write = defaultWrite;
|
|
31
|
+
}
|
|
32
|
+
if (write) {
|
|
33
|
+
config.write = write;
|
|
34
|
+
}
|
|
35
|
+
return config;
|
|
36
|
+
}
|
|
37
|
+
function defaultRead(get) {
|
|
38
|
+
return get(this);
|
|
39
|
+
}
|
|
40
|
+
function defaultWrite(get, set, arg) {
|
|
41
|
+
return set(
|
|
42
|
+
this,
|
|
43
|
+
typeof arg === "function" ? arg(get(this)) : arg
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let overriddenCreateStore;
|
|
48
|
+
function INTERNAL_overrideCreateStore(fn) {
|
|
49
|
+
overriddenCreateStore = fn(overriddenCreateStore);
|
|
50
|
+
}
|
|
51
|
+
function createStore() {
|
|
52
|
+
if (overriddenCreateStore) {
|
|
53
|
+
return overriddenCreateStore();
|
|
54
|
+
}
|
|
55
|
+
return INTERNAL_buildStoreRev2();
|
|
56
|
+
}
|
|
57
|
+
let defaultStore;
|
|
58
|
+
function getDefaultStore() {
|
|
59
|
+
if (!defaultStore) {
|
|
60
|
+
defaultStore = createStore();
|
|
61
|
+
{
|
|
62
|
+
globalThis.__JOTAI_DEFAULT_STORE__ || (globalThis.__JOTAI_DEFAULT_STORE__ = defaultStore);
|
|
63
|
+
if (globalThis.__JOTAI_DEFAULT_STORE__ !== defaultStore) {
|
|
64
|
+
console.warn(
|
|
65
|
+
"Detected multiple Jotai instances. It may cause unexpected behavior with the default store. https://github.com/pmndrs/jotai/discussions/2044"
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return defaultStore;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
})
|
|
74
|
+
};
|
|
75
|
+
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
System.register(["jotai/vanilla/internals"],(function(f){"use strict";var a;return{setters:[function(i){a=i.INTERNAL_buildStoreRev2}],execute:(function(){f({INTERNAL_overrideCreateStore:N,atom:l,createStore:c,getDefaultStore:d});let i=0;function l(t,o){const r=`atom${++i}`,e={toString(){return r}};return typeof t=="function"?e.read=t:(e.init=t,e.read=s,e.write=S),o&&(e.write=o),e}function s(t){return t(this)}function S(t,o,r){return o(this,typeof r=="function"?r(t(this)):r)}let n;function N(t){n=t(n)}function c(){return n?n():a()}let u;function d(){return u||(u=c()),u}})}}));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import babel from '@babel/core';
|
|
2
|
+
import type { PluginObj } from '@babel/core';
|
|
3
|
+
import type { PluginOptions } from './utils';
|
|
4
|
+
/** @deprecated Use `jotai-babel/plugin-debug-label` instead. */
|
|
5
|
+
export default function debugLabelPlugin({ types: t }: typeof babel, options?: PluginOptions): PluginObj;
|
|
6
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import babel from '@babel/core';
|
|
2
|
+
import type { PluginObj } from '@babel/core';
|
|
3
|
+
import type { PluginOptions } from './utils';
|
|
4
|
+
/** @deprecated Use `jotai-babel/plugin-react-refresh` instead. */
|
|
5
|
+
export default function reactRefreshPlugin({ types: t }: typeof babel, options?: PluginOptions): PluginObj;
|
|
6
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import babel from '@babel/core';
|
|
2
|
+
import type { PluginOptions } from './utils';
|
|
3
|
+
/** @deprecated Use `jotai-babel/preset` instead. */
|
|
4
|
+
export default function jotaiPreset(_: typeof babel, options?: PluginOptions): {
|
|
5
|
+
plugins: babel.PluginItem[];
|
|
6
|
+
};
|
|
7
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { types } from '@babel/core';
|
|
2
|
+
export interface PluginOptions {
|
|
3
|
+
customAtomNames?: string[];
|
|
4
|
+
}
|
|
5
|
+
export declare function isAtom(t: typeof types, callee: babel.types.Expression | babel.types.V8IntrinsicIdentifier, customAtomNames?: PluginOptions['customAtomNames']): boolean;
|
|
6
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import babel from '@babel/core';
|
|
2
|
+
import type { PluginObj } from '@babel/core';
|
|
3
|
+
import type { PluginOptions } from './utils';
|
|
4
|
+
/** @deprecated Use `jotai-babel/plugin-debug-label` instead. */
|
|
5
|
+
export default function debugLabelPlugin({ types: t }: typeof babel, options?: PluginOptions): PluginObj;
|
|
6
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import babel from '@babel/core';
|
|
2
|
+
import type { PluginObj } from '@babel/core';
|
|
3
|
+
import type { PluginOptions } from './utils';
|
|
4
|
+
/** @deprecated Use `jotai-babel/plugin-react-refresh` instead. */
|
|
5
|
+
export default function reactRefreshPlugin({ types: t }: typeof babel, options?: PluginOptions): PluginObj;
|
|
6
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import babel from '@babel/core';
|
|
2
|
+
import type { PluginOptions } from './utils';
|
|
3
|
+
/** @deprecated Use `jotai-babel/preset` instead. */
|
|
4
|
+
export default function jotaiPreset(_: typeof babel, options?: PluginOptions): {
|
|
5
|
+
plugins: babel.PluginItem[];
|
|
6
|
+
};
|
|
7
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { types } from '@babel/core';
|
|
2
|
+
export interface PluginOptions {
|
|
3
|
+
customAtomNames?: string[];
|
|
4
|
+
}
|
|
5
|
+
export declare function isAtom(t: typeof types, callee: babel.types.Expression | babel.types.V8IntrinsicIdentifier, customAtomNames?: PluginOptions['customAtomNames']): boolean;
|
|
6
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { FunctionComponent, ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { createStore } from 'jotai/vanilla';
|
|
3
|
+
type Store = ReturnType<typeof createStore>;
|
|
4
|
+
type Options = {
|
|
5
|
+
store?: Store;
|
|
6
|
+
};
|
|
7
|
+
export declare function useStore(options?: Options): Store;
|
|
8
|
+
export declare function Provider({ children, store, }: {
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
store?: Store;
|
|
11
|
+
}): ReactElement<{
|
|
12
|
+
value: Store | undefined;
|
|
13
|
+
}, FunctionComponent<{
|
|
14
|
+
value: Store;
|
|
15
|
+
}>>;
|
|
16
|
+
export {};
|
|
17
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Atom, ExtractAtomArgs, ExtractAtomResult, ExtractAtomValue, PrimitiveAtom, SetStateAction, WritableAtom } from 'jotai/vanilla';
|
|
2
|
+
import { useAtomValue } from './useAtomValue';
|
|
3
|
+
type SetAtom<Args extends unknown[], Result> = (...args: Args) => Result;
|
|
4
|
+
type Options = Parameters<typeof useAtomValue>[1];
|
|
5
|
+
export declare function useAtom<Value, Args extends unknown[], Result>(atom: WritableAtom<Value, Args, Result>, options?: Options): [
|
|
6
|
+
Awaited<Value>,
|
|
7
|
+
SetAtom<Args, Result>
|
|
8
|
+
];
|
|
9
|
+
export declare function useAtom<Value>(atom: PrimitiveAtom<Value>, options?: Options): [
|
|
10
|
+
Awaited<Value>,
|
|
11
|
+
SetAtom<[
|
|
12
|
+
SetStateAction<Value>
|
|
13
|
+
], void>
|
|
14
|
+
];
|
|
15
|
+
export declare function useAtom<Value>(atom: Atom<Value>, options?: Options): [
|
|
16
|
+
Awaited<Value>,
|
|
17
|
+
never
|
|
18
|
+
];
|
|
19
|
+
export declare function useAtom<AtomType extends WritableAtom<unknown, never[], unknown>>(atom: AtomType, options?: Options): [
|
|
20
|
+
Awaited<ExtractAtomValue<AtomType>>,
|
|
21
|
+
SetAtom<ExtractAtomArgs<AtomType>, ExtractAtomResult<AtomType>>
|
|
22
|
+
];
|
|
23
|
+
export declare function useAtom<AtomType extends Atom<unknown>>(atom: AtomType, options?: Options): [
|
|
24
|
+
Awaited<ExtractAtomValue<AtomType>>,
|
|
25
|
+
never
|
|
26
|
+
];
|
|
27
|
+
export {};
|
|
28
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Atom, ExtractAtomValue } from 'jotai/vanilla';
|
|
2
|
+
import { useStore } from './Provider';
|
|
3
|
+
type Options = Parameters<typeof useStore>[0] & {
|
|
4
|
+
delay?: number;
|
|
5
|
+
unstable_promiseStatus?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function useAtomValue<Value>(atom: Atom<Value>, options?: Options): Awaited<Value>;
|
|
8
|
+
export declare function useAtomValue<AtomType extends Atom<unknown>>(atom: AtomType, options?: Options): Awaited<ExtractAtomValue<AtomType>>;
|
|
9
|
+
export {};
|
|
10
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ExtractAtomArgs, ExtractAtomResult, WritableAtom } from 'jotai/vanilla';
|
|
2
|
+
import { useStore } from './Provider';
|
|
3
|
+
type SetAtom<Args extends unknown[], Result> = (...args: Args) => Result;
|
|
4
|
+
type Options = Parameters<typeof useStore>[0];
|
|
5
|
+
export declare function useSetAtom<Value, Args extends unknown[], Result>(atom: WritableAtom<Value, Args, Result>, options?: Options): SetAtom<Args, Result>;
|
|
6
|
+
export declare function useSetAtom<AtomType extends WritableAtom<unknown, never[], unknown>>(atom: AtomType, options?: Options): SetAtom<ExtractAtomArgs<AtomType>, ExtractAtomResult<AtomType>>;
|
|
7
|
+
export {};
|
|
8
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { useSetAtom } from 'jotai/react';
|
|
2
|
+
import type { Getter, Setter } from 'jotai/vanilla';
|
|
3
|
+
type Options = Parameters<typeof useSetAtom>[1];
|
|
4
|
+
export declare function useAtomCallback<Result, Args extends unknown[]>(callback: (get: Getter, set: Setter, ...arg: Args) => Result, options?: Options): (...args: Args) => Result;
|
|
5
|
+
export {};
|
|
6
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useStore } from 'jotai/react';
|
|
2
|
+
import type { WritableAtom } from 'jotai/vanilla';
|
|
3
|
+
type Options = Parameters<typeof useStore>[0] & {
|
|
4
|
+
dangerouslyForceHydrate?: boolean;
|
|
5
|
+
};
|
|
6
|
+
type AnyWritableAtom = WritableAtom<any, any[], any>;
|
|
7
|
+
type InferAtomTuples<T> = {
|
|
8
|
+
[K in keyof T]: T[K] extends readonly [
|
|
9
|
+
infer A,
|
|
10
|
+
...infer Rest
|
|
11
|
+
] ? A extends WritableAtom<unknown, infer Args, unknown> ? Rest extends Args ? readonly [
|
|
12
|
+
A,
|
|
13
|
+
...Rest
|
|
14
|
+
] : never : T[K] : never;
|
|
15
|
+
};
|
|
16
|
+
export type INTERNAL_InferAtomTuples<T> = InferAtomTuples<T>;
|
|
17
|
+
export declare function useHydrateAtoms<T extends (readonly [
|
|
18
|
+
AnyWritableAtom,
|
|
19
|
+
...unknown[]
|
|
20
|
+
])[]>(values: InferAtomTuples<T>, options?: Options): void;
|
|
21
|
+
export declare function useHydrateAtoms<T extends Map<AnyWritableAtom, unknown>>(values: T, options?: Options): void;
|
|
22
|
+
export declare function useHydrateAtoms<T extends Iterable<readonly [
|
|
23
|
+
AnyWritableAtom,
|
|
24
|
+
...unknown[]
|
|
25
|
+
]>>(values: InferAtomTuples<T>, options?: Options): void;
|
|
26
|
+
export {};
|
|
27
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useAtom } from 'jotai/react';
|
|
2
|
+
import type { PrimitiveAtom } from 'jotai/vanilla';
|
|
3
|
+
type Options = Parameters<typeof useAtom>[1];
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated please use a recipe instead
|
|
6
|
+
* https://github.com/pmndrs/jotai/pull/2467
|
|
7
|
+
*/
|
|
8
|
+
export declare function useReducerAtom<Value, Action>(anAtom: PrimitiveAtom<Value>, reducer: (v: Value, a?: Action) => Value, options?: Options): [
|
|
9
|
+
Value,
|
|
10
|
+
(action?: Action) => void
|
|
11
|
+
];
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated please use a recipe instead
|
|
14
|
+
* https://github.com/pmndrs/jotai/pull/2467
|
|
15
|
+
*/
|
|
16
|
+
export declare function useReducerAtom<Value, Action>(anAtom: PrimitiveAtom<Value>, reducer: (v: Value, a: Action) => Value, options?: Options): [
|
|
17
|
+
Value,
|
|
18
|
+
(action: Action) => void
|
|
19
|
+
];
|
|
20
|
+
export {};
|
|
21
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useSetAtom } from 'jotai/react';
|
|
2
|
+
import { RESET } from 'jotai/vanilla/utils';
|
|
3
|
+
import type { WritableAtom } from 'jotai/vanilla';
|
|
4
|
+
type Options = Parameters<typeof useSetAtom>[1];
|
|
5
|
+
export declare function useResetAtom<T>(anAtom: WritableAtom<unknown, [
|
|
6
|
+
typeof RESET
|
|
7
|
+
], T>, options?: Options): () => T;
|
|
8
|
+
export {};
|
|
9
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { useResetAtom } from './utils/useResetAtom';
|
|
2
|
+
export { useReducerAtom } from './utils/useReducerAtom';
|
|
3
|
+
export { useAtomCallback } from './utils/useAtomCallback';
|
|
4
|
+
export { useHydrateAtoms } from './utils/useHydrateAtoms';
|
|
5
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Store } from './store';
|
|
2
|
+
type Getter = <Value>(atom: Atom<Value>) => Value;
|
|
3
|
+
type Setter = <Value, Args extends unknown[], Result>(atom: WritableAtom<Value, Args, Result>, ...args: Args) => Result;
|
|
4
|
+
type SetAtom<Args extends unknown[], Result> = <A extends Args>(...args: A) => Result;
|
|
5
|
+
/**
|
|
6
|
+
* setSelf is for internal use only and subject to change without notice.
|
|
7
|
+
*/
|
|
8
|
+
type Read<Value, SetSelf = never> = (get: Getter, options: {
|
|
9
|
+
readonly signal: AbortSignal;
|
|
10
|
+
readonly setSelf: SetSelf;
|
|
11
|
+
}) => Value;
|
|
12
|
+
type Write<Args extends unknown[], Result> = (get: Getter, set: Setter, ...args: Args) => Result;
|
|
13
|
+
type WithInitialValue<Value> = {
|
|
14
|
+
init: Value;
|
|
15
|
+
};
|
|
16
|
+
type OnUnmount = () => void;
|
|
17
|
+
type OnMount<Args extends unknown[], Result> = <S extends SetAtom<Args, Result>>(setAtom: S) => OnUnmount | void;
|
|
18
|
+
export interface Atom<Value> {
|
|
19
|
+
toString: () => string;
|
|
20
|
+
read: Read<Value>;
|
|
21
|
+
debugLabel?: string;
|
|
22
|
+
/**
|
|
23
|
+
* To ONLY be used by Jotai libraries to mark atoms as private. Subject to change.
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
debugPrivate?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Fires after atom is referenced by the store for the first time
|
|
29
|
+
* This is an internal API and subject to change without notice.
|
|
30
|
+
*/
|
|
31
|
+
INTERNAL_onInit?: (store: Store) => void;
|
|
32
|
+
}
|
|
33
|
+
export interface WritableAtom<Value, Args extends unknown[], Result> extends Atom<Value> {
|
|
34
|
+
read: Read<Value, SetAtom<Args, unknown>>;
|
|
35
|
+
write: Write<Args, Result>;
|
|
36
|
+
onMount?: OnMount<Args, Result>;
|
|
37
|
+
}
|
|
38
|
+
type SetStateAction<Value> = Value | ((prev: Value) => Value);
|
|
39
|
+
export type PrimitiveAtom<Value> = WritableAtom<Value, [
|
|
40
|
+
SetStateAction<Value>
|
|
41
|
+
], void>;
|
|
42
|
+
export declare function atom<Value, Args extends unknown[], Result>(read: Read<Value, SetAtom<Args, unknown>>, write: Write<Args, Result>): WritableAtom<Value, Args, Result>;
|
|
43
|
+
export declare function atom<Value>(read: Read<Value>): Atom<Value>;
|
|
44
|
+
export declare function atom<Value, Args extends unknown[], Result>(initialValue: Value, write: Write<Args, Result>): WritableAtom<Value, Args, Result> & WithInitialValue<Value>;
|
|
45
|
+
export declare function atom<Value>(): PrimitiveAtom<Value | undefined> & WithInitialValue<Value | undefined>;
|
|
46
|
+
export declare function atom<Value>(initialValue: Value): PrimitiveAtom<Value> & WithInitialValue<Value>;
|
|
47
|
+
export {};
|
|
48
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { Atom, WritableAtom } from './atom';
|
|
2
|
+
type AnyValue = unknown;
|
|
3
|
+
type AnyError = unknown;
|
|
4
|
+
type AnyAtom = Atom<AnyValue>;
|
|
5
|
+
type AnyWritableAtom = WritableAtom<AnyValue, unknown[], unknown>;
|
|
6
|
+
type OnUnmount = () => void;
|
|
7
|
+
type EpochNumber = number;
|
|
8
|
+
/**
|
|
9
|
+
* Mutable atom state,
|
|
10
|
+
* tracked for both mounted and unmounted atoms in a store.
|
|
11
|
+
*
|
|
12
|
+
* This should be garbage collectable.
|
|
13
|
+
* We can mutate it during atom read. (except for fields with TODO)
|
|
14
|
+
*/
|
|
15
|
+
type AtomState<Value = AnyValue> = {
|
|
16
|
+
/**
|
|
17
|
+
* Map of atoms that the atom depends on.
|
|
18
|
+
* The map value is the epoch number of the dependency.
|
|
19
|
+
*/
|
|
20
|
+
readonly d: Map<AnyAtom, EpochNumber>;
|
|
21
|
+
/**
|
|
22
|
+
* Set of atoms with pending promise that depend on the atom.
|
|
23
|
+
*
|
|
24
|
+
* This may cause memory leaks, but it's for the capability to continue promises
|
|
25
|
+
* TODO(daishi): revisit how to handle this
|
|
26
|
+
*/
|
|
27
|
+
readonly p: Set<AnyAtom>;
|
|
28
|
+
/** The epoch number of the atom. */
|
|
29
|
+
n: EpochNumber;
|
|
30
|
+
/** Atom value */
|
|
31
|
+
v?: Value;
|
|
32
|
+
/** Atom error */
|
|
33
|
+
e?: AnyError;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* State tracked for mounted atoms. An atom is considered "mounted" if it has a
|
|
37
|
+
* subscriber, or is a transitive dependency of another atom that has a
|
|
38
|
+
* subscriber.
|
|
39
|
+
* The mounted state of an atom is freed once it is no longer mounted.
|
|
40
|
+
*/
|
|
41
|
+
type Mounted = {
|
|
42
|
+
/** Set of listeners to notify when the atom value changes. */
|
|
43
|
+
readonly l: Set<() => void>;
|
|
44
|
+
/** Set of mounted atoms that the atom depends on. */
|
|
45
|
+
readonly d: Set<AnyAtom>;
|
|
46
|
+
/** Set of mounted atoms that depends on the atom. */
|
|
47
|
+
readonly t: Set<AnyAtom>;
|
|
48
|
+
/** Function to run when the atom is unmounted. */
|
|
49
|
+
u?: () => void;
|
|
50
|
+
};
|
|
51
|
+
type WeakMapLike<K extends object, V> = {
|
|
52
|
+
get(key: K): V | undefined;
|
|
53
|
+
set(key: K, value: V): void;
|
|
54
|
+
has(key: K): boolean;
|
|
55
|
+
delete(key: K): boolean;
|
|
56
|
+
};
|
|
57
|
+
type SetLike<T> = {
|
|
58
|
+
readonly size: number;
|
|
59
|
+
add(value: T): void;
|
|
60
|
+
has(value: T): boolean;
|
|
61
|
+
delete(value: T): boolean;
|
|
62
|
+
clear(): void;
|
|
63
|
+
forEach(callback: (value: T) => void): void;
|
|
64
|
+
[Symbol.iterator](): IterableIterator<T>;
|
|
65
|
+
};
|
|
66
|
+
type AtomStateMap = WeakMapLike<AnyAtom, AtomState>;
|
|
67
|
+
type MountedMap = WeakMapLike<AnyAtom, Mounted>;
|
|
68
|
+
type InvalidatedAtoms = WeakMapLike<AnyAtom, EpochNumber>;
|
|
69
|
+
type ChangedAtoms = SetLike<AnyAtom>;
|
|
70
|
+
type Callbacks = SetLike<() => void>;
|
|
71
|
+
type AtomRead = <Value>(store: Store, atom: Atom<Value>, ...params: Parameters<Atom<Value>['read']>) => Value;
|
|
72
|
+
type AtomWrite = <Value, Args extends unknown[], Result>(store: Store, atom: WritableAtom<Value, Args, Result>, ...params: Parameters<WritableAtom<Value, Args, Result>['write']>) => Result;
|
|
73
|
+
type AtomOnInit = <Value>(store: Store, atom: Atom<Value>) => void;
|
|
74
|
+
type AtomOnMount = <Value, Args extends unknown[], Result>(store: Store, atom: WritableAtom<Value, Args, Result>, setAtom: (...args: Args) => Result) => OnUnmount | void;
|
|
75
|
+
type EnsureAtomState = <Value>(store: Store, atom: Atom<Value>) => AtomState<Value>;
|
|
76
|
+
type FlushCallbacks = (store: Store) => void;
|
|
77
|
+
type RecomputeInvalidatedAtoms = (store: Store) => void;
|
|
78
|
+
type ReadAtomState = <Value>(store: Store, atom: Atom<Value>) => AtomState<Value>;
|
|
79
|
+
type InvalidateDependents = (store: Store, atom: AnyAtom) => void;
|
|
80
|
+
type WriteAtomState = <Value, Args extends unknown[], Result>(store: Store, atom: WritableAtom<Value, Args, Result>, ...args: Args) => Result;
|
|
81
|
+
type MountDependencies = (store: Store, atom: AnyAtom) => void;
|
|
82
|
+
type MountAtom = <Value>(store: Store, atom: Atom<Value>) => Mounted;
|
|
83
|
+
type UnmountAtom = <Value>(store: Store, atom: Atom<Value>) => Mounted | undefined;
|
|
84
|
+
type SetAtomStateValueOrPromise = <Value>(store: Store, atom: Atom<Value>, valueOrPromise: Value) => void;
|
|
85
|
+
type StoreGet = <Value>(store: Store, atom: Atom<Value>) => Value;
|
|
86
|
+
type StoreSet = <Value, Args extends unknown[], Result>(store: Store, atom: WritableAtom<Value, Args, Result>, ...args: Args) => Result;
|
|
87
|
+
type StoreSub = (store: Store, atom: AnyAtom, listener: () => void) => () => void;
|
|
88
|
+
type EnhanceBuildingBlocks = (buildingBlocks: Readonly<BuildingBlocks>) => Readonly<BuildingBlocks>;
|
|
89
|
+
type AbortHandlersMap = WeakMapLike<PromiseLike<unknown>, Set<() => void>>;
|
|
90
|
+
type RegisterAbortHandler = <T>(store: Store, promise: PromiseLike<T>, abortHandler: () => void) => void;
|
|
91
|
+
type AbortPromise = <T>(store: Store, promise: PromiseLike<T>) => void;
|
|
92
|
+
type Store = {
|
|
93
|
+
get: <Value>(atom: Atom<Value>) => Value;
|
|
94
|
+
set: <Value, Args extends unknown[], Result>(atom: WritableAtom<Value, Args, Result>, ...args: Args) => Result;
|
|
95
|
+
sub: (atom: AnyAtom, listener: () => void) => () => void;
|
|
96
|
+
};
|
|
97
|
+
type BuildingBlocks = [
|
|
98
|
+
/*atomStateMap*/ AtomStateMap,
|
|
99
|
+
/*mountedMap*/ MountedMap,
|
|
100
|
+
/*invalidatedAtoms*/ InvalidatedAtoms,
|
|
101
|
+
/*changedAtoms*/ ChangedAtoms,
|
|
102
|
+
/*mountCallbacks*/ Callbacks,
|
|
103
|
+
/*unmountCallbacks*/ Callbacks,
|
|
104
|
+
/*storeHooks*/ StoreHooks,
|
|
105
|
+
/*atomRead*/ AtomRead,
|
|
106
|
+
/*atomWrite*/ AtomWrite,
|
|
107
|
+
/*atomOnInit*/ AtomOnInit,
|
|
108
|
+
/*atomOnMount*/ AtomOnMount,
|
|
109
|
+
/*ensureAtomState*/ EnsureAtomState,
|
|
110
|
+
/*flushCallbacks*/ FlushCallbacks,
|
|
111
|
+
/*recomputeInvalidatedAtoms*/ RecomputeInvalidatedAtoms,
|
|
112
|
+
/*readAtomState*/ ReadAtomState,
|
|
113
|
+
/*invalidateDependents*/ InvalidateDependents,
|
|
114
|
+
/*writeAtomState*/ WriteAtomState,
|
|
115
|
+
/*mountDependencies*/ MountDependencies,
|
|
116
|
+
/*mountAtom*/ MountAtom,
|
|
117
|
+
/*unmountAtom*/ UnmountAtom,
|
|
118
|
+
/*setAtomStateValueOrPromise*/ SetAtomStateValueOrPromise,
|
|
119
|
+
/*storeGet*/ StoreGet,
|
|
120
|
+
/*storeSet*/ StoreSet,
|
|
121
|
+
/*storeSub*/ StoreSub,
|
|
122
|
+
/*enhanceBuildingBlocks*/ EnhanceBuildingBlocks | undefined,
|
|
123
|
+
/*abortHandlersMap*/ AbortHandlersMap,
|
|
124
|
+
/*registerAbortHandler*/ RegisterAbortHandler,
|
|
125
|
+
/*abortPromise*/ AbortPromise
|
|
126
|
+
];
|
|
127
|
+
export type { AtomState as INTERNAL_AtomState, Mounted as INTERNAL_Mounted, AtomStateMap as INTERNAL_AtomStateMap, MountedMap as INTERNAL_MountedMap, InvalidatedAtoms as INTERNAL_InvalidatedAtoms, ChangedAtoms as INTERNAL_ChangedAtoms, Callbacks as INTERNAL_Callbacks, AtomRead as INTERNAL_AtomRead, AtomWrite as INTERNAL_AtomWrite, AtomOnInit as INTERNAL_AtomOnInit, AtomOnMount as INTERNAL_AtomOnMount, EnsureAtomState as INTERNAL_EnsureAtomState, FlushCallbacks as INTERNAL_FlushCallbacks, RecomputeInvalidatedAtoms as INTERNAL_RecomputeInvalidatedAtoms, ReadAtomState as INTERNAL_ReadAtomState, InvalidateDependents as INTERNAL_InvalidateDependents, WriteAtomState as INTERNAL_WriteAtomState, MountDependencies as INTERNAL_MountDependencies, MountAtom as INTERNAL_MountAtom, UnmountAtom as INTERNAL_UnmountAtom, Store as INTERNAL_Store, BuildingBlocks as INTERNAL_BuildingBlocks, StoreHooks as INTERNAL_StoreHooks, };
|
|
128
|
+
declare function hasInitialValue<T extends Atom<AnyValue>>(atom: T): atom is T & (T extends Atom<infer Value> ? {
|
|
129
|
+
init: Value;
|
|
130
|
+
} : never);
|
|
131
|
+
declare function isActuallyWritableAtom(atom: AnyAtom): atom is AnyWritableAtom;
|
|
132
|
+
declare function isAtomStateInitialized<Value>(atomState: AtomState<Value>): boolean;
|
|
133
|
+
declare function returnAtomValue<Value>(atomState: AtomState<Value>): Value;
|
|
134
|
+
declare function isPromiseLike(p: unknown): p is PromiseLike<unknown>;
|
|
135
|
+
declare function addPendingPromiseToDependency(atom: AnyAtom, promise: PromiseLike<AnyValue>, dependencyAtomState: AtomState): void;
|
|
136
|
+
declare function getMountedOrPendingDependents(atom: AnyAtom, atomState: AtomState, mountedMap: MountedMap): Iterable<AnyAtom>;
|
|
137
|
+
type StoreHook = {
|
|
138
|
+
(): void;
|
|
139
|
+
add(callback: () => void): () => void;
|
|
140
|
+
};
|
|
141
|
+
type StoreHookForAtoms = {
|
|
142
|
+
(atom: AnyAtom): void;
|
|
143
|
+
add(atom: AnyAtom, callback: () => void): () => void;
|
|
144
|
+
add(atom: undefined, callback: (atom: AnyAtom) => void): () => void;
|
|
145
|
+
};
|
|
146
|
+
/** StoreHooks are an experimental API. */
|
|
147
|
+
type StoreHooks = {
|
|
148
|
+
/** Listener to notify when the atom state is created. */
|
|
149
|
+
readonly i?: StoreHookForAtoms;
|
|
150
|
+
/** Listener to notify when the atom is read. */
|
|
151
|
+
readonly r?: StoreHookForAtoms;
|
|
152
|
+
/** Listener to notify when the atom value is changed. */
|
|
153
|
+
readonly c?: StoreHookForAtoms;
|
|
154
|
+
/** Listener to notify when the atom is mounted. */
|
|
155
|
+
readonly m?: StoreHookForAtoms;
|
|
156
|
+
/** Listener to notify when the atom is unmounted. */
|
|
157
|
+
readonly u?: StoreHookForAtoms;
|
|
158
|
+
/** Listener to notify when callbacks are being flushed. */
|
|
159
|
+
readonly f?: StoreHook;
|
|
160
|
+
};
|
|
161
|
+
declare function initializeStoreHooks(storeHooks: StoreHooks): Required<StoreHooks>;
|
|
162
|
+
declare function getBuildingBlocks(store: Store): Readonly<BuildingBlocks>;
|
|
163
|
+
declare function buildStore(...buildArgs: Partial<BuildingBlocks>): Store;
|
|
164
|
+
export { buildStore as INTERNAL_buildStoreRev2, getBuildingBlocks as INTERNAL_getBuildingBlocksRev2, initializeStoreHooks as INTERNAL_initializeStoreHooksRev2, hasInitialValue as INTERNAL_hasInitialValue, isActuallyWritableAtom as INTERNAL_isActuallyWritableAtom, isAtomStateInitialized as INTERNAL_isAtomStateInitialized, returnAtomValue as INTERNAL_returnAtomValue, isPromiseLike as INTERNAL_isPromiseLike, addPendingPromiseToDependency as INTERNAL_addPendingPromiseToDependency, getMountedOrPendingDependents as INTERNAL_getMountedOrPendingDependents, };
|
|
165
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { INTERNAL_Store } from 'jotai/vanilla/internals';
|
|
2
|
+
export type Store = INTERNAL_Store;
|
|
3
|
+
export declare function INTERNAL_overrideCreateStore(fn: (prev: typeof createStore | undefined) => typeof createStore): void;
|
|
4
|
+
export declare function createStore(): Store;
|
|
5
|
+
export declare function getDefaultStore(): Store;
|
|
6
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Atom, PrimitiveAtom, WritableAtom } from './atom';
|
|
2
|
+
export type Getter = Parameters<Atom<unknown>['read']>[0];
|
|
3
|
+
export type Setter = Parameters<WritableAtom<unknown, unknown[], unknown>['write']>[1];
|
|
4
|
+
export type ExtractAtomValue<AtomType> = AtomType extends Atom<infer Value> ? Value : never;
|
|
5
|
+
export type ExtractAtomArgs<AtomType> = AtomType extends WritableAtom<unknown, infer Args, infer _Result> ? Args : never;
|
|
6
|
+
export type ExtractAtomResult<AtomType> = AtomType extends WritableAtom<unknown, infer _Args, infer Result> ? Result : never;
|
|
7
|
+
export type SetStateAction<Value> = ExtractAtomArgs<PrimitiveAtom<Value>>[0];
|
|
8
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Atom } from 'jotai/vanilla';
|
|
2
|
+
/**
|
|
3
|
+
* in milliseconds
|
|
4
|
+
*/
|
|
5
|
+
type CreatedAt = number;
|
|
6
|
+
type ShouldRemove<Param> = (createdAt: CreatedAt, param: Param) => boolean;
|
|
7
|
+
type Cleanup = () => void;
|
|
8
|
+
type Callback<Param, AtomType> = (event: {
|
|
9
|
+
type: 'CREATE' | 'REMOVE';
|
|
10
|
+
param: Param;
|
|
11
|
+
atom: AtomType;
|
|
12
|
+
}) => void;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated atomFamily is deprecated and will be removed in v3.
|
|
15
|
+
* Please use the `jotai-family` package instead: https://github.com/jotaijs/jotai-family
|
|
16
|
+
*
|
|
17
|
+
* Install: `npm install jotai-family`
|
|
18
|
+
*
|
|
19
|
+
* Migration:
|
|
20
|
+
* ```ts
|
|
21
|
+
* // Before
|
|
22
|
+
* import { atomFamily } from 'jotai/utils'
|
|
23
|
+
*
|
|
24
|
+
* // After
|
|
25
|
+
* import { atomFamily } from 'jotai-family'
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export interface AtomFamily<Param, AtomType> {
|
|
29
|
+
(param: Param): AtomType;
|
|
30
|
+
getParams(): Iterable<Param>;
|
|
31
|
+
remove(param: Param): void;
|
|
32
|
+
setShouldRemove(shouldRemove: ShouldRemove<Param> | null): void;
|
|
33
|
+
/**
|
|
34
|
+
* fires when an atom is created or removed
|
|
35
|
+
* This API is for advanced use cases, and can change without notice.
|
|
36
|
+
*/
|
|
37
|
+
unstable_listen(callback: Callback<Param, AtomType>): Cleanup;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated atomFamily is deprecated and will be removed in v3.
|
|
41
|
+
* Please use the `jotai-family` package instead: https://github.com/jotaijs/jotai-family
|
|
42
|
+
*
|
|
43
|
+
* Install: `npm install jotai-family`
|
|
44
|
+
*
|
|
45
|
+
* Migration:
|
|
46
|
+
* ```ts
|
|
47
|
+
* // Before
|
|
48
|
+
* import { atomFamily } from 'jotai/utils'
|
|
49
|
+
*
|
|
50
|
+
* // After
|
|
51
|
+
* import { atomFamily } from 'jotai-family'
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function atomFamily<Param, AtomType extends Atom<unknown>>(initializeAtom: (param: Param) => AtomType, areEqual?: (a: Param, b: Param) => boolean): AtomFamily<Param, AtomType>;
|
|
55
|
+
export {};
|
|
56
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|