Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jotai

Package Overview
Dependencies
Maintainers
2
Versions
178
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jotai - npm Package Compare versions

Comparing version 2.2.0 to 2.2.1

2

package.json
{
"name": "jotai",
"private": false,
"version": "2.2.0",
"version": "2.2.1",
"description": "👻 Primitive and flexible state management for React",

@@ -6,0 +6,0 @@ "main": "./index.js",

@@ -80,3 +80,3 @@ 'use strict';

value = _step$value[1];
if (!hydratedSet.has(atom)) {
if (!hydratedSet.has(atom) || options != null && options.dangerouslyForceHydrate) {
hydratedSet.add(atom);

@@ -83,0 +83,0 @@ store.set(atom, value);

import { useStore } from 'jotai/react';
import type { WritableAtom } from 'jotai/vanilla';
type Options = Parameters<typeof useStore>[0];
type Options = Parameters<typeof useStore>[0] & {
dangerouslyForceHydrate?: boolean;
};
type AnyWritableAtom = WritableAtom<unknown, any[], any>;

@@ -5,0 +7,0 @@ type AtomMap<A = AnyWritableAtom, V = unknown> = Map<A, V>;

@@ -56,3 +56,3 @@ System.register(['react', 'jotai/react', 'jotai/vanilla/utils', 'jotai/vanilla'], (function (exports) {

for (const [atom, value] of values) {
if (!hydratedSet.has(atom)) {
if (!hydratedSet.has(atom) || (options == null ? void 0 : options.dangerouslyForceHydrate)) {
hydratedSet.add(atom);

@@ -59,0 +59,0 @@ store.set(atom, value);

@@ -1,1 +0,1 @@

System.register(["react","jotai/react","jotai/vanilla/utils","jotai/vanilla"],function(k){"use strict";var c,i,r,m,l,A,f;return{setters:[function(e){c=e.useCallback,i=e.useMemo},function(e){r=e.useSetAtom,m=e.useAtom,l=e.useStore},function(e){A=e.RESET},function(e){f=e.atom}],execute:function(){k({useAtomCallback:b,useHydrateAtoms:C,useReducerAtom:R,useResetAtom:e});function e(s,t){const n=r(s,t);return c(()=>n(A),[n])}function R(s,t,n){const[u,o]=m(s,n),a=c(d=>{o(j=>t(j,d))},[o,t]);return[u,a]}function b(s,t){const n=i(()=>f(null,(u,o,...a)=>s(u,o,...a)),[s]);return r(n,t)}const S=new WeakMap;function C(s,t){const n=l(t),u=E(n);for(const[o,a]of s)u.has(o)||(u.add(o),n.set(o,a))}const E=s=>{let t=S.get(s);return t||(t=new WeakSet,S.set(s,t)),t}}}});
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}}}});

@@ -418,3 +418,3 @@ System.register(['jotai/vanilla'], (function (exports) {

}
if (isPromiseLike(nextValue)) {
if (nextValue instanceof Promise) {
return nextValue.then((resolvedValue) => {

@@ -600,2 +600,5 @@ set(baseAtom, resolvedValue);

const promise = get(anAtom);
if (!(promise instanceof Promise)) {
return { v: promise };
}
if (promise === (prev == null ? void 0 : prev.p)) {

@@ -637,3 +640,3 @@ if (promiseErrorCache.has(promise)) {

return state.f;
});
}, anAtom.write);
},

@@ -640,0 +643,0 @@ anAtom,

@@ -1,1 +0,1 @@

System.register(["jotai/vanilla"],function(A){"use strict";var f;return{setters:[function(S){f=S.atom}],execute:function(){A({atomFamily:J,atomWithDefault:X,atomWithObservable:tt,atomWithReducer:z,atomWithReset:V,atomWithStorage:Z,createJSONStorage:D,freezeAtom:K,freezeAtomCreator:q,loadable:nt,selectAtom:C,splitAtom:U,unstable_unwrap:it});const S=A("RESET",Symbol());function V(e){const n=f(e,(o,c,s)=>{const r=typeof s=="function"?s(o(n)):s;c(n,r===S?e:r)});return n}function z(e,n){const o=f(e,(c,s,r)=>s(o,n(c(o),r)));return o}function J(e,n){let o=null;const c=new Map,s=r=>{let t;if(n===void 0)t=c.get(r);else for(const[i,a]of c)if(n(i,r)){t=a;break}if(t!==void 0)if(o!=null&&o(t[1],r))s.remove(r);else return t[0];const u=e(r);return c.set(r,[u,Date.now()]),u};return s.remove=r=>{if(n===void 0)c.delete(r);else for(const[t]of c)if(n(t,r)){c.delete(t);break}},s.setShouldRemove=r=>{if(o=r,!!o)for(const[t,u]of c)o(u[1],t)&&c.delete(t)},s}const L=(e,n,o)=>(n.has(o)?n:n.set(o,e())).get(o),_=new WeakMap,$=(e,n,o,c)=>{const s=L(()=>new WeakMap,_,n),r=L(()=>new WeakMap,s,o);return L(e,r,c)};function C(e,n,o=Object.is){return $(()=>{const c=Symbol(),s=([t,u])=>{if(u===c)return n(t);const i=n(t,u);return o(u,i)?u:i},r=f(t=>{const u=t(r),i=t(e);return i instanceof Promise||u instanceof Promise?Promise.all([i,u]).then(s):s([i,u])});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=(s,r)=>x(c(s,r)),o}}const P=(e,n,o)=>(n.has(o)?n:n.set(o,e())).get(o),B=new WeakMap,G=(e,n,o)=>{const c=P(()=>new WeakMap,B,n);return P(e,c,o)},H={},R=e=>!!e.write,Q=e=>typeof e=="function";function U(e,n){return G(()=>{const o=new WeakMap,c=(t,u)=>{let i=o.get(t);if(i)return i;const a=u&&o.get(u),l=[],m=[];return t.forEach((w,v)=>{const b=n?n(w):v;m[v]=b;const g=a&&a.atomList[a.keyList.indexOf(b)];if(g){l[v]=g;return}const W=h=>{const d=h(s),y=h(e),k=c(y,d==null?void 0:d.arr).keyList.indexOf(b);if(k<0||k>=y.length){const p=t[c(t).keyList.indexOf(b)];if(p)return p;throw new Error("splitAtom: index out of bounds for read")}return y[k]},O=(h,d,y)=>{const k=h(s),p=h(e),M=c(p,k==null?void 0:k.arr).keyList.indexOf(b);if(M<0||M>=p.length)throw new Error("splitAtom: index out of bounds for write");const at=Q(y)?y(p[M]):y;d(e,[...p.slice(0,M),at,...p.slice(M+1)])};l[v]=R(e)?f(W,O):f(W)}),a&&a.keyList.length===m.length&&a.keyList.every((w,v)=>w===m[v])?i=a:i={arr:t,atomList:l,keyList:m},o.set(t,i),i},s=f(t=>{const u=t(s),i=t(e);return c(i,u==null?void 0:u.arr)});s.init=void 0;const r=R(e)?f(t=>t(s).atomList,(t,u,i)=>{switch(i.type){case"remove":{const a=t(r).indexOf(i.atom);if(a>=0){const l=t(e);u(e,[...l.slice(0,a),...l.slice(a+1)])}break}case"insert":{const a=i.before?t(r).indexOf(i.before):t(r).length;if(a>=0){const l=t(e);u(e,[...l.slice(0,a),i.value,...l.slice(a)])}break}case"move":{const a=t(r).indexOf(i.atom),l=i.before?t(r).indexOf(i.before):t(r).length;if(a>=0&&l>=0){const m=t(e);a<l?u(e,[...m.slice(0,a),...m.slice(a+1,l),m[a],...m.slice(l)]):u(e,[...m.slice(0,l),m[a],...m.slice(l,a),...m.slice(a+1)])}break}}}):f(t=>t(s).atomList);return r},e,n||H)}function X(e){const n=Symbol(),o=f(n),c=f((s,r)=>{const t=s(o);return t!==n?t:e(s,r)},(s,r,t)=>{if(t===S)r(o,n);else if(typeof t=="function"){const u=s(c);r(o,t(u))}else r(o,t)});return c}const j=e=>typeof(e==null?void 0:e.then)=="function";function D(e){let n,o;const c={getItem:(s,r)=>{var t,u;const i=l=>{if(l=l||"",n!==l){try{o=JSON.parse(l)}catch{return r}n=l}return o},a=(u=(t=e())==null?void 0:t.getItem(s))!=null?u:null;return j(a)?a.then(i):i(a)},setItem:(s,r)=>{var t;return(t=e())==null?void 0:t.setItem(s,JSON.stringify(r))},removeItem:s=>{var r;return(r=e())==null?void 0:r.removeItem(s)}};return typeof window<"u"&&typeof window.addEventListener=="function"&&(c.subscribe=(s,r,t)=>{if(!(e()instanceof window.Storage))return()=>{};const u=i=>{if(i.storageArea===e()&&i.key===s){let a;try{a=JSON.parse(i.newValue||"")}catch{a=t}r(a)}};return window.addEventListener("storage",u),()=>{window.removeEventListener("storage",u)}}),c}const Y=D(()=>typeof window<"u"?window.localStorage:void 0);function Z(e,n,o=Y,c){const s=c==null?void 0:c.unstable_getOnInit,r=f(s?o.getItem(e,n):n);return r.onMount=t=>{s||t(o.getItem(e,n));let u;return o.subscribe&&(u=o.subscribe(e,t,n)),u},f(t=>t(r),(t,u,i)=>{const a=typeof i=="function"?i(t(r)):i;return a===S?(u(r,n),o.removeItem(e)):j(a)?a.then(l=>(u(r,l),o.setItem(e,l))):(u(r,a),o.setItem(e,a))})}function tt(e,n){const o=s=>{if("e"in s)throw s.e;return s.d},c=f(s=>{var r;let t=e(s);const u=(r=t[Symbol.observable])==null?void 0:r.call(t);u&&(t=u);let i;const a=()=>new Promise(d=>{i=d}),l=n&&"initialValue"in n?{d:typeof n.initialValue=="function"?n.initialValue():n.initialValue}:a();let m,w;const v=d=>{w=d,i==null||i(d),m==null||m(d)};let b,g;const W=()=>!m,O=()=>{b&&(clearTimeout(g),b.unsubscribe()),b=t.subscribe({next:d=>v({d}),error:d=>v({e:d}),complete:()=>{}}),W()&&n!=null&&n.unstable_timeout&&(g=setTimeout(()=>{b&&(b.unsubscribe(),b=void 0)},n.unstable_timeout))};O();const h=f(w||l);return h.onMount=d=>(m=d,w&&d(w),b?clearTimeout(g):O(),()=>{m=void 0,b&&(b.unsubscribe(),b=void 0)}),[h,t,a,O,W]});return f(s=>{const[r]=s(c),t=s(r);return t instanceof Promise?t.then(o):o(t)},(s,r,t)=>{const[u,i,a,l,m]=s(c);if("next"in i)m()&&(r(u,a()),l()),i.next(t);else throw new Error("observable is not subject")})}const E=new WeakMap,et=(e,n)=>(E.has(n)?E:E.set(n,e())).get(n),N={state:"loading"};function nt(e){return et(()=>{const n=new WeakMap,o=f(0),c=f((s,{setSelf:r})=>{s(o);const t=s(e);return t instanceof Promise?n.get(t)||(n.set(t,N),t.then(i=>{n.set(t,{state:"hasData",data:i})},i=>{n.set(t,{state:"hasError",error:i})}).finally(r),N):{state:"hasData",data:t}},(s,r)=>{r(o,t=>t+1)});return f(s=>s(c))},e)}const T=(e,n,o)=>(n.has(o)?n:n.set(o,e())).get(o),ot=new WeakMap,rt=(e,n,o)=>{const c=T(()=>new WeakMap,ot,n);return T(e,c,o)},st=()=>{};function it(e,n=st){return rt(()=>{const o=new WeakMap,c=new WeakMap,s=f(0),r=f((t,{setSelf:u})=>{t(s);const i=t(r),a=t(e);if(a===(i==null?void 0:i.p)){if(o.has(a))throw o.get(a);if(c.has(a))return{p:a,v:c.get(a)}}return a!==(i==null?void 0:i.p)&&a.then(l=>c.set(a,l),l=>o.set(a,l)).finally(u),i&&"v"in i?{p:a,f:n(i.v)}:{p:a,f:n()}},(t,u)=>{u(s,i=>i+1)});return r.init=void 0,f(t=>{const u=t(r);return"v"in u?u.v:u.f})},e,n)}}}});
System.register(["jotai/vanilla"],function(P){"use strict";var f;return{setters:[function(S){f=S.atom}],execute:function(){P({atomFamily:z,atomWithDefault:U,atomWithObservable:tt,atomWithReducer:V,atomWithReset:T,atomWithStorage:Z,createJSONStorage:j,freezeAtom:F,freezeAtomCreator:K,loadable:nt,selectAtom:$,splitAtom:Q,unstable_unwrap:it});const S=P("RESET",Symbol());function T(e){const n=f(e,(o,u,s)=>{const r=typeof s=="function"?s(o(n)):s;u(n,r===S?e:r)});return n}function V(e,n){const o=f(e,(u,s,r)=>s(o,n(u(o),r)));return o}function z(e,n){let o=null;const u=new Map,s=r=>{let t;if(n===void 0)t=u.get(r);else for(const[a,i]of u)if(n(a,r)){t=i;break}if(t!==void 0)if(o!=null&&o(t[1],r))s.remove(r);else return t[0];const c=e(r);return u.set(r,[c,Date.now()]),c};return s.remove=r=>{if(n===void 0)u.delete(r);else for(const[t]of u)if(n(t,r)){u.delete(t);break}},s.setShouldRemove=r=>{if(o=r,!!o)for(const[t,c]of u)o(c[1],t)&&u.delete(t)},s}const L=(e,n,o)=>(n.has(o)?n:n.set(o,e())).get(o),J=new WeakMap,_=(e,n,o,u)=>{const s=L(()=>new WeakMap,J,n),r=L(()=>new WeakMap,s,o);return L(e,r,u)};function $(e,n,o=Object.is){return _(()=>{const u=Symbol(),s=([t,c])=>{if(c===u)return n(t);const a=n(t,c);return o(c,a)?c:a},r=f(t=>{const c=t(r),a=t(e);return a instanceof Promise||c instanceof Promise?Promise.all([a,c]).then(s):s([a,c])});return r.init=u,r},e,n,o)}const I=new WeakMap,C=(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 u=e[o];x(u)}return e};function F(e){return C(()=>f(n=>x(n(e)),(n,o,u)=>o(e,u)),e)}function K(e){return(...n)=>{const o=e(...n),u=o.read;return o.read=(s,r)=>x(u(s,r)),o}}const A=(e,n,o)=>(n.has(o)?n:n.set(o,e())).get(o),q=new WeakMap,B=(e,n,o)=>{const u=A(()=>new WeakMap,q,n);return A(e,u,o)},G={},R=e=>!!e.write,H=e=>typeof e=="function";function Q(e,n){return B(()=>{const o=new WeakMap,u=(t,c)=>{let a=o.get(t);if(a)return a;const i=c&&o.get(c),l=[],m=[];return t.forEach((w,v)=>{const b=n?n(w):v;m[v]=b;const g=i&&i.atomList[i.keyList.indexOf(b)];if(g){l[v]=g;return}const W=h=>{const d=h(s),y=h(e),k=u(y,d==null?void 0:d.arr).keyList.indexOf(b);if(k<0||k>=y.length){const p=t[u(t).keyList.indexOf(b)];if(p)return p;throw new Error("splitAtom: index out of bounds for read")}return y[k]},O=(h,d,y)=>{const k=h(s),p=h(e),M=u(p,k==null?void 0:k.arr).keyList.indexOf(b);if(M<0||M>=p.length)throw new Error("splitAtom: index out of bounds for write");const at=H(y)?y(p[M]):y;d(e,[...p.slice(0,M),at,...p.slice(M+1)])};l[v]=R(e)?f(W,O):f(W)}),i&&i.keyList.length===m.length&&i.keyList.every((w,v)=>w===m[v])?a=i:a={arr:t,atomList:l,keyList:m},o.set(t,a),a},s=f(t=>{const c=t(s),a=t(e);return u(a,c==null?void 0:c.arr)});s.init=void 0;const r=R(e)?f(t=>t(s).atomList,(t,c,a)=>{switch(a.type){case"remove":{const i=t(r).indexOf(a.atom);if(i>=0){const l=t(e);c(e,[...l.slice(0,i),...l.slice(i+1)])}break}case"insert":{const i=a.before?t(r).indexOf(a.before):t(r).length;if(i>=0){const l=t(e);c(e,[...l.slice(0,i),a.value,...l.slice(i)])}break}case"move":{const i=t(r).indexOf(a.atom),l=a.before?t(r).indexOf(a.before):t(r).length;if(i>=0&&l>=0){const m=t(e);i<l?c(e,[...m.slice(0,i),...m.slice(i+1,l),m[i],...m.slice(l)]):c(e,[...m.slice(0,l),m[i],...m.slice(l,i),...m.slice(i+1)])}break}}}):f(t=>t(s).atomList);return r},e,n||G)}function U(e){const n=Symbol(),o=f(n),u=f((s,r)=>{const t=s(o);return t!==n?t:e(s,r)},(s,r,t)=>{if(t===S)r(o,n);else if(typeof t=="function"){const c=s(u);r(o,t(c))}else r(o,t)});return u}const X=e=>typeof(e==null?void 0:e.then)=="function";function j(e){let n,o;const u={getItem:(s,r)=>{var t,c;const a=l=>{if(l=l||"",n!==l){try{o=JSON.parse(l)}catch{return r}n=l}return o},i=(c=(t=e())==null?void 0:t.getItem(s))!=null?c:null;return X(i)?i.then(a):a(i)},setItem:(s,r)=>{var t;return(t=e())==null?void 0:t.setItem(s,JSON.stringify(r))},removeItem:s=>{var r;return(r=e())==null?void 0:r.removeItem(s)}};return typeof window<"u"&&typeof window.addEventListener=="function"&&(u.subscribe=(s,r,t)=>{if(!(e()instanceof window.Storage))return()=>{};const c=a=>{if(a.storageArea===e()&&a.key===s){let i;try{i=JSON.parse(a.newValue||"")}catch{i=t}r(i)}};return window.addEventListener("storage",c),()=>{window.removeEventListener("storage",c)}}),u}const Y=j(()=>typeof window<"u"?window.localStorage:void 0);function Z(e,n,o=Y,u){const s=u==null?void 0:u.unstable_getOnInit,r=f(s?o.getItem(e,n):n);return r.onMount=t=>{s||t(o.getItem(e,n));let c;return o.subscribe&&(c=o.subscribe(e,t,n)),c},f(t=>t(r),(t,c,a)=>{const i=typeof a=="function"?a(t(r)):a;return i===S?(c(r,n),o.removeItem(e)):i instanceof Promise?i.then(l=>(c(r,l),o.setItem(e,l))):(c(r,i),o.setItem(e,i))})}function tt(e,n){const o=s=>{if("e"in s)throw s.e;return s.d},u=f(s=>{var r;let t=e(s);const c=(r=t[Symbol.observable])==null?void 0:r.call(t);c&&(t=c);let a;const i=()=>new Promise(d=>{a=d}),l=n&&"initialValue"in n?{d:typeof n.initialValue=="function"?n.initialValue():n.initialValue}:i();let m,w;const v=d=>{w=d,a==null||a(d),m==null||m(d)};let b,g;const W=()=>!m,O=()=>{b&&(clearTimeout(g),b.unsubscribe()),b=t.subscribe({next:d=>v({d}),error:d=>v({e:d}),complete:()=>{}}),W()&&n!=null&&n.unstable_timeout&&(g=setTimeout(()=>{b&&(b.unsubscribe(),b=void 0)},n.unstable_timeout))};O();const h=f(w||l);return h.onMount=d=>(m=d,w&&d(w),b?clearTimeout(g):O(),()=>{m=void 0,b&&(b.unsubscribe(),b=void 0)}),[h,t,i,O,W]});return f(s=>{const[r]=s(u),t=s(r);return t instanceof Promise?t.then(o):o(t)},(s,r,t)=>{const[c,a,i,l,m]=s(u);if("next"in a)m()&&(r(c,i()),l()),a.next(t);else throw new Error("observable is not subject")})}const E=new WeakMap,et=(e,n)=>(E.has(n)?E:E.set(n,e())).get(n),D={state:"loading"};function nt(e){return et(()=>{const n=new WeakMap,o=f(0),u=f((s,{setSelf:r})=>{s(o);const t=s(e);return t instanceof Promise?n.get(t)||(n.set(t,D),t.then(a=>{n.set(t,{state:"hasData",data:a})},a=>{n.set(t,{state:"hasError",error:a})}).finally(r),D):{state:"hasData",data:t}},(s,r)=>{r(o,t=>t+1)});return f(s=>s(u))},e)}const N=(e,n,o)=>(n.has(o)?n:n.set(o,e())).get(o),ot=new WeakMap,rt=(e,n,o)=>{const u=N(()=>new WeakMap,ot,n);return N(e,u,o)},st=()=>{};function it(e,n=st){return rt(()=>{const o=new WeakMap,u=new WeakMap,s=f(0),r=f((t,{setSelf:c})=>{t(s);const a=t(r),i=t(e);if(!(i instanceof Promise))return{v:i};if(i===(a==null?void 0:a.p)){if(o.has(i))throw o.get(i);if(u.has(i))return{p:i,v:u.get(i)}}return i!==(a==null?void 0:a.p)&&i.then(l=>u.set(i,l),l=>o.set(i,l)).finally(c),a&&"v"in a?{p:i,f:n(a.v)}:{p:i,f:n()}},(t,c)=>{c(s,a=>a+1)});return r.init=void 0,f(t=>{const c=t(r);return"v"in c?c.v:c.f},e.write)},e,n)}}}});
import { useStore } from 'jotai/react';
import type { WritableAtom } from 'jotai/vanilla';
type Options = Parameters<typeof useStore>[0];
type Options = Parameters<typeof useStore>[0] & {
dangerouslyForceHydrate?: boolean;
};
type AnyWritableAtom = WritableAtom<unknown, any[], any>;

@@ -5,0 +7,0 @@ type AtomMap<A = AnyWritableAtom, V = unknown> = Map<A, V>;

@@ -31,5 +31,5 @@ import type { WritableAtom } from 'jotai/vanilla';

unstable_getOnInit?: boolean;
}): WritableAtom<PromiseLike<Value> | Value, [
SetStateActionWithReset<PromiseLike<Value> | Value>
], PromiseLike<void>>;
}): WritableAtom<Value | Promise<Value>, [
SetStateActionWithReset<Value | Promise<Value>>
], Promise<void>>;
export declare function atomWithStorage<Value>(key: string, initialValue: Value, storage?: SyncStorage<Value>, unstable_options?: {

@@ -36,0 +36,0 @@ unstable_getOnInit?: boolean;

import type { Atom } from 'jotai/vanilla';
export declare function selectAtom<Value, Slice>(anAtom: Atom<Promise<Value>>, selector: (v: Awaited<Value>, prevSlice?: Slice) => Slice, equalityFn?: (a: Slice, b: Slice) => boolean): Atom<Promise<Slice>>;
export declare function selectAtom<Value, Slice>(anAtom: Atom<Value>, selector: (v: Awaited<Value>, prevSlice?: Slice) => Slice, equalityFn?: (a: Slice, b: Slice) => boolean): Atom<Slice>;
export declare function selectAtom<Value, Slice>(anAtom: Atom<Value>, selector: (v: Awaited<Value>, prevSlice?: Slice) => Slice, equalityFn?: (a: Slice, b: Slice) => boolean): Atom<Value extends Promise<unknown> ? Promise<Slice> : Slice>;
declare type Awaited<T> = T extends Promise<infer V> ? V : T;

@@ -1,4 +0,6 @@

import type { Atom } from 'jotai/vanilla';
export declare function unwrap<Value>(anAtom: Atom<Promise<Value>>): Atom<Awaited<Value> | undefined>;
export declare function unwrap<Value, PendingValue>(anAtom: Atom<Promise<Value>>, fallback: (prev?: Value) => PendingValue): Atom<Awaited<Value> | PendingValue>;
import type { Atom, WritableAtom } from 'jotai/vanilla';
export declare function unwrap<Value, Args extends unknown[], Result>(anAtom: WritableAtom<Value, Args, Result>): WritableAtom<Awaited<Value> | undefined, Args, Result>;
export declare function unwrap<Value, Args extends unknown[], Result, PendingValue>(anAtom: WritableAtom<Value, Args, Result>, fallback: (prev?: Awaited<Value>) => PendingValue): WritableAtom<Awaited<Value> | PendingValue, Args, Result>;
export declare function unwrap<Value>(anAtom: Atom<Value>): Atom<Awaited<Value> | undefined>;
export declare function unwrap<Value, PendingValue>(anAtom: Atom<Value>, fallback: (prev?: Awaited<Value>) => PendingValue): Atom<Awaited<Value> | PendingValue>;
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
import { useStore } from 'jotai/react';
import type { WritableAtom } from 'jotai/vanilla';
type Options = Parameters<typeof useStore>[0];
type Options = Parameters<typeof useStore>[0] & {
dangerouslyForceHydrate?: boolean;
};
type AnyWritableAtom = WritableAtom<unknown, any[], any>;

@@ -5,0 +7,0 @@ type AtomMap<A = AnyWritableAtom, V = unknown> = Map<A, V>;

@@ -31,5 +31,5 @@ import type { WritableAtom } from 'jotai/vanilla';

unstable_getOnInit?: boolean;
}): WritableAtom<PromiseLike<Value> | Value, [
SetStateActionWithReset<PromiseLike<Value> | Value>
], PromiseLike<void>>;
}): WritableAtom<Value | Promise<Value>, [
SetStateActionWithReset<Value | Promise<Value>>
], Promise<void>>;
export declare function atomWithStorage<Value>(key: string, initialValue: Value, storage?: SyncStorage<Value>, unstable_options?: {

@@ -36,0 +36,0 @@ unstable_getOnInit?: boolean;

import type { Atom } from 'jotai/vanilla';
export declare function selectAtom<Value, Slice>(anAtom: Atom<Promise<Value>>, selector: (v: Awaited<Value>, prevSlice?: Slice) => Slice, equalityFn?: (a: Slice, b: Slice) => boolean): Atom<Promise<Slice>>;
export declare function selectAtom<Value, Slice>(anAtom: Atom<Value>, selector: (v: Awaited<Value>, prevSlice?: Slice) => Slice, equalityFn?: (a: Slice, b: Slice) => boolean): Atom<Slice>;
export declare function selectAtom<Value, Slice>(anAtom: Atom<Value>, selector: (v: Awaited<Value>, prevSlice?: Slice) => Slice, equalityFn?: (a: Slice, b: Slice) => boolean): Atom<Value extends Promise<unknown> ? Promise<Slice> : Slice>;
declare type Awaited<T> = T extends Promise<infer V> ? V : T;

@@ -1,4 +0,6 @@

import type { Atom } from 'jotai/vanilla';
export declare function unwrap<Value>(anAtom: Atom<Promise<Value>>): Atom<Awaited<Value> | undefined>;
export declare function unwrap<Value, PendingValue>(anAtom: Atom<Promise<Value>>, fallback: (prev?: Value) => PendingValue): Atom<Awaited<Value> | PendingValue>;
import type { Atom, WritableAtom } from 'jotai/vanilla';
export declare function unwrap<Value, Args extends unknown[], Result>(anAtom: WritableAtom<Value, Args, Result>): WritableAtom<Awaited<Value> | undefined, Args, Result>;
export declare function unwrap<Value, Args extends unknown[], Result, PendingValue>(anAtom: WritableAtom<Value, Args, Result>, fallback: (prev?: Awaited<Value>) => PendingValue): WritableAtom<Awaited<Value> | PendingValue, Args, Result>;
export declare function unwrap<Value>(anAtom: Atom<Value>): Atom<Awaited<Value> | undefined>;
export declare function unwrap<Value, PendingValue>(anAtom: Atom<Value>, fallback: (prev?: Awaited<Value>) => PendingValue): Atom<Awaited<Value> | PendingValue>;
declare type Awaited<T> = T extends Promise<infer V> ? V : T;

@@ -79,3 +79,3 @@ (function (global, factory) {

value = _step$value[1];
if (!hydratedSet.has(atom)) {
if (!hydratedSet.has(atom) || options != null && options.dangerouslyForceHydrate) {
hydratedSet.add(atom);

@@ -82,0 +82,0 @@ store.set(atom, value);

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("jotai/react"),require("jotai/vanilla/utils"),require("jotai/vanilla")):"function"==typeof define&&define.amd?define(["exports","react","jotai/react","jotai/vanilla/utils","jotai/vanilla"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).jotaiReactUtils={},t.React,t.jotaiReact,t.jotaiVanillaUtils,t.jotaiVanilla)}(this,(function(t,e,r,n,a){"use strict";function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function i(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return o(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}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 u=new WeakMap;var l=function(t){var e=u.get(t);return e||(e=new WeakSet,u.set(t,e)),e};t.useAtomCallback=function(t,n){var o=e.useMemo((function(){return a.atom(null,(function(e,r){for(var n=arguments.length,a=new Array(n>2?n-2:0),o=2;o<n;o++)a[o-2]=arguments[o];return t.apply(void 0,[e,r].concat(a))}))}),[t]);return r.useSetAtom(o,n)},t.useHydrateAtoms=function(t,e){for(var n,a=r.useStore(e),o=l(a),u=i(t);!(n=u()).done;){var c=n.value,f=c[0],s=c[1];o.has(f)||(o.add(f),a.set(f,s))}},t.useReducerAtom=function(t,n,a){var o=r.useAtom(t,a),i=o[0],u=o[1];return[i,e.useCallback((function(t){u((function(e){return n(e,t)}))}),[u,n])]},t.useResetAtom=function(t,a){var o=r.useSetAtom(t,a);return e.useCallback((function(){return o(n.RESET)}),[o])}}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("jotai/react"),require("jotai/vanilla/utils"),require("jotai/vanilla")):"function"==typeof define&&define.amd?define(["exports","react","jotai/react","jotai/vanilla/utils","jotai/vanilla"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).jotaiReactUtils={},e.React,e.jotaiReact,e.jotaiVanillaUtils,e.jotaiVanilla)}(this,(function(e,t,r,n,a){"use strict";function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function i(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return o(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}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 u=new WeakMap;var l=function(e){var t=u.get(e);return t||(t=new WeakSet,u.set(e,t)),t};e.useAtomCallback=function(e,n){var o=t.useMemo((function(){return a.atom(null,(function(t,r){for(var n=arguments.length,a=new Array(n>2?n-2:0),o=2;o<n;o++)a[o-2]=arguments[o];return e.apply(void 0,[t,r].concat(a))}))}),[e]);return r.useSetAtom(o,n)},e.useHydrateAtoms=function(e,t){for(var n,a=r.useStore(t),o=l(a),u=i(e);!(n=u()).done;){var c=n.value,s=c[0],f=c[1];(!o.has(s)||null!=t&&t.dangerouslyForceHydrate)&&(o.add(s),a.set(s,f))}},e.useReducerAtom=function(e,n,a){var o=r.useAtom(e,a),i=o[0],u=o[1];return[i,t.useCallback((function(e){u((function(t){return n(t,e)}))}),[u,n])]},e.useResetAtom=function(e,a){var o=r.useSetAtom(e,a);return t.useCallback((function(){return o(n.RESET)}),[o])}}));

@@ -437,3 +437,3 @@ (function (global, factory) {

}
if (isPromiseLike(nextValue)) {
if (nextValue instanceof Promise) {
return nextValue.then(function (resolvedValue) {

@@ -652,2 +652,7 @@ set(baseAtom, resolvedValue);

var promise = get(anAtom);
if (!(promise instanceof Promise)) {
return {
v: promise
};
}
if (promise === (prev == null ? void 0 : prev.p)) {

@@ -696,3 +701,3 @@ if (promiseErrorCache.has(promise)) {

return state.f;
});
}, anAtom.write);
}, anAtom, fallback);

@@ -699,0 +704,0 @@ }

@@ -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};var m=function(t){return"function"==typeof(null==t?void 0:t.then)};function d(t){var n,e,r={getItem:function(r,o){var i,a,u=function(t){if(n!==(t=t||"")){try{e=JSON.parse(t)}catch(t){return o}n=t}return e},f=null!=(i=null==(a=t())?void 0:a.getItem(r))?i:null;return m(f)?f.then(u):u(f)},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&&(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 b=d((function(){return"undefined"!=typeof window?window.localStorage:void 0}));var p=new WeakMap,y={state:"loading"};var h=function(t,n,e){return(n.has(e)?n:n.set(e,t())).get(e)},w=new WeakMap,g=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=b);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)):m(f)?f.then((function(n){return i(u,n),o.setItem(t,n)})):(i(u,f),o.setItem(t,f))}))},t.createJSONStorage=d,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(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=o.setSelf;n(r);var a=n(t);if(!(a instanceof Promise))return{state:"hasData",data:a};var u=e.get(a);return u||(e.set(a,y),a.then((function(t){e.set(a,{state:"hasData",data:t})}),(function(t){e.set(a,{state:"hasError",error:t})})).finally(i),y)}),(function(t,n){n(r,(function(t){return t+1}))}));return n.atom((function(t){return t(o)}))},r=t,(p.has(r)?p:p.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;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.unstable_unwrap=function(t,e){return void 0===e&&(e=g),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===(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}))},o=e,i=h((function(){return new WeakMap}),w,t),h(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&&(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(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=o.setSelf;n(r);var a=n(t);if(!(a instanceof Promise))return{state:"hasData",data:a};var u=e.get(a);return u||(e.set(a,p),a.then((function(t){e.set(a,{state:"hasData",data:t})}),(function(t){e.set(a,{state:"hasError",error:t})})).finally(i),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;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.unstable_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}),t.write)},o=e,i=y((function(){return new WeakMap}),h,t),y(r,i,o);var r,o,i}}));

@@ -435,3 +435,3 @@ 'use strict';

}
if (isPromiseLike(nextValue)) {
if (nextValue instanceof Promise) {
return nextValue.then(function (resolvedValue) {

@@ -650,2 +650,7 @@ set(baseAtom, resolvedValue);

var promise = get(anAtom);
if (!(promise instanceof Promise)) {
return {
v: promise
};
}
if (promise === (prev == null ? void 0 : prev.p)) {

@@ -694,3 +699,3 @@ if (promiseErrorCache.has(promise)) {

return state.f;
});
}, anAtom.write);
}, anAtom, fallback);

@@ -697,0 +702,0 @@ }

@@ -31,5 +31,5 @@ import type { WritableAtom } from 'jotai/vanilla';

unstable_getOnInit?: boolean;
}): WritableAtom<PromiseLike<Value> | Value, [
SetStateActionWithReset<PromiseLike<Value> | Value>
], PromiseLike<void>>;
}): WritableAtom<Value | Promise<Value>, [
SetStateActionWithReset<Value | Promise<Value>>
], Promise<void>>;
export declare function atomWithStorage<Value>(key: string, initialValue: Value, storage?: SyncStorage<Value>, unstable_options?: {

@@ -36,0 +36,0 @@ unstable_getOnInit?: boolean;

import type { Atom } from 'jotai/vanilla';
export declare function selectAtom<Value, Slice>(anAtom: Atom<Promise<Value>>, selector: (v: Awaited<Value>, prevSlice?: Slice) => Slice, equalityFn?: (a: Slice, b: Slice) => boolean): Atom<Promise<Slice>>;
export declare function selectAtom<Value, Slice>(anAtom: Atom<Value>, selector: (v: Awaited<Value>, prevSlice?: Slice) => Slice, equalityFn?: (a: Slice, b: Slice) => boolean): Atom<Slice>;
export declare function selectAtom<Value, Slice>(anAtom: Atom<Value>, selector: (v: Awaited<Value>, prevSlice?: Slice) => Slice, equalityFn?: (a: Slice, b: Slice) => boolean): Atom<Value extends Promise<unknown> ? Promise<Slice> : Slice>;

@@ -1,3 +0,5 @@

import type { Atom } from 'jotai/vanilla';
export declare function unwrap<Value>(anAtom: Atom<Promise<Value>>): Atom<Awaited<Value> | undefined>;
export declare function unwrap<Value, PendingValue>(anAtom: Atom<Promise<Value>>, fallback: (prev?: Value) => PendingValue): Atom<Awaited<Value> | PendingValue>;
import type { Atom, WritableAtom } from 'jotai/vanilla';
export declare function unwrap<Value, Args extends unknown[], Result>(anAtom: WritableAtom<Value, Args, Result>): WritableAtom<Awaited<Value> | undefined, Args, Result>;
export declare function unwrap<Value, Args extends unknown[], Result, PendingValue>(anAtom: WritableAtom<Value, Args, Result>, fallback: (prev?: Awaited<Value>) => PendingValue): WritableAtom<Awaited<Value> | PendingValue, Args, Result>;
export declare function unwrap<Value>(anAtom: Atom<Value>): Atom<Awaited<Value> | undefined>;
export declare function unwrap<Value, PendingValue>(anAtom: Atom<Value>, fallback: (prev?: Awaited<Value>) => PendingValue): Atom<Awaited<Value> | PendingValue>;

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc