Comparing version 2.5.0 to 2.5.1
{ | ||
"name": "jotai", | ||
"private": false, | ||
"version": "2.5.0", | ||
"version": "2.5.1", | ||
"description": "👻 Primitive and flexible state management for React", | ||
@@ -37,3 +37,2 @@ "main": "./index.js", | ||
".": { | ||
"types": "./index.d.ts", | ||
"import": { | ||
@@ -43,6 +42,8 @@ "types": "./esm/index.d.mts", | ||
}, | ||
"default": "./index.js" | ||
"default": { | ||
"types": "./index.d.ts", | ||
"default": "./index.js" | ||
} | ||
}, | ||
"./*": { | ||
"types": "./*.d.ts", | ||
"import": { | ||
@@ -52,3 +53,6 @@ "types": "./esm/*.d.mts", | ||
}, | ||
"default": "./*.js" | ||
"default": { | ||
"types": "./*.d.ts", | ||
"default": "./*.js" | ||
} | ||
} | ||
@@ -55,0 +59,0 @@ }, |
@@ -7,10 +7,9 @@ import { useStore } from 'jotai/react'; | ||
type AnyWritableAtom = WritableAtom<unknown, any[], any>; | ||
type AtomMap<A = AnyWritableAtom, V = unknown> = Map<A, V>; | ||
type AtomTuple<A = AnyWritableAtom, V = unknown> = readonly [A, V]; | ||
type InferAtoms<T extends Iterable<AtomTuple>> = { | ||
[K in keyof T]: T[K] extends AtomTuple<infer A> ? A extends AnyWritableAtom ? AtomTuple<A, ReturnType<A['read']>> : T[K] : never; | ||
type InferAtomTuples<T> = { | ||
[K in keyof T]: T[K] extends readonly [infer A, unknown] ? A extends WritableAtom<unknown, infer Args, any> ? readonly [A, Args[0]] : T[K] : never; | ||
}; | ||
export declare function useHydrateAtoms<T extends Array<AtomTuple>>(values: InferAtoms<T>, options?: Options): void; | ||
export declare function useHydrateAtoms<T extends AtomMap>(values: T, options?: Options): void; | ||
export declare function useHydrateAtoms<T extends Iterable<AtomTuple>>(values: InferAtoms<T>, options?: Options): void; | ||
export type INTERNAL_InferAtomTuples<T> = InferAtomTuples<T>; | ||
export declare function useHydrateAtoms<T extends (readonly [AnyWritableAtom, unknown])[]>(values: InferAtomTuples<T>, options?: Options): void; | ||
export declare function useHydrateAtoms<T extends Map<AnyWritableAtom, unknown>>(values: T, options?: Options): void; | ||
export declare function useHydrateAtoms<T extends Iterable<readonly [AnyWritableAtom, unknown]>>(values: InferAtomTuples<T>, options?: Options): void; | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
System.register(["react","jotai/react","jotai/vanilla/utils","jotai/vanilla"],function(k){"use strict";var r,i,c,l,m,f,A;return{setters:[function(e){r=e.useCallback,i=e.useMemo},function(e){c=e.useSetAtom,l=e.useAtom,m=e.useStore},function(e){f=e.RESET},function(e){A=e.atom}],execute:function(){k({useAtomCallback:d,useHydrateAtoms:y,useReducerAtom:R,useResetAtom:e});function e(n,t){const o=c(n,t);return r(()=>o(f),[o])}function R(n,t,o){const[u,s]=l(n,o),a=r(C=>{s(E=>t(E,C))},[s,t]);return[u,a]}function d(n,t){const o=i(()=>A(null,(u,s,...a)=>n(u,s,...a)),[n]);return c(o,t)}const S=new WeakMap;function y(n,t){const o=m(t),u=b(o);for(const[s,a]of n)(!u.has(s)||t!=null&&t.dangerouslyForceHydrate)&&(u.add(s),o.set(s,a))}const b=n=>{let t=S.get(n);return t||(t=new WeakSet,S.set(n,t)),t}}}}); | ||
System.register(["react","jotai/react","jotai/vanilla/utils","jotai/vanilla"],function(d){"use strict";var r,i,c,l,m,f,A;return{setters:[function(e){r=e.useCallback,i=e.useMemo},function(e){c=e.useSetAtom,l=e.useAtom,m=e.useStore},function(e){f=e.RESET},function(e){A=e.atom}],execute:function(){d({useAtomCallback:R,useHydrateAtoms:y,useReducerAtom:k,useResetAtom:e});function e(n,t){const o=c(n,t);return r(()=>o(f),[o])}function k(n,t,o){const[u,s]=l(n,o),a=r(C=>{s(E=>t(E,C))},[s,t]);return[u,a]}function R(n,t){const o=i(()=>A(null,(u,s,...a)=>n(u,s,...a)),[n]);return c(o,t)}const S=new WeakMap;function y(n,t){const o=m(t),u=b(o);for(const[s,a]of n)(!u.has(s)||t!=null&&t.dangerouslyForceHydrate)&&(u.add(s),o.set(s,a))}const b=n=>{let t=S.get(n);return t||(t=new WeakSet,S.set(n,t)),t}}}}); |
@@ -630,3 +630,3 @@ System.register(['jotai/vanilla'], (function (exports) { | ||
if (prev && "v" in prev) { | ||
return { p: promise, f: fallback(prev.v) }; | ||
return { p: promise, f: fallback(prev.v), v: prev.v }; | ||
} | ||
@@ -646,6 +646,6 @@ return { p: promise, f: fallback() }; | ||
const state = get(promiseAndValueAtom); | ||
if ("v" in state) { | ||
return state.v; | ||
if ("f" in state) { | ||
return state.f; | ||
} | ||
return state.f; | ||
return state.v; | ||
}, | ||
@@ -652,0 +652,0 @@ (_get, set, ...args) => set(anAtom, ...args) |
@@ -1,1 +0,1 @@ | ||
System.register(["jotai/vanilla"],function(P){"use strict";var f;return{setters:[function(W){f=W.atom}],execute:function(){P({atomFamily:J,atomWithDefault:X,atomWithObservable:et,atomWithReducer:z,atomWithReset:T,atomWithStorage:tt,createJSONStorage:R,freezeAtom:K,freezeAtomCreator:q,loadable:ot,selectAtom:C,splitAtom:U,unwrap:at});const W=P("RESET",Symbol());function T(e){const n=f(e,(o,c,i)=>{const r=typeof i=="function"?i(o(n)):i;c(n,r===W?e:r)});return n}function z(e,n){const o=f(e,(c,i,r)=>i(o,n(c(o),r)));return o}function J(e,n){let o=null;const c=new Map,i=r=>{let t;if(n===void 0)t=c.get(r);else for(const[u,s]of c)if(n(u,r)){t=s;break}if(t!==void 0)if(o!=null&&o(t[1],r))i.remove(r);else return t[0];const a=e(r);return c.set(r,[a,Date.now()]),a};return i.remove=r=>{if(n===void 0)c.delete(r);else for(const[t]of c)if(n(t,r)){c.delete(t);break}},i.setShouldRemove=r=>{if(o=r,!!o)for(const[t,a]of c)o(a[1],t)&&c.delete(t)},i}const L=(e,n,o)=>(n.has(o)?n:n.set(o,e())).get(o),$=new WeakMap,_=(e,n,o,c)=>{const i=L(()=>new WeakMap,$,n),r=L(()=>new WeakMap,i,o);return L(e,r,c)};function C(e,n,o=Object.is){return _(()=>{const c=Symbol(),i=([t,a])=>{if(a===c)return n(t);const u=n(t,a);return o(a,u)?a:u},r=f(t=>{const a=t(r),u=t(e);return u instanceof Promise||a instanceof Promise?Promise.all([u,a]).then(i):i([u,a])});return r.init=c,r},e,n,o)}const I=new WeakMap,F=(e,n)=>(I.has(n)?I:I.set(n,e())).get(n),x=e=>{if(typeof e!="object"||e===null)return;Object.freeze(e);const n=Object.getOwnPropertyNames(e);for(const o of n){const c=e[o];x(c)}return e};function K(e){return F(()=>f(n=>x(n(e)),(n,o,c)=>o(e,c)),e)}function q(e){return(...n)=>{const o=e(...n),c=o.read;return o.read=function(i,r){return x(c.call(this,i,r))},o}}const A=(e,n,o)=>(n.has(o)?n:n.set(o,e())).get(o),B=new WeakMap,G=(e,n,o)=>{const c=A(()=>new WeakMap,B,n);return A(e,c,o)},H={},j=e=>!!e.write,Q=e=>typeof e=="function";function U(e,n){return G(()=>{const o=new WeakMap,c=(t,a)=>{let u=o.get(t);if(u)return u;const s=a&&o.get(a),l=[],m=[];return t.forEach((w,v)=>{const b=n?n(w):v;m[v]=b;const y=s&&s.atomList[s.keyList.indexOf(b)];if(y){l[v]=y;return}const O=p=>{const d=p(i),g=p(e),k=c(g,d==null?void 0:d.arr).keyList.indexOf(b);if(k<0||k>=g.length){const h=t[c(t).keyList.indexOf(b)];if(h)return h;throw new Error("splitAtom: index out of bounds for read")}return g[k]},M=(p,d,g)=>{const k=p(i),h=p(e),S=c(h,k==null?void 0:k.arr).keyList.indexOf(b);if(S<0||S>=h.length)throw new Error("splitAtom: index out of bounds for write");const N=Q(g)?g(h[S]):g;Object.is(h[S],N)||d(e,[...h.slice(0,S),N,...h.slice(S+1)])};l[v]=j(e)?f(O,M):f(O)}),s&&s.keyList.length===m.length&&s.keyList.every((w,v)=>w===m[v])?u=s:u={arr:t,atomList:l,keyList:m},o.set(t,u),u},i=f(t=>{const a=t(i),u=t(e);return c(u,a==null?void 0:a.arr)});i.init=void 0;const r=j(e)?f(t=>t(i).atomList,(t,a,u)=>{switch(u.type){case"remove":{const s=t(r).indexOf(u.atom);if(s>=0){const l=t(e);a(e,[...l.slice(0,s),...l.slice(s+1)])}break}case"insert":{const s=u.before?t(r).indexOf(u.before):t(r).length;if(s>=0){const l=t(e);a(e,[...l.slice(0,s),u.value,...l.slice(s)])}break}case"move":{const s=t(r).indexOf(u.atom),l=u.before?t(r).indexOf(u.before):t(r).length;if(s>=0&&l>=0){const m=t(e);s<l?a(e,[...m.slice(0,s),...m.slice(s+1,l),m[s],...m.slice(l)]):a(e,[...m.slice(0,l),m[s],...m.slice(l,s),...m.slice(s+1)])}break}}}):f(t=>t(i).atomList);return r},e,n||H)}function X(e){const n=Symbol(),o=f(n),c=f((i,r)=>{const t=i(o);return t!==n?t:e(i,r)},(i,r,t)=>{if(t===W)r(o,n);else if(typeof t=="function"){const a=i(c);r(o,t(a))}else r(o,t)});return c}const Y=e=>typeof(e==null?void 0:e.then)=="function";function R(e){let n,o;const c={getItem:(i,r)=>{var t,a;const u=l=>{if(l=l||"",n!==l){try{o=JSON.parse(l)}catch{return r}n=l}return o},s=(a=(t=e())==null?void 0:t.getItem(i))!=null?a:null;return Y(s)?s.then(u):u(s)},setItem:(i,r)=>{var t;return(t=e())==null?void 0:t.setItem(i,JSON.stringify(r))},removeItem:i=>{var r;return(r=e())==null?void 0:r.removeItem(i)}};return typeof window<"u"&&typeof window.addEventListener=="function"&&window.Storage&&(c.subscribe=(i,r,t)=>{if(!(e()instanceof window.Storage))return()=>{};const a=u=>{if(u.storageArea===e()&&u.key===i){let s;try{s=JSON.parse(u.newValue||"")}catch{s=t}r(s)}};return window.addEventListener("storage",a),()=>{window.removeEventListener("storage",a)}}),c}const Z=R(()=>typeof window<"u"?window.localStorage:void 0);function tt(e,n,o=Z,c){const i=c==null?void 0:c.unstable_getOnInit,r=f(i?o.getItem(e,n):n);return r.onMount=t=>{i||t(o.getItem(e,n));let a;return o.subscribe&&(a=o.subscribe(e,t,n)),a},f(t=>t(r),(t,a,u)=>{const s=typeof u=="function"?u(t(r)):u;return s===W?(a(r,n),o.removeItem(e)):s instanceof Promise?s.then(l=>(a(r,l),o.setItem(e,l))):(a(r,s),o.setItem(e,s))})}function et(e,n){const o=i=>{if("e"in i)throw i.e;return i.d},c=f(i=>{var r;let t=e(i);const a=(r=t[Symbol.observable])==null?void 0:r.call(t);a&&(t=a);let u;const s=()=>new Promise(d=>{u=d}),l=n&&"initialValue"in n?{d:typeof n.initialValue=="function"?n.initialValue():n.initialValue}:s();let m,w;const v=d=>{w=d,u==null||u(d),m==null||m(d)};let b,y;const O=()=>!m,M=()=>{b&&(clearTimeout(y),b.unsubscribe()),b=t.subscribe({next:d=>v({d}),error:d=>v({e:d}),complete:()=>{}}),O()&&n!=null&&n.unstable_timeout&&(y=setTimeout(()=>{b&&(b.unsubscribe(),b=void 0)},n.unstable_timeout))};M();const p=f(w||l);return p.onMount=d=>(m=d,w&&d(w),b?clearTimeout(y):M(),()=>{m=void 0,b&&(b.unsubscribe(),b=void 0)}),[p,t,s,M,O]});return f(i=>{const[r]=i(c),t=i(r);return t instanceof Promise?t.then(o):o(t)},(i,r,t)=>{const[a,u,s,l,m]=i(c);if("next"in u)m()&&(r(a,s()),l()),u.next(t);else throw new Error("observable is not subject")})}const E=new WeakMap,nt=(e,n)=>(E.has(n)?E:E.set(n,e())).get(n),V={state:"loading"};function ot(e){return nt(()=>{const n=new WeakMap,o=f(0),c=f((i,{setSelf:r})=>{i(o);let t;try{t=i(e)}catch(s){return{state:"hasError",error:s}}if(!(t instanceof Promise))return{state:"hasData",data:t};const a=t;return n.get(a)||(n.set(a,V),a.then(s=>{n.set(a,{state:"hasData",data:s})},s=>{n.set(a,{state:"hasError",error:s})}).finally(r),V)},(i,r)=>{r(o,t=>t+1)});return f(i=>i(c))},e)}const D=(e,n,o)=>(n.has(o)?n:n.set(o,e())).get(o),rt=new WeakMap,st=(e,n,o)=>{const c=D(()=>new WeakMap,rt,n);return D(e,c,o)},it=()=>{};function at(e,n=it){return st(()=>{const o=new WeakMap,c=new WeakMap,i=f(0),r=f((t,{setSelf:a})=>{t(i);const u=t(r),s=t(e);if(!(s instanceof Promise))return{v:s};if(s===(u==null?void 0:u.p)){if(o.has(s))throw o.get(s);if(c.has(s))return{p:s,v:c.get(s)}}return s!==(u==null?void 0:u.p)&&s.then(l=>c.set(s,l),l=>o.set(s,l)).finally(a),u&&"v"in u?{p:s,f:n(u.v)}:{p:s,f:n()}},(t,a)=>{a(i,u=>u+1)});return r.init=void 0,f(t=>{const a=t(r);return"v"in a?a.v:a.f},(t,a,...u)=>a(e,...u))},e,n)}}}}); | ||
System.register(["jotai/vanilla"],function(P){"use strict";var f;return{setters:[function(W){f=W.atom}],execute:function(){P({atomFamily:J,atomWithDefault:X,atomWithObservable:et,atomWithReducer:z,atomWithReset:T,atomWithStorage:tt,createJSONStorage:R,freezeAtom:K,freezeAtomCreator:q,loadable:ot,selectAtom:C,splitAtom:U,unwrap:at});const W=P("RESET",Symbol());function T(e){const n=f(e,(o,c,i)=>{const r=typeof i=="function"?i(o(n)):i;c(n,r===W?e:r)});return n}function z(e,n){const o=f(e,(c,i,r)=>i(o,n(c(o),r)));return o}function J(e,n){let o=null;const c=new Map,i=r=>{let t;if(n===void 0)t=c.get(r);else for(const[u,s]of c)if(n(u,r)){t=s;break}if(t!==void 0)if(o!=null&&o(t[1],r))i.remove(r);else return t[0];const a=e(r);return c.set(r,[a,Date.now()]),a};return i.remove=r=>{if(n===void 0)c.delete(r);else for(const[t]of c)if(n(t,r)){c.delete(t);break}},i.setShouldRemove=r=>{if(o=r,!!o)for(const[t,a]of c)o(a[1],t)&&c.delete(t)},i}const L=(e,n,o)=>(n.has(o)?n:n.set(o,e())).get(o),$=new WeakMap,_=(e,n,o,c)=>{const i=L(()=>new WeakMap,$,n),r=L(()=>new WeakMap,i,o);return L(e,r,c)};function C(e,n,o=Object.is){return _(()=>{const c=Symbol(),i=([t,a])=>{if(a===c)return n(t);const u=n(t,a);return o(a,u)?a:u},r=f(t=>{const a=t(r),u=t(e);return u instanceof Promise||a instanceof Promise?Promise.all([u,a]).then(i):i([u,a])});return r.init=c,r},e,n,o)}const I=new WeakMap,F=(e,n)=>(I.has(n)?I:I.set(n,e())).get(n),x=e=>{if(typeof e!="object"||e===null)return;Object.freeze(e);const n=Object.getOwnPropertyNames(e);for(const o of n){const c=e[o];x(c)}return e};function K(e){return F(()=>f(n=>x(n(e)),(n,o,c)=>o(e,c)),e)}function q(e){return(...n)=>{const o=e(...n),c=o.read;return o.read=function(i,r){return x(c.call(this,i,r))},o}}const A=(e,n,o)=>(n.has(o)?n:n.set(o,e())).get(o),B=new WeakMap,G=(e,n,o)=>{const c=A(()=>new WeakMap,B,n);return A(e,c,o)},H={},j=e=>!!e.write,Q=e=>typeof e=="function";function U(e,n){return G(()=>{const o=new WeakMap,c=(t,a)=>{let u=o.get(t);if(u)return u;const s=a&&o.get(a),l=[],m=[];return t.forEach((w,b)=>{const v=n?n(w):b;m[b]=v;const y=s&&s.atomList[s.keyList.indexOf(v)];if(y){l[b]=y;return}const O=p=>{const d=p(i),g=p(e),k=c(g,d==null?void 0:d.arr).keyList.indexOf(v);if(k<0||k>=g.length){const h=t[c(t).keyList.indexOf(v)];if(h)return h;throw new Error("splitAtom: index out of bounds for read")}return g[k]},M=(p,d,g)=>{const k=p(i),h=p(e),S=c(h,k==null?void 0:k.arr).keyList.indexOf(v);if(S<0||S>=h.length)throw new Error("splitAtom: index out of bounds for write");const N=Q(g)?g(h[S]):g;Object.is(h[S],N)||d(e,[...h.slice(0,S),N,...h.slice(S+1)])};l[b]=j(e)?f(O,M):f(O)}),s&&s.keyList.length===m.length&&s.keyList.every((w,b)=>w===m[b])?u=s:u={arr:t,atomList:l,keyList:m},o.set(t,u),u},i=f(t=>{const a=t(i),u=t(e);return c(u,a==null?void 0:a.arr)});i.init=void 0;const r=j(e)?f(t=>t(i).atomList,(t,a,u)=>{switch(u.type){case"remove":{const s=t(r).indexOf(u.atom);if(s>=0){const l=t(e);a(e,[...l.slice(0,s),...l.slice(s+1)])}break}case"insert":{const s=u.before?t(r).indexOf(u.before):t(r).length;if(s>=0){const l=t(e);a(e,[...l.slice(0,s),u.value,...l.slice(s)])}break}case"move":{const s=t(r).indexOf(u.atom),l=u.before?t(r).indexOf(u.before):t(r).length;if(s>=0&&l>=0){const m=t(e);s<l?a(e,[...m.slice(0,s),...m.slice(s+1,l),m[s],...m.slice(l)]):a(e,[...m.slice(0,l),m[s],...m.slice(l,s),...m.slice(s+1)])}break}}}):f(t=>t(i).atomList);return r},e,n||H)}function X(e){const n=Symbol(),o=f(n),c=f((i,r)=>{const t=i(o);return t!==n?t:e(i,r)},(i,r,t)=>{if(t===W)r(o,n);else if(typeof t=="function"){const a=i(c);r(o,t(a))}else r(o,t)});return c}const Y=e=>typeof(e==null?void 0:e.then)=="function";function R(e){let n,o;const c={getItem:(i,r)=>{var t,a;const u=l=>{if(l=l||"",n!==l){try{o=JSON.parse(l)}catch{return r}n=l}return o},s=(a=(t=e())==null?void 0:t.getItem(i))!=null?a:null;return Y(s)?s.then(u):u(s)},setItem:(i,r)=>{var t;return(t=e())==null?void 0:t.setItem(i,JSON.stringify(r))},removeItem:i=>{var r;return(r=e())==null?void 0:r.removeItem(i)}};return typeof window<"u"&&typeof window.addEventListener=="function"&&window.Storage&&(c.subscribe=(i,r,t)=>{if(!(e()instanceof window.Storage))return()=>{};const a=u=>{if(u.storageArea===e()&&u.key===i){let s;try{s=JSON.parse(u.newValue||"")}catch{s=t}r(s)}};return window.addEventListener("storage",a),()=>{window.removeEventListener("storage",a)}}),c}const Z=R(()=>typeof window<"u"?window.localStorage:void 0);function tt(e,n,o=Z,c){const i=c==null?void 0:c.unstable_getOnInit,r=f(i?o.getItem(e,n):n);return r.onMount=t=>{i||t(o.getItem(e,n));let a;return o.subscribe&&(a=o.subscribe(e,t,n)),a},f(t=>t(r),(t,a,u)=>{const s=typeof u=="function"?u(t(r)):u;return s===W?(a(r,n),o.removeItem(e)):s instanceof Promise?s.then(l=>(a(r,l),o.setItem(e,l))):(a(r,s),o.setItem(e,s))})}function et(e,n){const o=i=>{if("e"in i)throw i.e;return i.d},c=f(i=>{var r;let t=e(i);const a=(r=t[Symbol.observable])==null?void 0:r.call(t);a&&(t=a);let u;const s=()=>new Promise(d=>{u=d}),l=n&&"initialValue"in n?{d:typeof n.initialValue=="function"?n.initialValue():n.initialValue}:s();let m,w;const b=d=>{w=d,u==null||u(d),m==null||m(d)};let v,y;const O=()=>!m,M=()=>{v&&(clearTimeout(y),v.unsubscribe()),v=t.subscribe({next:d=>b({d}),error:d=>b({e:d}),complete:()=>{}}),O()&&n!=null&&n.unstable_timeout&&(y=setTimeout(()=>{v&&(v.unsubscribe(),v=void 0)},n.unstable_timeout))};M();const p=f(w||l);return p.onMount=d=>(m=d,w&&d(w),v?clearTimeout(y):M(),()=>{m=void 0,v&&(v.unsubscribe(),v=void 0)}),[p,t,s,M,O]});return f(i=>{const[r]=i(c),t=i(r);return t instanceof Promise?t.then(o):o(t)},(i,r,t)=>{const[a,u,s,l,m]=i(c);if("next"in u)m()&&(r(a,s()),l()),u.next(t);else throw new Error("observable is not subject")})}const E=new WeakMap,nt=(e,n)=>(E.has(n)?E:E.set(n,e())).get(n),V={state:"loading"};function ot(e){return nt(()=>{const n=new WeakMap,o=f(0),c=f((i,{setSelf:r})=>{i(o);let t;try{t=i(e)}catch(s){return{state:"hasError",error:s}}if(!(t instanceof Promise))return{state:"hasData",data:t};const a=t;return n.get(a)||(n.set(a,V),a.then(s=>{n.set(a,{state:"hasData",data:s})},s=>{n.set(a,{state:"hasError",error:s})}).finally(r),V)},(i,r)=>{r(o,t=>t+1)});return f(i=>i(c))},e)}const D=(e,n,o)=>(n.has(o)?n:n.set(o,e())).get(o),rt=new WeakMap,st=(e,n,o)=>{const c=D(()=>new WeakMap,rt,n);return D(e,c,o)},it=()=>{};function at(e,n=it){return st(()=>{const o=new WeakMap,c=new WeakMap,i=f(0),r=f((t,{setSelf:a})=>{t(i);const u=t(r),s=t(e);if(!(s instanceof Promise))return{v:s};if(s===(u==null?void 0:u.p)){if(o.has(s))throw o.get(s);if(c.has(s))return{p:s,v:c.get(s)}}return s!==(u==null?void 0:u.p)&&s.then(l=>c.set(s,l),l=>o.set(s,l)).finally(a),u&&"v"in u?{p:s,f:n(u.v),v:u.v}:{p:s,f:n()}},(t,a)=>{a(i,u=>u+1)});return r.init=void 0,f(t=>{const a=t(r);return"f"in a?a.f:a.v},(t,a,...u)=>a(e,...u))},e,n)}}}}); |
@@ -7,14 +7,22 @@ import { useStore } from 'jotai/react'; | ||
type AnyWritableAtom = WritableAtom<unknown, any[], any>; | ||
type AtomMap<A = AnyWritableAtom, V = unknown> = Map<A, V>; | ||
type AtomTuple<A = AnyWritableAtom, V = unknown> = readonly [ | ||
A, | ||
V | ||
]; | ||
type InferAtoms<T extends Iterable<AtomTuple>> = { | ||
[K in keyof T]: T[K] extends AtomTuple<infer A> ? A extends AnyWritableAtom ? AtomTuple<A, ReturnType<A['read']>> : T[K] : never; | ||
type InferAtomTuples<T> = { | ||
[K in keyof T]: T[K] extends readonly [ | ||
infer A, | ||
unknown | ||
] ? A extends WritableAtom<unknown, infer Args, any> ? readonly [ | ||
A, | ||
Args[0] | ||
] : T[K] : never; | ||
}; | ||
export declare function useHydrateAtoms<T extends Array<AtomTuple>>(values: InferAtoms<T>, options?: Options): void; | ||
export declare function useHydrateAtoms<T extends AtomMap>(values: T, options?: Options): void; | ||
export declare function useHydrateAtoms<T extends Iterable<AtomTuple>>(values: InferAtoms<T>, options?: Options): void; | ||
export type INTERNAL_InferAtomTuples<T> = InferAtomTuples<T>; | ||
export declare function useHydrateAtoms<T extends (readonly [ | ||
AnyWritableAtom, | ||
unknown | ||
])[]>(values: InferAtomTuples<T>, options?: Options): void; | ||
export declare function useHydrateAtoms<T extends Map<AnyWritableAtom, unknown>>(values: T, options?: Options): void; | ||
export declare function useHydrateAtoms<T extends Iterable<readonly [ | ||
AnyWritableAtom, | ||
unknown | ||
]>>(values: InferAtomTuples<T>, options?: Options): void; | ||
export {}; | ||
declare type Awaited<T> = T extends Promise<infer V> ? V : T; |
type Getter = <Value>(atom: Atom<Value>) => Value; | ||
type Setter = <Value, Args extends unknown[], Result>(atom: WritableAtom<Value, Args, Result>, ...args: Args) => Result; | ||
type SetAtom<Args extends unknown[], Result> = <A extends Args>(...args: A) => Result; | ||
/** | ||
* setSelf is for internal use only and subject to change without notice. | ||
*/ | ||
type Read<Value, SetSelf = never> = (get: Getter, options: { | ||
@@ -5,0 +8,0 @@ readonly signal: AbortSignal; |
@@ -7,14 +7,22 @@ import { useStore } from 'jotai/react'; | ||
type AnyWritableAtom = WritableAtom<unknown, any[], any>; | ||
type AtomMap<A = AnyWritableAtom, V = unknown> = Map<A, V>; | ||
type AtomTuple<A = AnyWritableAtom, V = unknown> = readonly [ | ||
A, | ||
V | ||
]; | ||
type InferAtoms<T extends Iterable<AtomTuple>> = { | ||
[K in keyof T]: T[K] extends AtomTuple<infer A> ? A extends AnyWritableAtom ? AtomTuple<A, ReturnType<A['read']>> : T[K] : never; | ||
type InferAtomTuples<T> = { | ||
[K in keyof T]: T[K] extends readonly [ | ||
infer A, | ||
unknown | ||
] ? A extends WritableAtom<unknown, infer Args, any> ? readonly [ | ||
A, | ||
Args[0] | ||
] : T[K] : never; | ||
}; | ||
export declare function useHydrateAtoms<T extends Array<AtomTuple>>(values: InferAtoms<T>, options?: Options): void; | ||
export declare function useHydrateAtoms<T extends AtomMap>(values: T, options?: Options): void; | ||
export declare function useHydrateAtoms<T extends Iterable<AtomTuple>>(values: InferAtoms<T>, options?: Options): void; | ||
export type INTERNAL_InferAtomTuples<T> = InferAtomTuples<T>; | ||
export declare function useHydrateAtoms<T extends (readonly [ | ||
AnyWritableAtom, | ||
unknown | ||
])[]>(values: InferAtomTuples<T>, options?: Options): void; | ||
export declare function useHydrateAtoms<T extends Map<AnyWritableAtom, unknown>>(values: T, options?: Options): void; | ||
export declare function useHydrateAtoms<T extends Iterable<readonly [ | ||
AnyWritableAtom, | ||
unknown | ||
]>>(values: InferAtomTuples<T>, options?: Options): void; | ||
export {}; | ||
declare type Awaited<T> = T extends Promise<infer V> ? V : T; |
type Getter = <Value>(atom: Atom<Value>) => Value; | ||
type Setter = <Value, Args extends unknown[], Result>(atom: WritableAtom<Value, Args, Result>, ...args: Args) => Result; | ||
type SetAtom<Args extends unknown[], Result> = <A extends Args>(...args: A) => Result; | ||
/** | ||
* setSelf is for internal use only and subject to change without notice. | ||
*/ | ||
type Read<Value, SetSelf = never> = (get: Getter, options: { | ||
@@ -5,0 +8,0 @@ readonly signal: AbortSignal; |
@@ -688,3 +688,4 @@ (function (global, factory) { | ||
p: promise, | ||
f: fallback(prev.v) | ||
f: fallback(prev.v), | ||
v: prev.v | ||
}; | ||
@@ -707,6 +708,6 @@ } | ||
var state = get(promiseAndValueAtom); | ||
if ('v' in state) { | ||
return state.v; | ||
if ('f' in state) { | ||
return state.f; | ||
} | ||
return state.f; | ||
return state.v; | ||
}, function (_get, set) { | ||
@@ -713,0 +714,0 @@ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { |
@@ -1,1 +0,1 @@ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("jotai/vanilla")):"function"==typeof define&&define.amd?define(["exports","jotai/vanilla"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).jotaiVanillaUtils={},t.jotaiVanilla)}(this,(function(t,n){"use strict";var e=Symbol();function r(t,n){(null==n||n>t.length)&&(n=t.length);for(var e=0,r=new Array(n);e<n;e++)r[e]=t[e];return r}function o(t,n){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(e)return(e=e.call(t)).next.bind(e);if(Array.isArray(t)||(e=function(t,n){if(t){if("string"==typeof t)return r(t,n);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?r(t,n):void 0}}(t))||n&&t&&"number"==typeof t.length){e&&(t=e);var o=0;return function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i=function(t,n,e){return(n.has(e)?n:n.set(e,t())).get(e)},a=new WeakMap;var u=new WeakMap,f=function t(n){if("object"==typeof n&&null!==n){Object.freeze(n);for(var e,r=o(Object.getOwnPropertyNames(n));!(e=r()).done;){t(n[e.value])}return n}};var c=function(t,n,e){return(n.has(e)?n:n.set(e,t())).get(e)},l=new WeakMap,s={},v=function(t){return!!t.write};function m(t){var n,e,r={getItem:function(r,o){var i,a,u,f=function(t){if(n!==(t=t||"")){try{e=JSON.parse(t)}catch(t){return o}n=t}return e},c=null!=(i=null==(a=t())?void 0:a.getItem(r))?i:null;return"function"==typeof(null==(u=c)?void 0:u.then)?c.then(f):f(c)},setItem:function(n,e){var r;return null==(r=t())?void 0:r.setItem(n,JSON.stringify(e))},removeItem:function(n){var e;return null==(e=t())?void 0:e.removeItem(n)}};return"undefined"!=typeof window&&"function"==typeof window.addEventListener&&window.Storage&&(r.subscribe=function(n,e,r){if(!(t()instanceof window.Storage))return function(){};var o=function(o){if(o.storageArea===t()&&o.key===n){var i;try{i=JSON.parse(o.newValue||"")}catch(t){i=r}e(i)}};return window.addEventListener("storage",o),function(){window.removeEventListener("storage",o)}}),r}var d=m((function(){return"undefined"!=typeof window?window.localStorage:void 0}));var b=new WeakMap,p={state:"loading"};var y=function(t,n,e){return(n.has(e)?n:n.set(e,t())).get(e)},h=new WeakMap,w=function(){};t.RESET=e,t.atomFamily=function(t,n){var e=null,r=new Map,i=function i(a){var u;if(void 0===n)u=r.get(a);else for(var f,c=o(r);!(f=c()).done;){var l=f.value,s=l[0],v=l[1];if(n(s,a)){u=v;break}}if(void 0!==u){if(null==e||!e(u[1],a))return u[0];i.remove(a)}var m=t(a);return r.set(a,[m,Date.now()]),m};return i.remove=function(t){if(void 0===n)r.delete(t);else for(var e,i=o(r);!(e=i()).done;){var a=e.value[0];if(n(a,t)){r.delete(a);break}}},i.setShouldRemove=function(t){if(e=t)for(var n,i=o(r);!(n=i()).done;){var a=n.value,u=a[0],f=a[1];e(f[1],u)&&r.delete(u)}},i},t.atomWithDefault=function(t){var r=Symbol(),o=n.atom(r),i=n.atom((function(n,e){var i=n(o);return i!==r?i:t(n,e)}),(function(t,n,a){if(a===e)n(o,r);else if("function"==typeof a){var u=t(i);n(o,a(u))}else n(o,a)}));return i},t.atomWithObservable=function(t,e){var r=function(t){if("e"in t)throw t.e;return t.d},o=n.atom((function(r){var o,i,a,u=t(r),f=null==(o=(i=u)[Symbol.observable])?void 0:o.call(i);f&&(u=f);var c,l,s,v,m=function(){return new Promise((function(t){a=t}))},d=e&&"initialValue"in e?{d:"function"==typeof e.initialValue?e.initialValue():e.initialValue}:m(),b=function(t){l=t,null==a||a(t),null==c||c(t)},p=function(){return!c},y=function(){s&&(clearTimeout(v),s.unsubscribe()),s=u.subscribe({next:function(t){return b({d:t})},error:function(t){return b({e:t})},complete:function(){}}),p()&&null!=e&&e.unstable_timeout&&(v=setTimeout((function(){s&&(s.unsubscribe(),s=void 0)}),e.unstable_timeout))};y();var h=n.atom(l||d);return h.onMount=function(t){return c=t,l&&t(l),s?clearTimeout(v):y(),function(){c=void 0,s&&(s.unsubscribe(),s=void 0)}},[h,u,m,y,p]}));return n.atom((function(t){var n=t(o),e=t(n[0]);return e instanceof Promise?e.then(r):r(e)}),(function(t,n,e){var r=t(o),i=r[0],a=r[1],u=r[2],f=r[3],c=r[4];if(!("next"in a))throw new Error("observable is not subject");c()&&(n(i,u()),f()),a.next(e)}))},t.atomWithReducer=function(t,e){var r=n.atom(t,(function(t,n,o){return n(r,e(t(r),o))}));return r},t.atomWithReset=function(t){var r=n.atom(t,(function(n,o,i){var a="function"==typeof i?i(n(r)):i;o(r,a===e?t:a)}));return r},t.atomWithStorage=function(t,r,o,i){void 0===o&&(o=d);var a=null==i?void 0:i.unstable_getOnInit,u=n.atom(a?o.getItem(t,r):r);return u.onMount=function(n){var e;return a||n(o.getItem(t,r)),o.subscribe&&(e=o.subscribe(t,n,r)),e},n.atom((function(t){return t(u)}),(function(n,i,a){var f="function"==typeof a?a(n(u)):a;return f===e?(i(u,r),o.removeItem(t)):f instanceof Promise?f.then((function(n){return i(u,n),o.setItem(t,n)})):(i(u,f),o.setItem(t,f))}))},t.createJSONStorage=m,t.freezeAtom=function(t){return e=function(){return n.atom((function(n){return f(n(t))}),(function(n,e,r){return e(t,r)}))},r=t,(u.has(r)?u:u.set(r,e())).get(r);var e,r},t.freezeAtomCreator=function(t){return function(){var n=t.apply(void 0,arguments),e=n.read;return n.read=function(t,n){return f(e.call(this,t,n))},n}},t.loadable=function(t){return e=function(){var e=new WeakMap,r=n.atom(0),o=n.atom((function(n,o){var i,a=o.setSelf;n(r);try{i=n(t)}catch(t){return{state:"hasError",error:t}}if(!(i instanceof Promise))return{state:"hasData",data:i};var u=i,f=e.get(u);return f||(e.set(u,p),u.then((function(t){e.set(u,{state:"hasData",data:t})}),(function(t){e.set(u,{state:"hasError",error:t})})).finally(a),p)}),(function(t,n){n(r,(function(t){return t+1}))}));return n.atom((function(t){return t(o)}))},r=t,(b.has(r)?b:b.set(r,e())).get(r);var e,r},t.selectAtom=function(t,e,r){return void 0===r&&(r=Object.is),o=function(){var o=Symbol(),i=function(t){var n=t[0],i=t[1];if(i===o)return e(n);var a=e(n,i);return r(i,a)?i:a},a=n.atom((function(n){var e=n(a),r=n(t);return r instanceof Promise||e instanceof Promise?Promise.all([r,e]).then(i):i([r,e])}));return a.init=o,a},u=e,f=r,c=i((function(){return new WeakMap}),a,t),l=i((function(){return new WeakMap}),c,u),i(o,l,f);var o,u,f,c,l},t.splitAtom=function(t,e){return r=function(){var r=new WeakMap,o=function o(a,u){var f=r.get(a);if(f)return f;var c=u&&r.get(u),l=[],s=[];return a.forEach((function(r,u){var f=e?e(r):u;s[u]=f;var m=c&&c.atomList[c.keyList.indexOf(f)];if(m)l[u]=m;else{var d=function(n){var e=n(i),r=n(t),u=o(r,null==e?void 0:e.arr).keyList.indexOf(f);if(u<0||u>=r.length){var c=a[o(a).keyList.indexOf(f)];if(c)return c;throw new Error("splitAtom: index out of bounds for read")}return r[u]};l[u]=v(t)?n.atom(d,(function(n,e,r){var a=n(i),u=n(t),c=o(u,null==a?void 0:a.arr).keyList.indexOf(f);if(c<0||c>=u.length)throw new Error("splitAtom: index out of bounds for write");var l="function"==typeof r?r(u[c]):r;Object.is(u[c],l)||e(t,[].concat(u.slice(0,c),[l],u.slice(c+1)))})):n.atom(d)}})),f=c&&c.keyList.length===s.length&&c.keyList.every((function(t,n){return t===s[n]}))?c:{arr:a,atomList:l,keyList:s},r.set(a,f),f},i=n.atom((function(n){var e=n(i),r=n(t);return o(r,null==e?void 0:e.arr)}));i.init=void 0;var a=v(t)?n.atom((function(t){return t(i).atomList}),(function(n,e,r){switch(r.type){case"remove":var o=n(a).indexOf(r.atom);if(o>=0){var i=n(t);e(t,[].concat(i.slice(0,o),i.slice(o+1)))}break;case"insert":var u=r.before?n(a).indexOf(r.before):n(a).length;if(u>=0){var f=n(t);e(t,[].concat(f.slice(0,u),[r.value],f.slice(u)))}break;case"move":var c=n(a).indexOf(r.atom),l=r.before?n(a).indexOf(r.before):n(a).length;if(c>=0&&l>=0){var s=n(t);e(t,c<l?[].concat(s.slice(0,c),s.slice(c+1,l),[s[c]],s.slice(l)):[].concat(s.slice(0,l),[s[c]],s.slice(l,c),s.slice(c+1)))}}})):n.atom((function(t){return t(i).atomList}));return a},o=e||s,i=c((function(){return new WeakMap}),l,t),c(r,i,o);var r,o,i},t.unwrap=function(t,e){return void 0===e&&(e=w),r=function(){var r=new WeakMap,o=new WeakMap,i=n.atom(0),a=n.atom((function(n,u){var f=u.setSelf;n(i);var c=n(a),l=n(t);if(!(l instanceof Promise))return{v:l};if(l===(null==c?void 0:c.p)){if(r.has(l))throw r.get(l);if(o.has(l))return{p:l,v:o.get(l)}}return l!==(null==c?void 0:c.p)&&l.then((function(t){return o.set(l,t)}),(function(t){return r.set(l,t)})).finally(f),c&&"v"in c?{p:l,f:e(c.v)}:{p:l,f:e()}}),(function(t,n){n(i,(function(t){return t+1}))}));return a.init=void 0,n.atom((function(t){var n=t(a);return"v"in n?n.v:n.f}),(function(n,e){for(var r=arguments.length,o=new Array(r>2?r-2:0),i=2;i<r;i++)o[i-2]=arguments[i];return e.apply(void 0,[t].concat(o))}))},o=e,i=y((function(){return new WeakMap}),h,t),y(r,i,o);var r,o,i}})); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("jotai/vanilla")):"function"==typeof define&&define.amd?define(["exports","jotai/vanilla"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).jotaiVanillaUtils={},t.jotaiVanilla)}(this,(function(t,n){"use strict";var e=Symbol();function r(t,n){(null==n||n>t.length)&&(n=t.length);for(var e=0,r=new Array(n);e<n;e++)r[e]=t[e];return r}function o(t,n){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(e)return(e=e.call(t)).next.bind(e);if(Array.isArray(t)||(e=function(t,n){if(t){if("string"==typeof t)return r(t,n);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?r(t,n):void 0}}(t))||n&&t&&"number"==typeof t.length){e&&(t=e);var o=0;return function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i=function(t,n,e){return(n.has(e)?n:n.set(e,t())).get(e)},a=new WeakMap;var u=new WeakMap,f=function t(n){if("object"==typeof n&&null!==n){Object.freeze(n);for(var e,r=o(Object.getOwnPropertyNames(n));!(e=r()).done;){t(n[e.value])}return n}};var c=function(t,n,e){return(n.has(e)?n:n.set(e,t())).get(e)},l=new WeakMap,s={},v=function(t){return!!t.write};function m(t){var n,e,r={getItem:function(r,o){var i,a,u,f=function(t){if(n!==(t=t||"")){try{e=JSON.parse(t)}catch(t){return o}n=t}return e},c=null!=(i=null==(a=t())?void 0:a.getItem(r))?i:null;return"function"==typeof(null==(u=c)?void 0:u.then)?c.then(f):f(c)},setItem:function(n,e){var r;return null==(r=t())?void 0:r.setItem(n,JSON.stringify(e))},removeItem:function(n){var e;return null==(e=t())?void 0:e.removeItem(n)}};return"undefined"!=typeof window&&"function"==typeof window.addEventListener&&window.Storage&&(r.subscribe=function(n,e,r){if(!(t()instanceof window.Storage))return function(){};var o=function(o){if(o.storageArea===t()&&o.key===n){var i;try{i=JSON.parse(o.newValue||"")}catch(t){i=r}e(i)}};return window.addEventListener("storage",o),function(){window.removeEventListener("storage",o)}}),r}var d=m((function(){return"undefined"!=typeof window?window.localStorage:void 0}));var b=new WeakMap,p={state:"loading"};var y=function(t,n,e){return(n.has(e)?n:n.set(e,t())).get(e)},h=new WeakMap,w=function(){};t.RESET=e,t.atomFamily=function(t,n){var e=null,r=new Map,i=function i(a){var u;if(void 0===n)u=r.get(a);else for(var f,c=o(r);!(f=c()).done;){var l=f.value,s=l[0],v=l[1];if(n(s,a)){u=v;break}}if(void 0!==u){if(null==e||!e(u[1],a))return u[0];i.remove(a)}var m=t(a);return r.set(a,[m,Date.now()]),m};return i.remove=function(t){if(void 0===n)r.delete(t);else for(var e,i=o(r);!(e=i()).done;){var a=e.value[0];if(n(a,t)){r.delete(a);break}}},i.setShouldRemove=function(t){if(e=t)for(var n,i=o(r);!(n=i()).done;){var a=n.value,u=a[0],f=a[1];e(f[1],u)&&r.delete(u)}},i},t.atomWithDefault=function(t){var r=Symbol(),o=n.atom(r),i=n.atom((function(n,e){var i=n(o);return i!==r?i:t(n,e)}),(function(t,n,a){if(a===e)n(o,r);else if("function"==typeof a){var u=t(i);n(o,a(u))}else n(o,a)}));return i},t.atomWithObservable=function(t,e){var r=function(t){if("e"in t)throw t.e;return t.d},o=n.atom((function(r){var o,i,a,u=t(r),f=null==(o=(i=u)[Symbol.observable])?void 0:o.call(i);f&&(u=f);var c,l,s,v,m=function(){return new Promise((function(t){a=t}))},d=e&&"initialValue"in e?{d:"function"==typeof e.initialValue?e.initialValue():e.initialValue}:m(),b=function(t){l=t,null==a||a(t),null==c||c(t)},p=function(){return!c},y=function(){s&&(clearTimeout(v),s.unsubscribe()),s=u.subscribe({next:function(t){return b({d:t})},error:function(t){return b({e:t})},complete:function(){}}),p()&&null!=e&&e.unstable_timeout&&(v=setTimeout((function(){s&&(s.unsubscribe(),s=void 0)}),e.unstable_timeout))};y();var h=n.atom(l||d);return h.onMount=function(t){return c=t,l&&t(l),s?clearTimeout(v):y(),function(){c=void 0,s&&(s.unsubscribe(),s=void 0)}},[h,u,m,y,p]}));return n.atom((function(t){var n=t(o),e=t(n[0]);return e instanceof Promise?e.then(r):r(e)}),(function(t,n,e){var r=t(o),i=r[0],a=r[1],u=r[2],f=r[3],c=r[4];if(!("next"in a))throw new Error("observable is not subject");c()&&(n(i,u()),f()),a.next(e)}))},t.atomWithReducer=function(t,e){var r=n.atom(t,(function(t,n,o){return n(r,e(t(r),o))}));return r},t.atomWithReset=function(t){var r=n.atom(t,(function(n,o,i){var a="function"==typeof i?i(n(r)):i;o(r,a===e?t:a)}));return r},t.atomWithStorage=function(t,r,o,i){void 0===o&&(o=d);var a=null==i?void 0:i.unstable_getOnInit,u=n.atom(a?o.getItem(t,r):r);return u.onMount=function(n){var e;return a||n(o.getItem(t,r)),o.subscribe&&(e=o.subscribe(t,n,r)),e},n.atom((function(t){return t(u)}),(function(n,i,a){var f="function"==typeof a?a(n(u)):a;return f===e?(i(u,r),o.removeItem(t)):f instanceof Promise?f.then((function(n){return i(u,n),o.setItem(t,n)})):(i(u,f),o.setItem(t,f))}))},t.createJSONStorage=m,t.freezeAtom=function(t){return e=function(){return n.atom((function(n){return f(n(t))}),(function(n,e,r){return e(t,r)}))},r=t,(u.has(r)?u:u.set(r,e())).get(r);var e,r},t.freezeAtomCreator=function(t){return function(){var n=t.apply(void 0,arguments),e=n.read;return n.read=function(t,n){return f(e.call(this,t,n))},n}},t.loadable=function(t){return e=function(){var e=new WeakMap,r=n.atom(0),o=n.atom((function(n,o){var i,a=o.setSelf;n(r);try{i=n(t)}catch(t){return{state:"hasError",error:t}}if(!(i instanceof Promise))return{state:"hasData",data:i};var u=i,f=e.get(u);return f||(e.set(u,p),u.then((function(t){e.set(u,{state:"hasData",data:t})}),(function(t){e.set(u,{state:"hasError",error:t})})).finally(a),p)}),(function(t,n){n(r,(function(t){return t+1}))}));return n.atom((function(t){return t(o)}))},r=t,(b.has(r)?b:b.set(r,e())).get(r);var e,r},t.selectAtom=function(t,e,r){return void 0===r&&(r=Object.is),o=function(){var o=Symbol(),i=function(t){var n=t[0],i=t[1];if(i===o)return e(n);var a=e(n,i);return r(i,a)?i:a},a=n.atom((function(n){var e=n(a),r=n(t);return r instanceof Promise||e instanceof Promise?Promise.all([r,e]).then(i):i([r,e])}));return a.init=o,a},u=e,f=r,c=i((function(){return new WeakMap}),a,t),l=i((function(){return new WeakMap}),c,u),i(o,l,f);var o,u,f,c,l},t.splitAtom=function(t,e){return r=function(){var r=new WeakMap,o=function o(a,u){var f=r.get(a);if(f)return f;var c=u&&r.get(u),l=[],s=[];return a.forEach((function(r,u){var f=e?e(r):u;s[u]=f;var m=c&&c.atomList[c.keyList.indexOf(f)];if(m)l[u]=m;else{var d=function(n){var e=n(i),r=n(t),u=o(r,null==e?void 0:e.arr).keyList.indexOf(f);if(u<0||u>=r.length){var c=a[o(a).keyList.indexOf(f)];if(c)return c;throw new Error("splitAtom: index out of bounds for read")}return r[u]};l[u]=v(t)?n.atom(d,(function(n,e,r){var a=n(i),u=n(t),c=o(u,null==a?void 0:a.arr).keyList.indexOf(f);if(c<0||c>=u.length)throw new Error("splitAtom: index out of bounds for write");var l="function"==typeof r?r(u[c]):r;Object.is(u[c],l)||e(t,[].concat(u.slice(0,c),[l],u.slice(c+1)))})):n.atom(d)}})),f=c&&c.keyList.length===s.length&&c.keyList.every((function(t,n){return t===s[n]}))?c:{arr:a,atomList:l,keyList:s},r.set(a,f),f},i=n.atom((function(n){var e=n(i),r=n(t);return o(r,null==e?void 0:e.arr)}));i.init=void 0;var a=v(t)?n.atom((function(t){return t(i).atomList}),(function(n,e,r){switch(r.type){case"remove":var o=n(a).indexOf(r.atom);if(o>=0){var i=n(t);e(t,[].concat(i.slice(0,o),i.slice(o+1)))}break;case"insert":var u=r.before?n(a).indexOf(r.before):n(a).length;if(u>=0){var f=n(t);e(t,[].concat(f.slice(0,u),[r.value],f.slice(u)))}break;case"move":var c=n(a).indexOf(r.atom),l=r.before?n(a).indexOf(r.before):n(a).length;if(c>=0&&l>=0){var s=n(t);e(t,c<l?[].concat(s.slice(0,c),s.slice(c+1,l),[s[c]],s.slice(l)):[].concat(s.slice(0,l),[s[c]],s.slice(l,c),s.slice(c+1)))}}})):n.atom((function(t){return t(i).atomList}));return a},o=e||s,i=c((function(){return new WeakMap}),l,t),c(r,i,o);var r,o,i},t.unwrap=function(t,e){return void 0===e&&(e=w),r=function(){var r=new WeakMap,o=new WeakMap,i=n.atom(0),a=n.atom((function(n,u){var f=u.setSelf;n(i);var c=n(a),l=n(t);if(!(l instanceof Promise))return{v:l};if(l===(null==c?void 0:c.p)){if(r.has(l))throw r.get(l);if(o.has(l))return{p:l,v:o.get(l)}}return l!==(null==c?void 0:c.p)&&l.then((function(t){return o.set(l,t)}),(function(t){return r.set(l,t)})).finally(f),c&&"v"in c?{p:l,f:e(c.v),v:c.v}:{p:l,f:e()}}),(function(t,n){n(i,(function(t){return t+1}))}));return a.init=void 0,n.atom((function(t){var n=t(a);return"f"in n?n.f:n.v}),(function(n,e){for(var r=arguments.length,o=new Array(r>2?r-2:0),i=2;i<r;i++)o[i-2]=arguments[i];return e.apply(void 0,[t].concat(o))}))},o=e,i=y((function(){return new WeakMap}),h,t),y(r,i,o);var r,o,i}})); |
type Getter = <Value>(atom: Atom<Value>) => Value; | ||
type Setter = <Value, Args extends unknown[], Result>(atom: WritableAtom<Value, Args, Result>, ...args: Args) => Result; | ||
type SetAtom<Args extends unknown[], Result> = <A extends Args>(...args: A) => Result; | ||
/** | ||
* setSelf is for internal use only and subject to change without notice. | ||
*/ | ||
type Read<Value, SetSelf = never> = (get: Getter, options: { | ||
@@ -5,0 +8,0 @@ readonly signal: AbortSignal; |
@@ -686,3 +686,4 @@ 'use strict'; | ||
p: promise, | ||
f: fallback(prev.v) | ||
f: fallback(prev.v), | ||
v: prev.v | ||
}; | ||
@@ -705,6 +706,6 @@ } | ||
var state = get(promiseAndValueAtom); | ||
if ('v' in state) { | ||
return state.v; | ||
if ('f' in state) { | ||
return state.f; | ||
} | ||
return state.f; | ||
return state.v; | ||
}, function (_get, set) { | ||
@@ -711,0 +712,0 @@ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { |
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
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
403451
8865