Comparing version 2.3.1 to 2.4.0
{ | ||
"name": "jotai", | ||
"private": false, | ||
"version": "2.3.1", | ||
"version": "2.4.0", | ||
"description": "👻 Primitive and flexible state management for React", | ||
@@ -6,0 +6,0 @@ "main": "./index.js", |
@@ -148,3 +148,3 @@ System.register([], (function (exports) { | ||
resolve(v); | ||
if ((prevAtomState == null ? void 0 : prevAtomState.d) !== nextAtomState.d) { | ||
if (mountedMap.has(atom) && (prevAtomState == null ? void 0 : prevAtomState.d) !== nextAtomState.d) { | ||
mountDependencies(atom, nextAtomState, prevAtomState == null ? void 0 : prevAtomState.d); | ||
@@ -165,3 +165,3 @@ } | ||
reject(e); | ||
if ((prevAtomState == null ? void 0 : prevAtomState.d) !== nextAtomState.d) { | ||
if (mountedMap.has(atom) && (prevAtomState == null ? void 0 : prevAtomState.d) !== nextAtomState.d) { | ||
mountDependencies(atom, nextAtomState, prevAtomState == null ? void 0 : prevAtomState.d); | ||
@@ -296,3 +296,6 @@ } | ||
}; | ||
const recomputeDependents = (atom) => { | ||
const recomputeDependents = (updatedAtoms) => { | ||
if (!updatedAtoms.size) { | ||
return; | ||
} | ||
const dependencyMap = /* @__PURE__ */ new Map(); | ||
@@ -313,3 +316,3 @@ const dirtyMap = /* @__PURE__ */ new WeakMap(); | ||
}; | ||
loop1(atom); | ||
updatedAtoms.forEach(loop1); | ||
const loop2 = (a) => { | ||
@@ -339,5 +342,6 @@ const mounted = mountedMap.get(a); | ||
}; | ||
loop2(atom); | ||
updatedAtoms.forEach(loop2); | ||
updatedAtoms.clear(); | ||
}; | ||
const writeAtomState = (atom, ...args) => { | ||
const writeAtomState = (updatedAtoms, atom, ...args) => { | ||
let isSync = true; | ||
@@ -354,8 +358,9 @@ const getter = (a) => returnAtomValue(readAtomState(a)); | ||
if (!prevAtomState || !isEqualAtomValue(prevAtomState, nextAtomState)) { | ||
recomputeDependents(a); | ||
updatedAtoms.add(a); | ||
} | ||
} else { | ||
r = writeAtomState(a, ...args2); | ||
r = writeAtomState(updatedAtoms, a, ...args2); | ||
} | ||
if (!isSync) { | ||
recomputeDependents(updatedAtoms); | ||
const flushed = flushPending(); | ||
@@ -375,3 +380,5 @@ { | ||
const writeAtom = (atom, ...args) => { | ||
const result = writeAtomState(atom, ...args); | ||
const updatedAtoms = /* @__PURE__ */ new Set(); | ||
const result = writeAtomState(updatedAtoms, atom, ...args); | ||
recomputeDependents(updatedAtoms); | ||
const flushed = flushPending(); | ||
@@ -479,6 +486,6 @@ { | ||
if (atomState) { | ||
if (atomState.d !== (prevAtomState == null ? void 0 : prevAtomState.d)) { | ||
const mounted = mountedMap.get(atom); | ||
if (mounted && atomState.d !== (prevAtomState == null ? void 0 : prevAtomState.d)) { | ||
mountDependencies(atom, atomState, prevAtomState == null ? void 0 : prevAtomState.d); | ||
} | ||
const mounted = mountedMap.get(atom); | ||
if (mounted && !// TODO This seems pretty hacky. Hope to fix it. | ||
@@ -538,8 +545,10 @@ // Maybe we could `mountDependencies` in `setAtomState`? | ||
dev_restore_atoms: (values) => { | ||
const updatedAtoms = /* @__PURE__ */ new Set(); | ||
for (const [atom, valueOrPromise] of values) { | ||
if (hasInitialValue(atom)) { | ||
setAtomValueOrPromise(atom, valueOrPromise); | ||
recomputeDependents(atom); | ||
updatedAtoms.add(atom); | ||
} | ||
} | ||
recomputeDependents(updatedAtoms); | ||
const flushed = flushPending(); | ||
@@ -546,0 +555,0 @@ storeListenersRev2.forEach( |
@@ -1,1 +0,1 @@ | ||
System.register([],function(b){"use strict";return{execute:function(){b("atom",N);let L=0;function N(i,l){const w=`atom${++L}`,d={toString:()=>w};return typeof i=="function"?d.read=i:(d.init=i,d.read=m=>m(d),d.write=(m,z,h)=>z(d,typeof h=="function"?h(m(d)):h)),l&&(d.write=l),d}const C=i=>"init"in i,q=i=>!!i.write,E=new WeakMap,R=(i,l)=>{E.set(i,l),i.catch(()=>{}).finally(()=>E.delete(i))},B=(i,l)=>{const w=E.get(i);w&&(E.delete(i),w(l))},F=(i,l)=>{i.status="fulfilled",i.value=l},G=(i,l)=>{i.status="rejected",i.reason=l},T=i=>typeof(i==null?void 0:i.then)=="function",M=(i,l)=>"v"in i&&"v"in l&&Object.is(i.v,l.v),H=(i,l)=>"e"in i&&"e"in l&&Object.is(i.e,l.e),y=i=>"v"in i&&i.v instanceof Promise,U=(i,l)=>"v"in i&&"v"in l&&i.v.orig&&i.v.orig===l.v.orig,S=i=>{if("e"in i)throw i.e;return i.v},V=b("createStore",()=>{const i=new WeakMap,l=new WeakMap,w=new Map,d=t=>i.get(t),m=(t,n)=>{const r=i.get(t);if(i.set(t,n),w.has(t)||w.set(t,r),r&&y(r)){const e="v"in n?n.v instanceof Promise?n.v:Promise.resolve(n.v):Promise.reject(n.e);B(r.v,e)}},z=(t,n,r)=>{const e=new Map;let s=!1;r.forEach((o,c)=>{!o&&c===t&&(o=n),o&&(e.set(c,o),n.d.get(c)!==o&&(s=!0))}),(s||n.d.size!==e.size)&&(n.d=e)},h=(t,n,r)=>{const e=d(t),s={d:(e==null?void 0:e.d)||new Map,v:n};if(r&&z(t,s,r),e&&M(e,s)&&e.d===s.d)return e;if(e&&y(e)&&y(s)&&U(e,s)){if(e.d===s.d)return e;s.v=e.v}return m(t,s),s},I=(t,n,r,e)=>{if(T(n)){let s;const o=new Promise((c,f)=>{let v=!1;n.then(a=>{if(!v){v=!0;const u=d(t),g=h(t,o,r);F(o,a),c(a),(u==null?void 0:u.d)!==g.d&&D(t,g,u==null?void 0:u.d)}},a=>{if(!v){v=!0;const u=d(t),g=h(t,o,r);G(o,a),f(a),(u==null?void 0:u.d)!==g.d&&D(t,g,u==null?void 0:u.d)}}),s=a=>{v||(v=!0,a.then(u=>F(o,u),u=>G(o,u)),c(a))}});return o.orig=n,o.status="pending",R(o,c=>{c&&s(c),e==null||e()}),h(t,o,r)}return h(t,n,r)},_=(t,n,r)=>{const e=d(t),s={d:(e==null?void 0:e.d)||new Map,e:n};return r&&z(t,s,r),e&&H(e,s)&&e.d===s.d?e:(m(t,s),s)},p=(t,n)=>{const r=d(t);if(!n&&r&&(l.has(t)||Array.from(r.d).every(([a,u])=>a===t||p(a)===u)))return r;const e=new Map;let s=!0;const o=a=>{if(a===t){const g=d(a);if(g)return e.set(a,g),S(g);if(C(a))return e.set(a,void 0),a.init;throw new Error("no atom init")}const u=p(a);return e.set(a,u),S(u)};let c,f;const v={get signal(){return c||(c=new AbortController),c.signal},get setSelf(){return!f&&q(t)&&(f=(...a)=>{if(!s)return P(t,...a)}),f}};try{const a=t.read(o,v);return I(t,a,e,()=>c==null?void 0:c.abort())}catch(a){return _(t,a,e)}finally{s=!1}},$=t=>S(p(t)),x=t=>{let n=l.get(t);return n||(n=j(t)),n},k=(t,n)=>!n.l.size&&(!n.t.size||n.t.size===1&&n.t.has(t)),K=t=>{const n=l.get(t);n&&k(t,n)&&W(t)},Q=t=>{const n=new Map,r=new WeakMap,e=o=>{const c=l.get(o);c==null||c.t.forEach(f=>{f!==o&&(n.set(f,(n.get(f)||new Set).add(o)),r.set(f,(r.get(f)||0)+1),e(f))})};e(t);const s=o=>{const c=l.get(o);c==null||c.t.forEach(f=>{var v;if(f!==o){let a=r.get(f);if(a&&r.set(f,--a),!a){let u=!!((v=n.get(f))!=null&&v.size);if(u){const g=d(f),X=p(f,!0);u=!g||!M(g,X)}u||n.forEach(g=>g.delete(f))}s(f)}})};s(t)},J=(t,...n)=>{let r=!0;const e=c=>S(p(c)),s=(c,...f)=>{let v;if(c===t){if(!C(c))throw new Error("atom not writable");const a=d(c),u=I(c,f[0]);(!a||!M(a,u))&&Q(c)}else v=J(c,...f);return r||O(),v},o=t.write(e,s,...n);return r=!1,o},P=(t,...n)=>{const r=J(t,...n);return O(),r},j=(t,n)=>{var r;(r=d(t))==null||r.d.forEach((s,o)=>{const c=l.get(o);c?c.t.add(t):o!==t&&j(o,t)}),p(t);const e={t:new Set(n&&[n]),l:new Set};if(l.set(t,e),q(t)&&t.onMount){const s=t.onMount((...o)=>P(t,...o));s&&(e.u=s)}return e},W=t=>{var n;const r=(n=l.get(t))==null?void 0:n.u;r&&r(),l.delete(t);const e=d(t);e&&(y(e)&&B(e.v),e.d.forEach((s,o)=>{if(o!==t){const c=l.get(o);c&&(c.t.delete(t),k(o,c)&&W(o))}}))},D=(t,n,r)=>{const e=new Set(n.d.keys());r==null||r.forEach((s,o)=>{if(e.has(o)){e.delete(o);return}const c=l.get(o);c&&(c.t.delete(t),k(o,c)&&W(o))}),e.forEach(s=>{const o=l.get(s);o?o.t.add(t):l.has(t)&&j(s,t)})},O=()=>{for(;w.size;){const t=Array.from(w);w.clear(),t.forEach(([n,r])=>{const e=d(n);if(e){e.d!==(r==null?void 0:r.d)&&D(n,e,r==null?void 0:r.d);const s=l.get(n);s&&!(r&&!y(r)&&(M(r,e)||H(r,e)))&&s.l.forEach(o=>o())}})}};return{get:$,set:P,sub:(t,n)=>{const r=x(t);O();const e=r.l;return e.add(n),()=>{e.delete(n),K(t)}}}});let A;const Y=b("getDefaultStore",()=>(A||(A=V()),A))}}}); | ||
System.register([],function(A){"use strict";return{execute:function(){A("atom",R);let N=0;function R(s,l){const h=`atom${++N}`,f={toString:()=>h};return typeof s=="function"?f.read=s:(f.init=s,f.read=E=>E(f),f.write=(E,z,w)=>z(f,typeof w=="function"?w(E(f)):w)),l&&(f.write=l),f}const C=s=>"init"in s,q=s=>!!s.write,y=new WeakMap,T=(s,l)=>{y.set(s,l),s.catch(()=>{}).finally(()=>y.delete(s))},B=(s,l)=>{const h=y.get(s);h&&(y.delete(s),h(l))},F=(s,l)=>{s.status="fulfilled",s.value=l},G=(s,l)=>{s.status="rejected",s.reason=l},U=s=>typeof(s==null?void 0:s.then)=="function",M=(s,l)=>"v"in s&&"v"in l&&Object.is(s.v,l.v),H=(s,l)=>"e"in s&&"e"in l&&Object.is(s.e,l.e),p=s=>"v"in s&&s.v instanceof Promise,V=(s,l)=>"v"in s&&"v"in l&&s.v.orig&&s.v.orig===l.v.orig,S=s=>{if("e"in s)throw s.e;return s.v},_=A("createStore",()=>{const s=new WeakMap,l=new WeakMap,h=new Map,f=t=>s.get(t),E=(t,n)=>{const r=s.get(t);if(s.set(t,n),h.has(t)||h.set(t,r),r&&p(r)){const e="v"in n?n.v instanceof Promise?n.v:Promise.resolve(n.v):Promise.reject(n.e);B(r.v,e)}},z=(t,n,r)=>{const e=new Map;let i=!1;r.forEach((o,d)=>{!o&&d===t&&(o=n),o&&(e.set(d,o),n.d.get(d)!==o&&(i=!0))}),(i||n.d.size!==e.size)&&(n.d=e)},w=(t,n,r)=>{const e=f(t),i={d:(e==null?void 0:e.d)||new Map,v:n};if(r&&z(t,i,r),e&&M(e,i)&&e.d===i.d)return e;if(e&&p(e)&&p(i)&&V(e,i)){if(e.d===i.d)return e;i.v=e.v}return E(t,i),i},I=(t,n,r,e)=>{if(U(n)){let i;const o=new Promise((d,a)=>{let g=!1;n.then(u=>{if(!g){g=!0;const c=f(t),v=w(t,o,r);F(o,u),d(u),l.has(t)&&(c==null?void 0:c.d)!==v.d&&D(t,v,c==null?void 0:c.d)}},u=>{if(!g){g=!0;const c=f(t),v=w(t,o,r);G(o,u),a(u),l.has(t)&&(c==null?void 0:c.d)!==v.d&&D(t,v,c==null?void 0:c.d)}}),i=u=>{g||(g=!0,u.then(c=>F(o,c),c=>G(o,c)),d(u))}});return o.orig=n,o.status="pending",T(o,d=>{d&&i(d),e==null||e()}),w(t,o,r)}return w(t,n,r)},$=(t,n,r)=>{const e=f(t),i={d:(e==null?void 0:e.d)||new Map,e:n};return r&&z(t,i,r),e&&H(e,i)&&e.d===i.d?e:(E(t,i),i)},m=(t,n)=>{const r=f(t);if(!n&&r&&(l.has(t)||Array.from(r.d).every(([u,c])=>u===t||m(u)===c)))return r;const e=new Map;let i=!0;const o=u=>{if(u===t){const v=f(u);if(v)return e.set(u,v),S(v);if(C(u))return e.set(u,void 0),u.init;throw new Error("no atom init")}const c=m(u);return e.set(u,c),S(c)};let d,a;const g={get signal(){return d||(d=new AbortController),d.signal},get setSelf(){return!a&&q(t)&&(a=(...u)=>{if(!i)return P(t,...u)}),a}};try{const u=t.read(o,g);return I(t,u,e,()=>d==null?void 0:d.abort())}catch(u){return $(t,u,e)}finally{i=!1}},x=t=>S(m(t)),K=t=>{let n=l.get(t);return n||(n=j(t)),n},k=(t,n)=>!n.l.size&&(!n.t.size||n.t.size===1&&n.t.has(t)),Q=t=>{const n=l.get(t);n&&k(t,n)&&W(t)},J=t=>{if(!t.size)return;const n=new Map,r=new WeakMap,e=o=>{const d=l.get(o);d==null||d.t.forEach(a=>{a!==o&&(n.set(a,(n.get(a)||new Set).add(o)),r.set(a,(r.get(a)||0)+1),e(a))})};t.forEach(e);const i=o=>{const d=l.get(o);d==null||d.t.forEach(a=>{var g;if(a!==o){let u=r.get(a);if(u&&r.set(a,--u),!u){let c=!!((g=n.get(a))!=null&&g.size);if(c){const v=f(a),X=m(a,!0);c=!v||!M(v,X)}c||n.forEach(v=>v.delete(a))}i(a)}})};t.forEach(i),t.clear()},L=(t,n,...r)=>{let e=!0;const i=a=>S(m(a)),o=(a,...g)=>{let u;if(a===n){if(!C(a))throw new Error("atom not writable");const c=f(a),v=I(a,g[0]);(!c||!M(c,v))&&t.add(a)}else u=L(t,a,...g);return e||(J(t),O()),u},d=n.write(i,o,...r);return e=!1,d},P=(t,...n)=>{const r=new Set,e=L(r,t,...n);return J(r),O(),e},j=(t,n)=>{var r;(r=f(t))==null||r.d.forEach((i,o)=>{const d=l.get(o);d?d.t.add(t):o!==t&&j(o,t)}),m(t);const e={t:new Set(n&&[n]),l:new Set};if(l.set(t,e),q(t)&&t.onMount){const i=t.onMount((...o)=>P(t,...o));i&&(e.u=i)}return e},W=t=>{var n;const r=(n=l.get(t))==null?void 0:n.u;r&&r(),l.delete(t);const e=f(t);e&&(p(e)&&B(e.v),e.d.forEach((i,o)=>{if(o!==t){const d=l.get(o);d&&(d.t.delete(t),k(o,d)&&W(o))}}))},D=(t,n,r)=>{const e=new Set(n.d.keys());r==null||r.forEach((i,o)=>{if(e.has(o)){e.delete(o);return}const d=l.get(o);d&&(d.t.delete(t),k(o,d)&&W(o))}),e.forEach(i=>{const o=l.get(i);o?o.t.add(t):l.has(t)&&j(i,t)})},O=()=>{for(;h.size;){const t=Array.from(h);h.clear(),t.forEach(([n,r])=>{const e=f(n);if(e){const i=l.get(n);i&&e.d!==(r==null?void 0:r.d)&&D(n,e,r==null?void 0:r.d),i&&!(r&&!p(r)&&(M(r,e)||H(r,e)))&&i.l.forEach(o=>o())}})}};return{get:x,set:P,sub:(t,n)=>{const r=K(t);O();const e=r.l;return e.add(n),()=>{e.delete(n),Q(t)}}}});let b;const Y=A("getDefaultStore",()=>(b||(b=_()),b))}}}); |
@@ -216,7 +216,9 @@ System.register(['jotai/vanilla'], (function (exports) { | ||
const nextItem = isFunction(update) ? update(arr2[index2]) : update; | ||
set(arrAtom, [ | ||
...arr2.slice(0, index2), | ||
nextItem, | ||
...arr2.slice(index2 + 1) | ||
]); | ||
if (!Object.is(arr2[index2], nextItem)) { | ||
set(arrAtom, [ | ||
...arr2.slice(0, index2), | ||
nextItem, | ||
...arr2.slice(index2 + 1) | ||
]); | ||
} | ||
}; | ||
@@ -223,0 +225,0 @@ atomList[index] = isWritable(arrAtom) ? atom(read, write) : atom(read); |
@@ -1,1 +0,1 @@ | ||
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,unwrap:it});const S=P("RESET",Symbol());function T(e){const n=f(e,(o,u,i)=>{const r=typeof i=="function"?i(o(n)):i;u(n,r===S?e:r)});return n}function V(e,n){const o=f(e,(u,i,r)=>i(o,n(u(o),r)));return o}function z(e,n){let o=null;const u=new Map,i=r=>{let t;if(n===void 0)t=u.get(r);else for(const[c,s]of u)if(n(c,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 u.set(r,[a,Date.now()]),a};return i.remove=r=>{if(n===void 0)u.delete(r);else for(const[t]of u)if(n(t,r)){u.delete(t);break}},i.setShouldRemove=r=>{if(o=r,!!o)for(const[t,a]of u)o(a[1],t)&&u.delete(t)},i}const L=(e,n,o)=>(n.has(o)?n:n.set(o,e())).get(o),J=new WeakMap,$=(e,n,o,u)=>{const i=L(()=>new WeakMap,J,n),r=L(()=>new WeakMap,i,o);return L(e,r,u)};function _(e,n,o=Object.is){return $(()=>{const u=Symbol(),i=([t,a])=>{if(a===u)return n(t);const c=n(t,a);return o(a,c)?a:c},r=f(t=>{const a=t(r),c=t(e);return c instanceof Promise||a instanceof Promise?Promise.all([c,a]).then(i):i([c,a])});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=(i,r)=>x(u(i,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,a)=>{let c=o.get(t);if(c)return c;const s=a&&o.get(a),l=[],m=[];return t.forEach((h,b)=>{const v=n?n(h):b;m[b]=v;const g=s&&s.atomList[s.keyList.indexOf(v)];if(g){l[b]=g;return}const W=w=>{const d=w(i),y=w(e),k=u(y,d==null?void 0:d.arr).keyList.indexOf(v);if(k<0||k>=y.length){const p=t[u(t).keyList.indexOf(v)];if(p)return p;throw new Error("splitAtom: index out of bounds for read")}return y[k]},O=(w,d,y)=>{const k=w(i),p=w(e),M=u(p,k==null?void 0:k.arr).keyList.indexOf(v);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[b]=R(e)?f(W,O):f(W)}),s&&s.keyList.length===m.length&&s.keyList.every((h,b)=>h===m[b])?c=s:c={arr:t,atomList:l,keyList:m},o.set(t,c),c},i=f(t=>{const a=t(i),c=t(e);return u(c,a==null?void 0:a.arr)});i.init=void 0;const r=R(e)?f(t=>t(i).atomList,(t,a,c)=>{switch(c.type){case"remove":{const s=t(r).indexOf(c.atom);if(s>=0){const l=t(e);a(e,[...l.slice(0,s),...l.slice(s+1)])}break}case"insert":{const s=c.before?t(r).indexOf(c.before):t(r).length;if(s>=0){const l=t(e);a(e,[...l.slice(0,s),c.value,...l.slice(s)])}break}case"move":{const s=t(r).indexOf(c.atom),l=c.before?t(r).indexOf(c.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||G)}function U(e){const n=Symbol(),o=f(n),u=f((i,r)=>{const t=i(o);return t!==n?t:e(i,r)},(i,r,t)=>{if(t===S)r(o,n);else if(typeof t=="function"){const a=i(u);r(o,t(a))}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:(i,r)=>{var t,a;const c=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 X(s)?s.then(c):c(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"&&(u.subscribe=(i,r,t)=>{if(!(e()instanceof window.Storage))return()=>{};const a=c=>{if(c.storageArea===e()&&c.key===i){let s;try{s=JSON.parse(c.newValue||"")}catch{s=t}r(s)}};return window.addEventListener("storage",a),()=>{window.removeEventListener("storage",a)}}),u}const Y=j(()=>typeof window<"u"?window.localStorage:void 0);function Z(e,n,o=Y,u){const i=u==null?void 0:u.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,c)=>{const s=typeof c=="function"?c(t(r)):c;return s===S?(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 tt(e,n){const o=i=>{if("e"in i)throw i.e;return i.d},u=f(i=>{var r;let t=e(i);const a=(r=t[Symbol.observable])==null?void 0:r.call(t);a&&(t=a);let c;const s=()=>new Promise(d=>{c=d}),l=n&&"initialValue"in n?{d:typeof n.initialValue=="function"?n.initialValue():n.initialValue}:s();let m,h;const b=d=>{h=d,c==null||c(d),m==null||m(d)};let v,g;const W=()=>!m,O=()=>{v&&(clearTimeout(g),v.unsubscribe()),v=t.subscribe({next:d=>b({d}),error:d=>b({e:d}),complete:()=>{}}),W()&&n!=null&&n.unstable_timeout&&(g=setTimeout(()=>{v&&(v.unsubscribe(),v=void 0)},n.unstable_timeout))};O();const w=f(h||l);return w.onMount=d=>(m=d,h&&d(h),v?clearTimeout(g):O(),()=>{m=void 0,v&&(v.unsubscribe(),v=void 0)}),[w,t,s,O,W]});return f(i=>{const[r]=i(u),t=i(r);return t instanceof Promise?t.then(o):o(t)},(i,r,t)=>{const[a,c,s,l,m]=i(u);if("next"in c)m()&&(r(a,s()),l()),c.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((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,D),a.then(s=>{n.set(a,{state:"hasData",data:s})},s=>{n.set(a,{state:"hasError",error:s})}).finally(r),D)},(i,r)=>{r(o,t=>t+1)});return f(i=>i(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,i=f(0),r=f((t,{setSelf:a})=>{t(i);const c=t(r),s=t(e);if(!(s instanceof Promise))return{v:s};if(s===(c==null?void 0:c.p)){if(o.has(s))throw o.get(s);if(u.has(s))return{p:s,v:u.get(s)}}return s!==(c==null?void 0:c.p)&&s.then(l=>u.set(s,l),l=>o.set(s,l)).finally(a),c&&"v"in c?{p:s,f:n(c.v)}:{p:s,f:n()}},(t,a)=>{a(i,c=>c+1)});return r.init=void 0,f(t=>{const a=t(r);return"v"in a?a.v:a.f},e.write)},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:V,atomWithStorage:tt,createJSONStorage:R,freezeAtom:K,freezeAtomCreator:q,loadable:ot,selectAtom:C,splitAtom:U,unwrap:at});const W=P("RESET",Symbol());function V(e){const n=f(e,(o,u,i)=>{const r=typeof i=="function"?i(o(n)):i;u(n,r===W?e:r)});return n}function z(e,n){const o=f(e,(u,i,r)=>i(o,n(u(o),r)));return o}function J(e,n){let o=null;const u=new Map,i=r=>{let t;if(n===void 0)t=u.get(r);else for(const[c,s]of u)if(n(c,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 u.set(r,[a,Date.now()]),a};return i.remove=r=>{if(n===void 0)u.delete(r);else for(const[t]of u)if(n(t,r)){u.delete(t);break}},i.setShouldRemove=r=>{if(o=r,!!o)for(const[t,a]of u)o(a[1],t)&&u.delete(t)},i}const L=(e,n,o)=>(n.has(o)?n:n.set(o,e())).get(o),$=new WeakMap,_=(e,n,o,u)=>{const i=L(()=>new WeakMap,$,n),r=L(()=>new WeakMap,i,o);return L(e,r,u)};function C(e,n,o=Object.is){return _(()=>{const u=Symbol(),i=([t,a])=>{if(a===u)return n(t);const c=n(t,a);return o(a,c)?a:c},r=f(t=>{const a=t(r),c=t(e);return c instanceof Promise||a instanceof Promise?Promise.all([c,a]).then(i):i([c,a])});return r.init=u,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 u=e[o];x(u)}return e};function K(e){return F(()=>f(n=>x(n(e)),(n,o,u)=>o(e,u)),e)}function q(e){return(...n)=>{const o=e(...n),u=o.read;return o.read=(i,r)=>x(u(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 u=A(()=>new WeakMap,B,n);return A(e,u,o)},H={},j=e=>!!e.write,Q=e=>typeof e=="function";function U(e,n){return G(()=>{const o=new WeakMap,u=(t,a)=>{let c=o.get(t);if(c)return c;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=u(g,d==null?void 0:d.arr).keyList.indexOf(b);if(k<0||k>=g.length){const h=t[u(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=u(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 T=Q(g)?g(h[S]):g;Object.is(h[S],T)||d(e,[...h.slice(0,S),T,...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])?c=s:c={arr:t,atomList:l,keyList:m},o.set(t,c),c},i=f(t=>{const a=t(i),c=t(e);return u(c,a==null?void 0:a.arr)});i.init=void 0;const r=j(e)?f(t=>t(i).atomList,(t,a,c)=>{switch(c.type){case"remove":{const s=t(r).indexOf(c.atom);if(s>=0){const l=t(e);a(e,[...l.slice(0,s),...l.slice(s+1)])}break}case"insert":{const s=c.before?t(r).indexOf(c.before):t(r).length;if(s>=0){const l=t(e);a(e,[...l.slice(0,s),c.value,...l.slice(s)])}break}case"move":{const s=t(r).indexOf(c.atom),l=c.before?t(r).indexOf(c.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),u=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(u);r(o,t(a))}else r(o,t)});return u}const Y=e=>typeof(e==null?void 0:e.then)=="function";function R(e){let n,o;const u={getItem:(i,r)=>{var t,a;const c=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(c):c(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"&&(u.subscribe=(i,r,t)=>{if(!(e()instanceof window.Storage))return()=>{};const a=c=>{if(c.storageArea===e()&&c.key===i){let s;try{s=JSON.parse(c.newValue||"")}catch{s=t}r(s)}};return window.addEventListener("storage",a),()=>{window.removeEventListener("storage",a)}}),u}const Z=R(()=>typeof window<"u"?window.localStorage:void 0);function tt(e,n,o=Z,u){const i=u==null?void 0:u.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,c)=>{const s=typeof c=="function"?c(t(r)):c;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},u=f(i=>{var r;let t=e(i);const a=(r=t[Symbol.observable])==null?void 0:r.call(t);a&&(t=a);let c;const s=()=>new Promise(d=>{c=d}),l=n&&"initialValue"in n?{d:typeof n.initialValue=="function"?n.initialValue():n.initialValue}:s();let m,w;const v=d=>{w=d,c==null||c(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(u),t=i(r);return t instanceof Promise?t.then(o):o(t)},(i,r,t)=>{const[a,c,s,l,m]=i(u);if("next"in c)m()&&(r(a,s()),l()),c.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),D={state:"loading"};function ot(e){return nt(()=>{const n=new WeakMap,o=f(0),u=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,D),a.then(s=>{n.set(a,{state:"hasData",data:s})},s=>{n.set(a,{state:"hasError",error:s})}).finally(r),D)},(i,r)=>{r(o,t=>t+1)});return f(i=>i(u))},e)}const N=(e,n,o)=>(n.has(o)?n:n.set(o,e())).get(o),rt=new WeakMap,st=(e,n,o)=>{const u=N(()=>new WeakMap,rt,n);return N(e,u,o)},it=()=>{};function at(e,n=it){return st(()=>{const o=new WeakMap,u=new WeakMap,i=f(0),r=f((t,{setSelf:a})=>{t(i);const c=t(r),s=t(e);if(!(s instanceof Promise))return{v:s};if(s===(c==null?void 0:c.p)){if(o.has(s))throw o.get(s);if(u.has(s))return{p:s,v:u.get(s)}}return s!==(c==null?void 0:c.p)&&s.then(l=>u.set(s,l),l=>o.set(s,l)).finally(a),c&&"v"in c?{p:s,f:n(c.v)}:{p:s,f:n()}},(t,a)=>{a(i,c=>c+1)});return r.init=void 0,f(t=>{const a=t(r);return"v"in a?a.v:a.f},e.write)},e,n)}}}}); |
@@ -194,3 +194,3 @@ (function (global, factory) { | ||
resolve(v); | ||
if ((prevAtomState == null ? void 0 : prevAtomState.d) !== nextAtomState.d) { | ||
if (mountedMap.has(atom) && (prevAtomState == null ? void 0 : prevAtomState.d) !== nextAtomState.d) { | ||
mountDependencies(atom, nextAtomState, prevAtomState == null ? void 0 : prevAtomState.d); | ||
@@ -206,3 +206,3 @@ } | ||
reject(e); | ||
if ((prevAtomState == null ? void 0 : prevAtomState.d) !== nextAtomState.d) { | ||
if (mountedMap.has(atom) && (prevAtomState == null ? void 0 : prevAtomState.d) !== nextAtomState.d) { | ||
mountDependencies(atom, nextAtomState, prevAtomState == null ? void 0 : prevAtomState.d); | ||
@@ -344,3 +344,6 @@ } | ||
}; | ||
var recomputeDependents = function recomputeDependents(atom) { | ||
var recomputeDependents = function recomputeDependents(updatedAtoms) { | ||
if (!updatedAtoms.size) { | ||
return; | ||
} | ||
var dependencyMap = new Map(); | ||
@@ -358,3 +361,3 @@ var dirtyMap = new WeakMap(); | ||
}; | ||
loop1(atom); | ||
updatedAtoms.forEach(loop1); | ||
var loop2 = function loop2(a) { | ||
@@ -386,5 +389,6 @@ var mounted = mountedMap.get(a); | ||
}; | ||
loop2(atom); | ||
updatedAtoms.forEach(loop2); | ||
updatedAtoms.clear(); | ||
}; | ||
var writeAtomState = function writeAtomState(atom) { | ||
var writeAtomState = function writeAtomState(updatedAtoms, atom) { | ||
var isSync = true; | ||
@@ -406,8 +410,9 @@ var getter = function getter(a) { | ||
if (!prevAtomState || !isEqualAtomValue(prevAtomState, nextAtomState)) { | ||
recomputeDependents(a); | ||
updatedAtoms.add(a); | ||
} | ||
} else { | ||
r = writeAtomState.apply(void 0, [a].concat(args)); | ||
r = writeAtomState.apply(void 0, [updatedAtoms, a].concat(args)); | ||
} | ||
if (!isSync) { | ||
recomputeDependents(updatedAtoms); | ||
var flushed = flushPending(); | ||
@@ -425,4 +430,4 @@ { | ||
}; | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { | ||
args[_key2 - 2] = arguments[_key2]; | ||
} | ||
@@ -434,6 +439,8 @@ var result = atom.write.apply(atom, [getter, setter].concat(args)); | ||
var writeAtom = function writeAtom(atom) { | ||
var updatedAtoms = new Set(); | ||
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) { | ||
args[_key4 - 1] = arguments[_key4]; | ||
} | ||
var result = writeAtomState.apply(void 0, [atom].concat(args)); | ||
var result = writeAtomState.apply(void 0, [updatedAtoms, atom].concat(args)); | ||
recomputeDependents(updatedAtoms); | ||
var flushed = flushPending(); | ||
@@ -551,6 +558,6 @@ { | ||
if (atomState) { | ||
if (atomState.d !== (prevAtomState == null ? void 0 : prevAtomState.d)) { | ||
var mounted = mountedMap.get(atom); | ||
if (mounted && atomState.d !== (prevAtomState == null ? void 0 : prevAtomState.d)) { | ||
mountDependencies(atom, atomState, prevAtomState == null ? void 0 : prevAtomState.d); | ||
} | ||
var mounted = mountedMap.get(atom); | ||
if (mounted && !(prevAtomState && !hasPromiseAtomValue(prevAtomState) && (isEqualAtomValue(prevAtomState, atomState) || isEqualAtomError(prevAtomState, atomState)))) { | ||
@@ -622,2 +629,3 @@ mounted.l.forEach(function (listener) { | ||
dev_restore_atoms: function dev_restore_atoms(values) { | ||
var updatedAtoms = new Set(); | ||
for (var _iterator = _createForOfIteratorHelperLoose(values), _step; !(_step = _iterator()).done;) { | ||
@@ -629,5 +637,6 @@ var _step$value = _step.value, | ||
setAtomValueOrPromise(atom, valueOrPromise); | ||
recomputeDependents(atom); | ||
updatedAtoms.add(atom); | ||
} | ||
} | ||
recomputeDependents(updatedAtoms); | ||
var flushed = flushPending(); | ||
@@ -634,0 +643,0 @@ storeListenersRev2.forEach(function (l) { |
@@ -1,1 +0,1 @@ | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).jotaiVanilla={})}(this,(function(n){"use strict";var t=0;var e,r=function(n){return"init"in n},i=function(n){return!!n.write},o=new WeakMap,u=function(n,t){var e=o.get(n);e&&(o.delete(n),e(t))},a=function(n,t){n.status="fulfilled",n.value=t},f=function(n,t){n.status="rejected",n.reason=t},c=function(n,t){return"v"in n&&"v"in t&&Object.is(n.v,t.v)},v=function(n,t){return"e"in n&&"e"in t&&Object.is(n.e,t.e)},l=function(n){return"v"in n&&n.v instanceof Promise},d=function(n){if("e"in n)throw n.e;return n.v},s=function(){var n=new WeakMap,t=new WeakMap,e=new Map,s=function(t){return n.get(t)},g=function(t,r){var i=n.get(t);if(n.set(t,r),e.has(t)||e.set(t,i),i&&l(i)){var o="v"in r?r.v instanceof Promise?r.v:Promise.resolve(r.v):Promise.reject(r.e);u(i.v,o)}},h=function(n,t,e){var r=new Map,i=!1;e.forEach((function(e,o){e||o!==n||(e=t),e&&(r.set(o,e),t.d.get(o)!==e&&(i=!0))})),(i||t.d.size!==r.size)&&(t.d=r)},p=function(n,t,e){var r,i,o=s(n),u={d:(null==o?void 0:o.d)||new Map,v:t};if(e&&h(n,u,e),o&&c(o,u)&&o.d===u.d)return o;if(o&&l(o)&&l(u)&&(i=u,"v"in(r=o)&&"v"in i&&r.v.orig&&r.v.orig===i.v.orig)){if(o.d===u.d)return o;u.v=o.v}return g(n,u),u},w=function(n,t,e,r){if("function"==typeof(null==(c=t)?void 0:c.then)){var i,u=new Promise((function(r,o){var c=!1;t.then((function(t){if(!c){c=!0;var i=s(n),o=p(n,u,e);a(u,t),r(t),(null==i?void 0:i.d)!==o.d&&S(n,o,null==i?void 0:i.d)}}),(function(t){if(!c){c=!0;var r=s(n),i=p(n,u,e);f(u,t),o(t),(null==r?void 0:r.d)!==i.d&&S(n,i,null==r?void 0:r.d)}})),i=function(n){c||(c=!0,n.then((function(n){return a(u,n)}),(function(n){return f(u,n)})),r(n))}}));return u.orig=t,u.status="pending",function(n,t){o.set(n,t),n.catch((function(){})).finally((function(){return o.delete(n)}))}(u,(function(n){n&&i(n),null==r||r()})),p(n,u,e)}var c;return p(n,t,e)},y=function n(e,o){var u=s(e);if(!o&&u){if(t.has(e))return u;if(Array.from(u.d).every((function(t){var r=t[0],i=t[1];return r===e||n(r)===i})))return u}var a,f,c=new Map,l=!0,p={get signal(){return a||(a=new AbortController),a.signal},get setSelf(){return!f&&i(e)&&(f=function(){if(!l){for(var n=arguments.length,t=new Array(n),r=0;r<n;r++)t[r]=arguments[r];return M.apply(void 0,[e].concat(t))}}),f}};try{var y=e.read((function(t){if(t===e){var i=s(t);if(i)return c.set(t,i),d(i);if(r(t))return c.set(t,void 0),t.init;throw new Error("no atom init")}var o=n(t);return c.set(t,o),d(o)}),p);return w(e,y,c,(function(){var n;return null==(n=a)?void 0:n.abort()}))}catch(n){return function(n,t,e){var r=s(n),i={d:(null==r?void 0:r.d)||new Map,e:t};return e&&h(n,i,e),r&&v(r,i)&&r.d===i.d?r:(g(n,i),i)}(e,n,c)}finally{l=!1}},m=function(n,t){return!t.l.size&&(!t.t.size||1===t.t.size&&t.t.has(n))},E=function n(e){for(var i=!0,o=arguments.length,u=new Array(o>1?o-1:0),a=1;a<o;a++)u[a-1]=arguments[a];var f=e.write.apply(e,[function(n){return d(y(n))},function(o){for(var u,a=arguments.length,f=new Array(a>1?a-1:0),v=1;v<a;v++)f[v-1]=arguments[v];if(o===e){if(!r(o))throw new Error("atom not writable");var l=s(o),d=w(o,f[0]);l&&c(l,d)||function(n){var e=new Map,r=new WeakMap;!function n(i){var o=t.get(i);null==o||o.t.forEach((function(t){t!==i&&(e.set(t,(e.get(t)||new Set).add(i)),r.set(t,(r.get(t)||0)+1),n(t))}))}(n),function n(i){var o=t.get(i);null==o||o.t.forEach((function(t){if(t!==i){var o=r.get(t);if(o&&r.set(t,--o),!o){var u,a=!(null==(u=e.get(t))||!u.size);if(a){var f=s(t),v=y(t,!0);a=!f||!c(f,v)}a||e.forEach((function(n){return n.delete(t)}))}n(t)}}))}(n)}(o)}else u=n.apply(void 0,[o].concat(f));return i||z(),u}].concat(u));return i=!1,f},M=function(n){for(var t=arguments.length,e=new Array(t>1?t-1:0),r=1;r<t;r++)e[r-1]=arguments[r];var i=E.apply(void 0,[n].concat(e));return z(),i},b=function n(e,r){var o;null==(o=s(e))||o.d.forEach((function(r,i){var o=t.get(i);o?o.t.add(e):i!==e&&n(i,e)})),y(e);var u={t:new Set(r&&[r]),l:new Set};if(t.set(e,u),i(e)&&e.onMount){var a=e.onMount((function(){for(var n=arguments.length,t=new Array(n),r=0;r<n;r++)t[r]=arguments[r];return M.apply(void 0,[e].concat(t))}));a&&(u.u=a)}return u},A=function n(e){var r,i=null==(r=t.get(e))?void 0:r.u;i&&i(),t.delete(e);var o=s(e);o&&(l(o)&&u(o.v),o.d.forEach((function(r,i){if(i!==e){var o=t.get(i);o&&(o.t.delete(e),m(i,o)&&n(i))}})))},S=function(n,e,r){var i=new Set(e.d.keys());null==r||r.forEach((function(e,r){if(i.has(r))i.delete(r);else{var o=t.get(r);o&&(o.t.delete(n),m(r,o)&&A(r))}})),i.forEach((function(e){var r=t.get(e);r?r.t.add(n):t.has(n)&&b(e,n)}))},z=function(){for(;e.size;){var n=Array.from(e);e.clear(),n.forEach((function(n){var e=n[0],r=n[1],i=s(e);if(i){i.d!==(null==r?void 0:r.d)&&S(e,i,null==r?void 0:r.d);var o=t.get(e);!o||r&&!l(r)&&(c(r,i)||v(r,i))||o.l.forEach((function(n){return n()}))}}))}};return{get:function(n){return d(y(n))},set:M,sub:function(n,e){var r=function(n){var e=t.get(n);return e||(e=b(n)),e}(n);z();var i=r.l;return i.add(e),function(){i.delete(e),function(n){var e=t.get(n);e&&m(n,e)&&A(n)}(n)}}}};n.atom=function(n,e){var r="atom"+ ++t,i={toString:function(){return r}};return"function"==typeof n?i.read=n:(i.init=n,i.read=function(n){return n(i)},i.write=function(n,t,e){return t(i,"function"==typeof e?e(n(i)):e)}),e&&(i.write=e),i},n.createStore=s,n.getDefaultStore=function(){return e||(e=s()),e}})); | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).jotaiVanilla={})}(this,(function(n){"use strict";var t=0;var e,r=function(n){return"init"in n},i=function(n){return!!n.write},o=new WeakMap,u=function(n,t){var e=o.get(n);e&&(o.delete(n),e(t))},a=function(n,t){n.status="fulfilled",n.value=t},f=function(n,t){n.status="rejected",n.reason=t},c=function(n,t){return"v"in n&&"v"in t&&Object.is(n.v,t.v)},v=function(n,t){return"e"in n&&"e"in t&&Object.is(n.e,t.e)},l=function(n){return"v"in n&&n.v instanceof Promise},d=function(n){if("e"in n)throw n.e;return n.v},s=function(){var n=new WeakMap,t=new WeakMap,e=new Map,s=function(t){return n.get(t)},g=function(t,r){var i=n.get(t);if(n.set(t,r),e.has(t)||e.set(t,i),i&&l(i)){var o="v"in r?r.v instanceof Promise?r.v:Promise.resolve(r.v):Promise.reject(r.e);u(i.v,o)}},h=function(n,t,e){var r=new Map,i=!1;e.forEach((function(e,o){e||o!==n||(e=t),e&&(r.set(o,e),t.d.get(o)!==e&&(i=!0))})),(i||t.d.size!==r.size)&&(t.d=r)},w=function(n,t,e){var r,i,o=s(n),u={d:(null==o?void 0:o.d)||new Map,v:t};if(e&&h(n,u,e),o&&c(o,u)&&o.d===u.d)return o;if(o&&l(o)&&l(u)&&(i=u,"v"in(r=o)&&"v"in i&&r.v.orig&&r.v.orig===i.v.orig)){if(o.d===u.d)return o;u.v=o.v}return g(n,u),u},p=function(n,e,r,i){if("function"==typeof(null==(v=e)?void 0:v.then)){var u,c=new Promise((function(i,o){var v=!1;e.then((function(e){if(!v){v=!0;var o=s(n),u=w(n,c,r);a(c,e),i(e),t.has(n)&&(null==o?void 0:o.d)!==u.d&&A(n,u,null==o?void 0:o.d)}}),(function(e){if(!v){v=!0;var i=s(n),u=w(n,c,r);f(c,e),o(e),t.has(n)&&(null==i?void 0:i.d)!==u.d&&A(n,u,null==i?void 0:i.d)}})),u=function(n){v||(v=!0,n.then((function(n){return a(c,n)}),(function(n){return f(c,n)})),i(n))}}));return c.orig=e,c.status="pending",function(n,t){o.set(n,t),n.catch((function(){})).finally((function(){return o.delete(n)}))}(c,(function(n){n&&u(n),null==i||i()})),w(n,c,r)}var v;return w(n,e,r)},y=function n(e,o){var u=s(e);if(!o&&u){if(t.has(e))return u;if(Array.from(u.d).every((function(t){var r=t[0],i=t[1];return r===e||n(r)===i})))return u}var a,f,c=new Map,l=!0,w={get signal(){return a||(a=new AbortController),a.signal},get setSelf(){return!f&&i(e)&&(f=function(){if(!l){for(var n=arguments.length,t=new Array(n),r=0;r<n;r++)t[r]=arguments[r];return b.apply(void 0,[e].concat(t))}}),f}};try{var y=e.read((function(t){if(t===e){var i=s(t);if(i)return c.set(t,i),d(i);if(r(t))return c.set(t,void 0),t.init;throw new Error("no atom init")}var o=n(t);return c.set(t,o),d(o)}),w);return p(e,y,c,(function(){var n;return null==(n=a)?void 0:n.abort()}))}catch(n){return function(n,t,e){var r=s(n),i={d:(null==r?void 0:r.d)||new Map,e:t};return e&&h(n,i,e),r&&v(r,i)&&r.d===i.d?r:(g(n,i),i)}(e,n,c)}finally{l=!1}},E=function(n,t){return!t.l.size&&(!t.t.size||1===t.t.size&&t.t.has(n))},m=function(n){if(n.size){var e=new Map,r=new WeakMap;n.forEach((function n(i){var o=t.get(i);null==o||o.t.forEach((function(t){t!==i&&(e.set(t,(e.get(t)||new Set).add(i)),r.set(t,(r.get(t)||0)+1),n(t))}))}));n.forEach((function n(i){var o=t.get(i);null==o||o.t.forEach((function(t){if(t!==i){var o=r.get(t);if(o&&r.set(t,--o),!o){var u,a=!(null==(u=e.get(t))||!u.size);if(a){var f=s(t),v=y(t,!0);a=!f||!c(f,v)}a||e.forEach((function(n){return n.delete(t)}))}n(t)}}))})),n.clear()}},M=function n(t,e){for(var i=!0,o=arguments.length,u=new Array(o>2?o-2:0),a=2;a<o;a++)u[a-2]=arguments[a];var f=e.write.apply(e,[function(n){return d(y(n))},function(o){for(var u,a=arguments.length,f=new Array(a>1?a-1:0),v=1;v<a;v++)f[v-1]=arguments[v];if(o===e){if(!r(o))throw new Error("atom not writable");var l=s(o),d=p(o,f[0]);l&&c(l,d)||t.add(o)}else u=n.apply(void 0,[t,o].concat(f));return i||(m(t),j()),u}].concat(u));return i=!1,f},b=function(n){for(var t=new Set,e=arguments.length,r=new Array(e>1?e-1:0),i=1;i<e;i++)r[i-1]=arguments[i];var o=M.apply(void 0,[t,n].concat(r));return m(t),j(),o},S=function n(e,r){var o;null==(o=s(e))||o.d.forEach((function(r,i){var o=t.get(i);o?o.t.add(e):i!==e&&n(i,e)})),y(e);var u={t:new Set(r&&[r]),l:new Set};if(t.set(e,u),i(e)&&e.onMount){var a=e.onMount((function(){for(var n=arguments.length,t=new Array(n),r=0;r<n;r++)t[r]=arguments[r];return b.apply(void 0,[e].concat(t))}));a&&(u.u=a)}return u},z=function n(e){var r,i=null==(r=t.get(e))?void 0:r.u;i&&i(),t.delete(e);var o=s(e);o&&(l(o)&&u(o.v),o.d.forEach((function(r,i){if(i!==e){var o=t.get(i);o&&(o.t.delete(e),E(i,o)&&n(i))}})))},A=function(n,e,r){var i=new Set(e.d.keys());null==r||r.forEach((function(e,r){if(i.has(r))i.delete(r);else{var o=t.get(r);o&&(o.t.delete(n),E(r,o)&&z(r))}})),i.forEach((function(e){var r=t.get(e);r?r.t.add(n):t.has(n)&&S(e,n)}))},j=function(){for(;e.size;){var n=Array.from(e);e.clear(),n.forEach((function(n){var e=n[0],r=n[1],i=s(e);if(i){var o=t.get(e);o&&i.d!==(null==r?void 0:r.d)&&A(e,i,null==r?void 0:r.d),!o||r&&!l(r)&&(c(r,i)||v(r,i))||o.l.forEach((function(n){return n()}))}}))}};return{get:function(n){return d(y(n))},set:b,sub:function(n,e){var r=function(n){var e=t.get(n);return e||(e=S(n)),e}(n);j();var i=r.l;return i.add(e),function(){i.delete(e),function(n){var e=t.get(n);e&&E(n,e)&&z(n)}(n)}}}};n.atom=function(n,e){var r="atom"+ ++t,i={toString:function(){return r}};return"function"==typeof n?i.read=n:(i.init=n,i.read=function(n){return n(i)},i.write=function(n,t,e){return t(i,"function"==typeof e?e(n(i)):e)}),e&&(i.write=e),i},n.createStore=s,n.getDefaultStore=function(){return e||(e=s()),e}})); |
@@ -250,3 +250,5 @@ (function (global, factory) { | ||
var nextItem = isFunction(update) ? update(arr[index]) : update; | ||
set(arrAtom, [].concat(arr.slice(0, index), [nextItem], arr.slice(index + 1))); | ||
if (!Object.is(arr[index], nextItem)) { | ||
set(arrAtom, [].concat(arr.slice(0, index), [nextItem], arr.slice(index + 1))); | ||
} | ||
}; | ||
@@ -253,0 +255,0 @@ atomList[index] = isWritable(arrAtom) ? vanilla.atom(read, write) : vanilla.atom(read); |
@@ -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&&(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,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;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}),t.write)},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&&(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,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}),t.write)},o=e,i=y((function(){return new WeakMap}),h,t),y(r,i,o);var r,o,i}})); |
@@ -190,3 +190,3 @@ 'use strict'; | ||
resolve(v); | ||
if ((prevAtomState == null ? void 0 : prevAtomState.d) !== nextAtomState.d) { | ||
if (mountedMap.has(atom) && (prevAtomState == null ? void 0 : prevAtomState.d) !== nextAtomState.d) { | ||
mountDependencies(atom, nextAtomState, prevAtomState == null ? void 0 : prevAtomState.d); | ||
@@ -202,3 +202,3 @@ } | ||
reject(e); | ||
if ((prevAtomState == null ? void 0 : prevAtomState.d) !== nextAtomState.d) { | ||
if (mountedMap.has(atom) && (prevAtomState == null ? void 0 : prevAtomState.d) !== nextAtomState.d) { | ||
mountDependencies(atom, nextAtomState, prevAtomState == null ? void 0 : prevAtomState.d); | ||
@@ -340,3 +340,6 @@ } | ||
}; | ||
var recomputeDependents = function recomputeDependents(atom) { | ||
var recomputeDependents = function recomputeDependents(updatedAtoms) { | ||
if (!updatedAtoms.size) { | ||
return; | ||
} | ||
var dependencyMap = new Map(); | ||
@@ -354,3 +357,3 @@ var dirtyMap = new WeakMap(); | ||
}; | ||
loop1(atom); | ||
updatedAtoms.forEach(loop1); | ||
var loop2 = function loop2(a) { | ||
@@ -382,5 +385,6 @@ var mounted = mountedMap.get(a); | ||
}; | ||
loop2(atom); | ||
updatedAtoms.forEach(loop2); | ||
updatedAtoms.clear(); | ||
}; | ||
var writeAtomState = function writeAtomState(atom) { | ||
var writeAtomState = function writeAtomState(updatedAtoms, atom) { | ||
var isSync = true; | ||
@@ -402,8 +406,9 @@ var getter = function getter(a) { | ||
if (!prevAtomState || !isEqualAtomValue(prevAtomState, nextAtomState)) { | ||
recomputeDependents(a); | ||
updatedAtoms.add(a); | ||
} | ||
} else { | ||
r = writeAtomState.apply(void 0, [a].concat(args)); | ||
r = writeAtomState.apply(void 0, [updatedAtoms, a].concat(args)); | ||
} | ||
if (!isSync) { | ||
recomputeDependents(updatedAtoms); | ||
var flushed = flushPending(); | ||
@@ -421,4 +426,4 @@ if (process.env.NODE_ENV !== 'production') { | ||
}; | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { | ||
args[_key2 - 2] = arguments[_key2]; | ||
} | ||
@@ -430,6 +435,8 @@ var result = atom.write.apply(atom, [getter, setter].concat(args)); | ||
var writeAtom = function writeAtom(atom) { | ||
var updatedAtoms = new Set(); | ||
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) { | ||
args[_key4 - 1] = arguments[_key4]; | ||
} | ||
var result = writeAtomState.apply(void 0, [atom].concat(args)); | ||
var result = writeAtomState.apply(void 0, [updatedAtoms, atom].concat(args)); | ||
recomputeDependents(updatedAtoms); | ||
var flushed = flushPending(); | ||
@@ -547,6 +554,6 @@ if (process.env.NODE_ENV !== 'production') { | ||
if (atomState) { | ||
if (atomState.d !== (prevAtomState == null ? void 0 : prevAtomState.d)) { | ||
var mounted = mountedMap.get(atom); | ||
if (mounted && atomState.d !== (prevAtomState == null ? void 0 : prevAtomState.d)) { | ||
mountDependencies(atom, atomState, prevAtomState == null ? void 0 : prevAtomState.d); | ||
} | ||
var mounted = mountedMap.get(atom); | ||
if (mounted && !(prevAtomState && !hasPromiseAtomValue(prevAtomState) && (isEqualAtomValue(prevAtomState, atomState) || isEqualAtomError(prevAtomState, atomState)))) { | ||
@@ -618,2 +625,3 @@ mounted.l.forEach(function (listener) { | ||
dev_restore_atoms: function dev_restore_atoms(values) { | ||
var updatedAtoms = new Set(); | ||
for (var _iterator = _createForOfIteratorHelperLoose(values), _step; !(_step = _iterator()).done;) { | ||
@@ -625,5 +633,6 @@ var _step$value = _step.value, | ||
setAtomValueOrPromise(atom, valueOrPromise); | ||
recomputeDependents(atom); | ||
updatedAtoms.add(atom); | ||
} | ||
} | ||
recomputeDependents(updatedAtoms); | ||
var flushed = flushPending(); | ||
@@ -630,0 +639,0 @@ storeListenersRev2.forEach(function (l) { |
@@ -248,3 +248,5 @@ 'use strict'; | ||
var nextItem = isFunction(update) ? update(arr[index]) : update; | ||
set(arrAtom, [].concat(arr.slice(0, index), [nextItem], arr.slice(index + 1))); | ||
if (!Object.is(arr[index], nextItem)) { | ||
set(arrAtom, [].concat(arr.slice(0, index), [nextItem], arr.slice(index + 1))); | ||
} | ||
}; | ||
@@ -251,0 +253,0 @@ atomList[index] = isWritable(arrAtom) ? vanilla.atom(read, write) : vanilla.atom(read); |
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
401764
8761