@depup/jotai 2.18.0-depup.0 → 2.18.1-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/changes.json +1 -1
- package/esm/vanilla/internals.mjs +9 -3
- package/esm/vanilla/utils/atomWithObservable.d.mts +5 -1
- package/esm/vanilla/utils.mjs +5 -11
- package/package.json +3 -3
- package/system/vanilla/internals.development.js +9 -3
- package/system/vanilla/internals.production.js +1 -1
- package/system/vanilla/utils.development.js +5 -11
- package/system/vanilla/utils.production.js +1 -1
- package/ts3.8/esm/vanilla/utils/atomWithObservable.d.ts +5 -1
- package/ts3.8/vanilla/utils/atomWithObservable.d.ts +5 -1
- package/umd/vanilla/internals.development.js +9 -3
- package/umd/vanilla/internals.production.js +1 -1
- package/umd/vanilla/utils.development.js +3 -10
- package/umd/vanilla/utils.production.js +1 -1
- package/vanilla/internals.js +9 -3
- package/vanilla/utils/atomWithObservable.d.ts +5 -1
- package/vanilla/utils.js +3 -10
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ npm install @depup/jotai
|
|
|
13
13
|
|
|
14
14
|
| Field | Value |
|
|
15
15
|
|-------|-------|
|
|
16
|
-
| Original | [jotai](https://www.npmjs.com/package/jotai) @ 2.18.
|
|
16
|
+
| Original | [jotai](https://www.npmjs.com/package/jotai) @ 2.18.1 |
|
|
17
17
|
| Processed | 2026-03-09 |
|
|
18
18
|
| Smoke test | failed |
|
|
19
19
|
| Deps updated | 0 |
|
package/changes.json
CHANGED
|
@@ -194,6 +194,7 @@ const BUILDING_BLOCK_recomputeInvalidatedAtoms = (store) => {
|
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
if (hasChangedDeps) {
|
|
197
|
+
invalidatedAtoms.set(a, aState.n);
|
|
197
198
|
readAtomState(store, a);
|
|
198
199
|
mountDependencies(store, a);
|
|
199
200
|
}
|
|
@@ -320,6 +321,7 @@ const BUILDING_BLOCK_readAtomState = (store, atom) => {
|
|
|
320
321
|
}
|
|
321
322
|
};
|
|
322
323
|
const prevEpochNumber = atomState.n;
|
|
324
|
+
const prevInvalidated = invalidatedAtoms.get(atom) === prevEpochNumber;
|
|
323
325
|
try {
|
|
324
326
|
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
|
|
325
327
|
storeMutationSet.delete(store);
|
|
@@ -350,7 +352,7 @@ const BUILDING_BLOCK_readAtomState = (store, atom) => {
|
|
|
350
352
|
return atomState;
|
|
351
353
|
} finally {
|
|
352
354
|
isSync = false;
|
|
353
|
-
if (
|
|
355
|
+
if (atomState.n !== prevEpochNumber && prevInvalidated) {
|
|
354
356
|
invalidatedAtoms.set(atom, atomState.n);
|
|
355
357
|
changedAtoms.add(atom);
|
|
356
358
|
(_b = storeHooks.c) == null ? void 0 : _b.call(storeHooks, atom);
|
|
@@ -590,14 +592,18 @@ const BUILDING_BLOCK_storeGet = (store, atom) => {
|
|
|
590
592
|
};
|
|
591
593
|
const BUILDING_BLOCK_storeSet = (store, atom, ...args) => {
|
|
592
594
|
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
595
|
+
const changedAtoms = buildingBlocks[3];
|
|
593
596
|
const flushCallbacks = buildingBlocks[12];
|
|
594
597
|
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
595
598
|
const writeAtomState = buildingBlocks[16];
|
|
599
|
+
const prevChangedAtomsSize = changedAtoms.size;
|
|
596
600
|
try {
|
|
597
601
|
return writeAtomState(store, atom, ...args);
|
|
598
602
|
} finally {
|
|
599
|
-
|
|
600
|
-
|
|
603
|
+
if (changedAtoms.size !== prevChangedAtomsSize) {
|
|
604
|
+
recomputeInvalidatedAtoms(store);
|
|
605
|
+
flushCallbacks(store);
|
|
606
|
+
}
|
|
601
607
|
}
|
|
602
608
|
};
|
|
603
609
|
const BUILDING_BLOCK_storeSub = (store, atom, listener) => {
|
|
@@ -8,7 +8,7 @@ type Observer<T> = {
|
|
|
8
8
|
error: (error: AnyError) => void;
|
|
9
9
|
complete: () => void;
|
|
10
10
|
};
|
|
11
|
-
type
|
|
11
|
+
type SubscribableObservable<T> = {
|
|
12
12
|
subscribe(observer: Observer<T>): Subscription;
|
|
13
13
|
} | {
|
|
14
14
|
subscribe(observer: Partial<Observer<T>>): Subscription;
|
|
@@ -16,6 +16,10 @@ type ObservableLike<T> = {
|
|
|
16
16
|
subscribe(observer: Partial<Observer<T>>): Subscription;
|
|
17
17
|
subscribe(next: (value: T) => void): Subscription;
|
|
18
18
|
};
|
|
19
|
+
type SymbolObservable<T> = {
|
|
20
|
+
[Symbol.observable]: () => SubscribableObservable<T>;
|
|
21
|
+
};
|
|
22
|
+
type ObservableLike<T> = SubscribableObservable<T> | SymbolObservable<T>;
|
|
19
23
|
type SubjectLike<T> = ObservableLike<T> & Observer<T>;
|
|
20
24
|
type Options<Data> = {
|
|
21
25
|
initialValue?: Data | (() => Data);
|
package/esm/vanilla/utils.mjs
CHANGED
|
@@ -455,12 +455,9 @@ function atomWithStorage(key, initialValue, storage = defaultStorage, options) {
|
|
|
455
455
|
baseAtom.debugPrivate = true;
|
|
456
456
|
}
|
|
457
457
|
baseAtom.onMount = (setAtom) => {
|
|
458
|
+
var _a;
|
|
458
459
|
setAtom(storage.getItem(key, initialValue));
|
|
459
|
-
|
|
460
|
-
if (storage.subscribe) {
|
|
461
|
-
unsub = storage.subscribe(key, setAtom, initialValue);
|
|
462
|
-
}
|
|
463
|
-
return unsub;
|
|
460
|
+
return (_a = storage.subscribe) == null ? void 0 : _a.call(storage, key, setAtom, initialValue);
|
|
464
461
|
};
|
|
465
462
|
const anAtom = atom(
|
|
466
463
|
(get) => get(baseAtom),
|
|
@@ -493,11 +490,8 @@ function atomWithObservable(getObservable, options) {
|
|
|
493
490
|
};
|
|
494
491
|
const observableResultAtom = atom((get) => {
|
|
495
492
|
var _a;
|
|
496
|
-
|
|
497
|
-
const
|
|
498
|
-
if (itself) {
|
|
499
|
-
observable = itself;
|
|
500
|
-
}
|
|
493
|
+
const observable = getObservable(get);
|
|
494
|
+
const subscribable = ((_a = observable[Symbol.observable]) == null ? void 0 : _a.call(observable)) || observable;
|
|
501
495
|
let resolve;
|
|
502
496
|
const makePending = () => new Promise((r) => {
|
|
503
497
|
resolve = r;
|
|
@@ -526,7 +520,7 @@ function atomWithObservable(getObservable, options) {
|
|
|
526
520
|
clearTimeout(timer);
|
|
527
521
|
subscription.unsubscribe();
|
|
528
522
|
}
|
|
529
|
-
subscription =
|
|
523
|
+
subscription = subscribable.subscribe({
|
|
530
524
|
next: (d) => listener({ d }),
|
|
531
525
|
error: (e) => listener({ e }),
|
|
532
526
|
complete: () => {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "[DepUp] 👻 Primitive and flexible state management for React",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "commonjs",
|
|
6
|
-
"version": "2.18.
|
|
6
|
+
"version": "2.18.1-depup.0",
|
|
7
7
|
"main": "./index.js",
|
|
8
8
|
"types": "./index.d.ts",
|
|
9
9
|
"typesVersions": {
|
|
@@ -118,8 +118,8 @@
|
|
|
118
118
|
"changes": {},
|
|
119
119
|
"depsUpdated": 0,
|
|
120
120
|
"originalPackage": "jotai",
|
|
121
|
-
"originalVersion": "2.18.
|
|
122
|
-
"processedAt": "2026-03-
|
|
121
|
+
"originalVersion": "2.18.1",
|
|
122
|
+
"processedAt": "2026-03-09T16:26:16.914Z",
|
|
123
123
|
"smokeTest": "failed"
|
|
124
124
|
}
|
|
125
125
|
}
|
|
@@ -212,6 +212,7 @@ System.register([], (function (exports) {
|
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
if (hasChangedDeps) {
|
|
215
|
+
invalidatedAtoms.set(a, aState.n);
|
|
215
216
|
readAtomState(store, a);
|
|
216
217
|
mountDependencies(store, a);
|
|
217
218
|
}
|
|
@@ -338,6 +339,7 @@ System.register([], (function (exports) {
|
|
|
338
339
|
}
|
|
339
340
|
};
|
|
340
341
|
const prevEpochNumber = atomState.n;
|
|
342
|
+
const prevInvalidated = invalidatedAtoms.get(atom) === prevEpochNumber;
|
|
341
343
|
try {
|
|
342
344
|
if (true) {
|
|
343
345
|
storeMutationSet.delete(store);
|
|
@@ -368,7 +370,7 @@ System.register([], (function (exports) {
|
|
|
368
370
|
return atomState;
|
|
369
371
|
} finally {
|
|
370
372
|
isSync = false;
|
|
371
|
-
if (
|
|
373
|
+
if (atomState.n !== prevEpochNumber && prevInvalidated) {
|
|
372
374
|
invalidatedAtoms.set(atom, atomState.n);
|
|
373
375
|
changedAtoms.add(atom);
|
|
374
376
|
(_b = storeHooks.c) == null ? void 0 : _b.call(storeHooks, atom);
|
|
@@ -608,14 +610,18 @@ System.register([], (function (exports) {
|
|
|
608
610
|
};
|
|
609
611
|
const BUILDING_BLOCK_storeSet = (store, atom, ...args) => {
|
|
610
612
|
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
613
|
+
const changedAtoms = buildingBlocks[3];
|
|
611
614
|
const flushCallbacks = buildingBlocks[12];
|
|
612
615
|
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
613
616
|
const writeAtomState = buildingBlocks[16];
|
|
617
|
+
const prevChangedAtomsSize = changedAtoms.size;
|
|
614
618
|
try {
|
|
615
619
|
return writeAtomState(store, atom, ...args);
|
|
616
620
|
} finally {
|
|
617
|
-
|
|
618
|
-
|
|
621
|
+
if (changedAtoms.size !== prevChangedAtomsSize) {
|
|
622
|
+
recomputeInvalidatedAtoms(store);
|
|
623
|
+
flushCallbacks(store);
|
|
624
|
+
}
|
|
619
625
|
}
|
|
620
626
|
};
|
|
621
627
|
const BUILDING_BLOCK_storeSub = (store, atom, listener) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
System.register([],(function(C){"use strict";return{execute:(function(){C({INTERNAL_addPendingPromiseToDependency:B,INTERNAL_buildStoreRev2:
|
|
1
|
+
System.register([],(function(C){"use strict";return{execute:(function(){C({INTERNAL_addPendingPromiseToDependency:B,INTERNAL_buildStoreRev2:fn,INTERNAL_getBuildingBlocksRev2:un,INTERNAL_getMountedOrPendingDependents:O,INTERNAL_hasInitialValue:W,INTERNAL_initializeStoreHooksRev2:q,INTERNAL_isActuallyWritableAtom:b,INTERNAL_isAtomStateInitialized:P,INTERNAL_isPromiseLike:I,INTERNAL_returnAtomValue:S});function W(n){return"init"in n}function b(n){return!!n.write}function P(n){return"v"in n||"e"in n}function S(n){if("e"in n)throw n.e;return n.v}function I(n){return typeof(n==null?void 0:n.then)=="function"}function B(n,e,o){if(!o.p.has(n)){o.p.add(n);const t=()=>o.p.delete(n);e.then(t,t)}}function O(n,e,o){var t;const r=new Set;for(const l of((t=o.get(n))==null?void 0:t.t)||[])r.add(l);for(const l of e.p)r.add(l);return r}const H=()=>{const n=new Set,e=()=>n.forEach(o=>o());return e.add=o=>(n.add(o),()=>n.delete(o)),e},R=()=>{const n={},e=new WeakMap,o=t=>{var r,l;(r=e.get(n))==null||r.forEach(s=>s(t)),(l=e.get(t))==null||l.forEach(s=>s())};return o.add=(t,r)=>{const l=t||n;let s=e.get(l);return s||(s=new Set,e.set(l,s)),s.add(r),()=>{s.delete(r),s.size||e.delete(l)}},o};function q(n){return n.i||(n.i=R()),n.r||(n.r=R()),n.c||(n.c=R()),n.m||(n.m=R()),n.u||(n.u=R()),n.f||(n.f=H()),n}const F=(n,e,...o)=>e.read(...o),G=(n,e,...o)=>e.write(...o),J=(n,e)=>{var o;return(o=e.INTERNAL_onInit)==null?void 0:o.call(e,n)},K=(n,e,o)=>{var t;return(t=e.onMount)==null?void 0:t.call(e,o)},Q=(n,e)=>{var o;const t=v(n),r=t[0],l=t[6],s=t[9];let c=r.get(e);return c||(c={d:new Map,p:new Set,n:0},r.set(e,c),(o=l.i)==null||o.call(l,e),s==null||s(n,e)),c},U=n=>{const e=v(n),o=e[1],t=e[3],r=e[4],l=e[5],s=e[6],c=e[13],d=[],g=p=>{try{p()}catch(u){d.push(u)}};do{s.f&&g(s.f);const p=new Set,u=p.add.bind(p);t.forEach(f=>{var a;return(a=o.get(f))==null?void 0:a.l.forEach(u)}),t.clear(),l.forEach(u),l.clear(),r.forEach(u),r.clear(),p.forEach(g),t.size&&c(n)}while(t.size||l.size||r.size);if(d.length)throw new AggregateError(d)},X=n=>{const e=v(n),o=e[1],t=e[2],r=e[3],l=e[11],s=e[14],c=e[17],d=[],g=new WeakSet,p=new WeakSet,u=Array.from(r);for(;u.length;){const f=u[u.length-1],a=l(n,f);if(p.has(f)){u.pop();continue}if(g.has(f)){t.get(f)===a.n&&d.push([f,a]),p.add(f),u.pop();continue}g.add(f);for(const w of O(f,a,o))g.has(w)||u.push(w)}for(let f=d.length-1;f>=0;--f){const[a,w]=d[f];let y=!1;for(const A of w.d.keys())if(A!==a&&r.has(A)){y=!0;break}y&&(t.set(a,w.n),s(n,a),c(n,a)),t.delete(a)}},Y=(n,e)=>{var o,t;const r=v(n),l=r[1],s=r[2],c=r[3],d=r[6],g=r[7],p=r[11],u=r[12],f=r[13],a=r[14],w=r[16],y=r[17],A=r[20],N=r[26],i=p(n,e);if(P(i)){if(l.has(e)&&s.get(e)!==i.n)return i;let h=!1;for(const[k,m]of i.d)if(a(n,k).n!==m){h=!0;break}if(!h)return i}let E=!0;const T=new Set(i.d.keys()),z=new Map,_=()=>{for(const h of T)z.has(h)||i.d.delete(h)},M=()=>{if(l.has(e)){const h=!c.size;y(n,e),h&&(f(n),u(n))}},dn=h=>{var k;if(h===e){const x=p(n,h);if(!P(x))if(W(h))A(n,h,h.init);else throw new Error("no atom init");return S(x)}const m=a(n,h);try{return S(m)}finally{z.set(h,m.n),i.d.set(h,m.n),I(i.v)&&B(e,i.v,m),l.has(e)&&((k=l.get(h))==null||k.t.add(e)),E||M()}};let L,j;const hn={get signal(){return L||(L=new AbortController),L.signal},get setSelf(){return!j&&b(e)&&(j=(...h)=>{if(!E)try{return w(n,e,...h)}finally{f(n),u(n)}}),j}},V=i.n,gn=s.get(e)===V;try{const h=g(n,e,dn,hn);if(A(n,e,h),I(h)){N(n,h,()=>L==null?void 0:L.abort());const k=()=>{_(),M()};h.then(k,k)}else _();return(o=d.r)==null||o.call(d,e),i}catch(h){return delete i.v,i.e=h,++i.n,i}finally{E=!1,i.n!==V&&gn&&(s.set(e,i.n),c.add(e),(t=d.c)==null||t.call(d,e))}},Z=(n,e)=>{const o=v(n),t=o[1],r=o[2],l=o[11],s=[e];for(;s.length;){const c=s.pop(),d=l(n,c);for(const g of O(c,d,t)){const p=l(n,g);r.get(g)!==p.n&&(r.set(g,p.n),s.push(g))}}},$=(n,e,...o)=>{const t=v(n),r=t[3],l=t[6],s=t[8],c=t[11],d=t[12],g=t[13],p=t[14],u=t[15],f=t[16],a=t[17],w=t[20];let y=!0;const A=i=>S(p(n,i)),N=(i,...E)=>{var T;const z=c(n,i);try{if(i===e){if(!W(i))throw new Error("atom not writable");const _=z.n,M=E[0];w(n,i,M),a(n,i),_!==z.n&&(r.add(i),u(n,i),(T=l.c)==null||T.call(l,i));return}else return f(n,i,...E)}finally{y||(g(n),d(n))}};try{return s(n,e,A,N,...o)}finally{y=!1}},nn=(n,e)=>{var o;const t=v(n),r=t[1],l=t[3],s=t[6],c=t[11],d=t[15],g=t[18],p=t[19],u=c(n,e),f=r.get(e);if(f){for(const[a,w]of u.d)if(!f.d.has(a)){const y=c(n,a);g(n,a).t.add(e),f.d.add(a),w!==y.n&&(l.add(a),d(n,a),(o=s.c)==null||o.call(s,a))}for(const a of f.d)if(!u.d.has(a)){f.d.delete(a);const w=p(n,a);w==null||w.t.delete(e)}}},en=(n,e)=>{var o;const t=v(n),r=t[1],l=t[4],s=t[6],c=t[10],d=t[11],g=t[12],p=t[13],u=t[14],f=t[16],a=t[18],w=d(n,e);let y=r.get(e);if(!y){u(n,e);for(const A of w.d.keys())a(n,A).t.add(e);if(y={l:new Set,d:new Set(w.d.keys()),t:new Set},r.set(e,y),b(e)){const A=()=>{let N=!0;const i=(...E)=>{try{return f(n,e,...E)}finally{N||(p(n),g(n))}};try{const E=c(n,e,i);E&&(y.u=()=>{N=!0;try{E()}finally{N=!1}})}finally{N=!1}};l.add(A)}(o=s.m)==null||o.call(s,e)}return y},tn=(n,e)=>{var o,t;const r=v(n),l=r[1],s=r[5],c=r[6],d=r[11],g=r[19],p=d(n,e);let u=l.get(e);if(!u||u.l.size)return u;let f=!1;for(const a of u.t)if((o=l.get(a))!=null&&o.d.has(e)){f=!0;break}if(!f){u.u&&s.add(u.u),u=void 0,l.delete(e);for(const a of p.d.keys()){const w=g(n,a);w==null||w.t.delete(e)}(t=c.u)==null||t.call(c,e);return}return u},rn=(n,e,o)=>{const t=v(n),r=t[11],l=t[27],s=r(n,e),c="v"in s,d=s.v;if(I(o))for(const g of s.d.keys())B(e,o,r(n,g));s.v=o,delete s.e,(!c||!Object.is(d,s.v))&&(++s.n,I(d)&&l(n,d))},on=(n,e)=>{const o=v(n)[14];return S(o(n,e))},ln=(n,e,...o)=>{const t=v(n),r=t[3],l=t[12],s=t[13],c=t[16],d=r.size;try{return c(n,e,...o)}finally{r.size!==d&&(s(n),l(n))}},sn=(n,e,o)=>{const t=v(n),r=t[12],l=t[18],s=t[19],c=l(n,e).l;return c.add(o),r(n),()=>{c.delete(o),s(n,e),r(n)}},an=(n,e,o)=>{const t=v(n)[25];let r=t.get(e);if(!r){r=new Set,t.set(e,r);const l=()=>t.delete(e);e.then(l,l)}r.add(o)},cn=(n,e)=>{const o=v(n)[25].get(e);o==null||o.forEach(t=>t())},D=new WeakMap,v=n=>D.get(n);function un(n){const e=v(n),o=e[24];return o?o(e):e}function fn(...n){const e={get(t){const r=v(e)[21];return r(e,t)},set(t,...r){const l=v(e)[22];return l(e,t,...r)},sub(t,r){const l=v(e)[23];return l(e,t,r)}},o=[new WeakMap,new WeakMap,new WeakMap,new Set,new Set,new Set,{},F,G,J,K,Q,U,X,Y,Z,$,nn,en,tn,rn,on,ln,sn,void 0,new WeakMap,an,cn].map((t,r)=>n[r]||t);return D.set(e,Object.freeze(o)),e}})}}));
|
|
@@ -481,12 +481,9 @@ System.register(['jotai/vanilla'], (function (exports) {
|
|
|
481
481
|
baseAtom.debugPrivate = true;
|
|
482
482
|
}
|
|
483
483
|
baseAtom.onMount = (setAtom) => {
|
|
484
|
+
var _a;
|
|
484
485
|
setAtom(storage.getItem(key, initialValue));
|
|
485
|
-
|
|
486
|
-
if (storage.subscribe) {
|
|
487
|
-
unsub = storage.subscribe(key, setAtom, initialValue);
|
|
488
|
-
}
|
|
489
|
-
return unsub;
|
|
486
|
+
return (_a = storage.subscribe) == null ? void 0 : _a.call(storage, key, setAtom, initialValue);
|
|
490
487
|
};
|
|
491
488
|
const anAtom = atom(
|
|
492
489
|
(get) => get(baseAtom),
|
|
@@ -519,11 +516,8 @@ System.register(['jotai/vanilla'], (function (exports) {
|
|
|
519
516
|
};
|
|
520
517
|
const observableResultAtom = atom((get) => {
|
|
521
518
|
var _a;
|
|
522
|
-
|
|
523
|
-
const
|
|
524
|
-
if (itself) {
|
|
525
|
-
observable = itself;
|
|
526
|
-
}
|
|
519
|
+
const observable = getObservable(get);
|
|
520
|
+
const subscribable = ((_a = observable[Symbol.observable]) == null ? void 0 : _a.call(observable)) || observable;
|
|
527
521
|
let resolve;
|
|
528
522
|
const makePending = () => new Promise((r) => {
|
|
529
523
|
resolve = r;
|
|
@@ -552,7 +546,7 @@ System.register(['jotai/vanilla'], (function (exports) {
|
|
|
552
546
|
clearTimeout(timer);
|
|
553
547
|
subscription.unsubscribe();
|
|
554
548
|
}
|
|
555
|
-
subscription =
|
|
549
|
+
subscription = subscribable.subscribe({
|
|
556
550
|
next: (d) => listener({ d }),
|
|
557
551
|
error: (e) => listener({ e }),
|
|
558
552
|
complete: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
System.register(["jotai/vanilla"],(function(x){"use strict";var m;return{setters:[function(O){m=O.atom}],execute:(function(){x({atomFamily:$,atomWithDefault:X,atomWithLazy:lt,atomWithObservable:nt,atomWithReducer:
|
|
1
|
+
System.register(["jotai/vanilla"],(function(x){"use strict";var m;return{setters:[function(O){m=O.atom}],execute:(function(){x({atomFamily:$,atomWithDefault:X,atomWithLazy:lt,atomWithObservable:nt,atomWithReducer:P,atomWithRefresh:at,atomWithReset:J,atomWithStorage:tt,createJSONStorage:V,freezeAtom:T,freezeAtomCreator:q,loadable:ct,selectAtom:K,splitAtom:U,unstable_withStorageValidator:Y,unwrap:_});const O=x("RESET",Symbol(""));function J(t){const e=m(t,(s,u,c)=>{const a=typeof c=="function"?c(s(e)):c;u(e,a===O?t:a)});return e}function P(t,e){return m(t,function(s,u,c){u(this,e(s(this),c))})}function $(t,e){let s=null;const u=new Map,c=new Set,a=i=>{let n;if(e===void 0)n=u.get(i);else for(const[l,f]of u)if(e(l,i)){n=f;break}if(n!==void 0)if(s!=null&&s(n[1],i))a.remove(i);else return n[0];const r=t(i);return u.set(i,[r,Date.now()]),o("CREATE",i,r),r},o=(i,n,r)=>{for(const l of c)l({type:i,param:n,atom:r})};return a.unstable_listen=i=>(c.add(i),()=>{c.delete(i)}),a.getParams=()=>u.keys(),a.remove=i=>{if(e===void 0){if(!u.has(i))return;const[n]=u.get(i);u.delete(i),o("REMOVE",i,n)}else for(const[n,[r]]of u)if(e(n,i)){u.delete(n),o("REMOVE",n,r);break}},a.setShouldRemove=i=>{if(s=i,!!s)for(const[n,[r,l]]of u)s(l,n)&&(u.delete(n),o("REMOVE",n,r))},a}const I=(t,e,s)=>(e.has(s)?e:e.set(s,t())).get(s),C=new WeakMap,F=(t,e,s,u)=>{const c=I(()=>new WeakMap,C,e),a=I(()=>new WeakMap,c,s);return I(t,a,u)};function K(t,e,s=Object.is){return F(()=>{const u=Symbol(),c=([o,i])=>{if(i===u)return e(o);const n=e(o,i);return s(i,n)?i:n},a=m(o=>{const i=o(a),n=o(t);return c([n,i])});return a.init=u,a},t,e,s)}const A=new WeakSet,L=t=>{if(typeof t!="object"||t===null)return t;Object.freeze(t);const e=Object.getOwnPropertyNames(t);for(const s of e)L(t[s]);return t};function T(t){if(A.has(t))return t;A.add(t);const e=t.read;if(t.read=function(s,u){return L(e.call(this,s,u))},"write"in t){const s=t.write;t.write=function(u,c,...a){return s.call(this,u,(...o)=>(o[0]===t&&(o[1]=L(o[1])),c(...o)),...a)}}return t}function q(t){return((...e)=>T(t(...e)))}const j=(t,e,s)=>(e.has(s)?e:e.set(s,t())).get(s),B=new WeakMap,G=(t,e,s)=>{const u=j(()=>new WeakMap,B,e);return j(t,u,s)},H={},N=t=>!!t.write,Q=t=>typeof t=="function";function U(t,e){return G(()=>{const s=new WeakMap,u=(o,i)=>{let n=s.get(o);if(n)return n;const r=i&&s.get(i),l=[],f=[];return o.forEach((b,v)=>{const d=e?e(b):v;f[v]=d;const g=r&&r.atomList[r.keyList.indexOf(d)];if(g){l[v]=g;return}const W=w=>{const y=w(c),h=w(t),S=u(h,y==null?void 0:y.arr).keyList.indexOf(d);if(S<0||S>=h.length){const p=o[u(o).keyList.indexOf(d)];if(p)return p;throw new Error("splitAtom: index out of bounds for read")}return h[S]},E=(w,y,h)=>{const S=w(c),p=w(t),k=u(p,S==null?void 0:S.arr).keyList.indexOf(d);if(k<0||k>=p.length)throw new Error("splitAtom: index out of bounds for write");const D=Q(h)?h(p[k]):h;Object.is(p[k],D)||y(t,[...p.slice(0,k),D,...p.slice(k+1)])};l[v]=N(t)?m(W,E):m(W)}),r&&r.keyList.length===f.length&&r.keyList.every((b,v)=>b===f[v])?n=r:n={arr:o,atomList:l,keyList:f},s.set(o,n),n},c=m(o=>{const i=o(c),n=o(t);return u(n,i==null?void 0:i.arr)});c.init=void 0;const a=N(t)?m(o=>o(c).atomList,(o,i,n)=>{switch(n.type){case"remove":{const r=o(a).indexOf(n.atom);if(r>=0){const l=o(t);i(t,[...l.slice(0,r),...l.slice(r+1)])}break}case"insert":{const r=n.before?o(a).indexOf(n.before):o(a).length;if(r>=0){const l=o(t);i(t,[...l.slice(0,r),n.value,...l.slice(r)])}break}case"move":{const r=o(a).indexOf(n.atom),l=n.before?o(a).indexOf(n.before):o(a).length;if(r>=0&&l>=0){const f=o(t);r<l?i(t,[...f.slice(0,r),...f.slice(r+1,l),f[r],...f.slice(l)]):i(t,[...f.slice(0,l),f[r],...f.slice(l,r),...f.slice(r+1)])}break}}}):m(o=>o(c).atomList);return a},t,e||H)}function X(t){const e=Symbol(),s=m(e),u=m((c,a)=>{const o=c(s);return o!==e?o:t(c,a)},(c,a,o)=>{const i=typeof o=="function"?o(c(u)):o;a(s,i===O?e:i)});return u}const M=t=>typeof(t==null?void 0:t.then)=="function";function Y(t){return e=>({...e,getItem:(s,u)=>{const c=o=>t(o)?o:u,a=e.getItem(s,u);return M(a)?a.then(c):c(a)}})}function V(t=()=>{try{return window.localStorage}catch(s){return}},e){var s;let u,c;const a={getItem:(n,r)=>{var l,f;const b=d=>{if(d=d||"",u!==d){try{c=JSON.parse(d,e==null?void 0:e.reviver)}catch(g){return r}u=d}return c},v=(f=(l=t())==null?void 0:l.getItem(n))!=null?f:null;return M(v)?v.then(b):b(v)},setItem:(n,r)=>{var l;return(l=t())==null?void 0:l.setItem(n,JSON.stringify(r,e==null?void 0:e.replacer))},removeItem:n=>{var r;return(r=t())==null?void 0:r.removeItem(n)}},o=n=>(r,l,f)=>n(r,b=>{let v;try{v=JSON.parse(b||"")}catch(d){v=f}l(v)});let i;try{i=(s=t())==null?void 0:s.subscribe}catch(n){}return!i&&typeof window!="undefined"&&typeof window.addEventListener=="function"&&window.Storage&&(i=(n,r)=>{if(!(t()instanceof window.Storage))return()=>{};const l=f=>{f.storageArea===t()&&f.key===n&&r(f.newValue)};return window.addEventListener("storage",l),()=>{window.removeEventListener("storage",l)}}),i&&(a.subscribe=o(i)),a}const Z=V();function tt(t,e,s=Z,u){const c=u==null?void 0:u.getOnInit,a=m(c?s.getItem(t,e):e);return a.onMount=o=>{var i;return o(s.getItem(t,e)),(i=s.subscribe)==null?void 0:i.call(s,t,o,e)},m(o=>o(a),(o,i,n)=>{const r=typeof n=="function"?n(o(a)):n;return r===O?(i(a,e),s.removeItem(t)):M(r)?r.then(l=>(i(a,l),s.setItem(t,l))):(i(a,r),s.setItem(t,r))})}const et=t=>typeof(t==null?void 0:t.then)=="function";function nt(t,e){const s=c=>{if("e"in c)throw c.e;return c.d},u=m(c=>{var a;const o=t(c),i=((a=o[Symbol.observable])==null?void 0:a.call(o))||o;let n;const r=()=>new Promise(h=>{n=h}),l=e&&"initialValue"in e?{d:typeof e.initialValue=="function"?e.initialValue():e.initialValue}:r();let f,b;const v=h=>{b=h,n==null||n(h),f==null||f(h)};let d,g;const W=()=>!f,E=()=>{d&&(d.unsubscribe(),d=void 0)},w=()=>{d&&(clearTimeout(g),d.unsubscribe()),d=i.subscribe({next:h=>v({d:h}),error:h=>v({e:h}),complete:()=>{}}),W()&&e!=null&&e.unstable_timeout&&(g=setTimeout(E,e.unstable_timeout))};w();const y=m(b||l);return y.onMount=h=>(f=h,b&&h(b),d?clearTimeout(g):w(),()=>{f=void 0,e!=null&&e.unstable_timeout?g=setTimeout(E,e.unstable_timeout):E()}),[y,o,r,w,W]});return m(c=>{const[a]=c(u),o=c(a);return et(o)?o.then(s):s(o)},(c,a,o)=>{const[i,n,r,l,f]=c(u);if("next"in n)f()&&(a(i,r()),l()),n.next(o);else throw new Error("observable is not subject")})}const z=(t,e,s)=>(e.has(s)?e:e.set(s,t())).get(s),ot=new WeakMap,rt=(t,e,s)=>{const u=z(()=>new WeakMap,ot,e);return z(t,u,s)},it=t=>typeof(t==null?void 0:t.then)=="function",st=()=>{};function _(t,e=st){return rt(()=>{const s=new WeakMap,u=new WeakMap,c=m(0),a=m([]);a.INTERNAL_onInit=i=>{i.set(a,[()=>i.set(c,n=>n+1)])};const o=m(i=>{i(c);let n;try{n=i(o)}catch(l){}const r=i(t);if(!it(r))return{v:r};if(r!==(n==null?void 0:n.p)&&r.then(l=>{u.set(r,l);const[f]=i(a);f()},l=>{s.set(r,l);const[f]=i(a);f()}),s.has(r))throw s.get(r);return u.has(r)?{p:r,v:u.get(r)}:n&&"v"in n?{p:r,f:e(n.v),v:n.v}:{p:r,f:e()}});return o.init=void 0,m(i=>{const n=i(o);return"f"in n?n.f:n.v},(i,n,...r)=>n(t,...r))},t,e)}const R=new WeakMap,ut=(t,e)=>(R.has(e)?R:R.set(e,t())).get(e);function ct(t){return ut(()=>{const e={state:"loading"},s=_(t,()=>e);return m(u=>{try{const c=u(s);return c===e?e:{state:"hasData",data:c}}catch(c){return{state:"hasError",error:c}}})},t)}function at(t,e){const s=m(0);return m((u,c)=>(u(s),t(u,c)),(u,c,...a)=>{if(a.length===0)c(s,o=>o+1);else if(e)return e(u,c,...a)})}function lt(t){const e=m(void 0);return delete e.init,Object.defineProperty(e,"init",{get(){return t()}}),e}})}}));
|
|
@@ -8,7 +8,7 @@ type Observer<T> = {
|
|
|
8
8
|
error: (error: AnyError) => void;
|
|
9
9
|
complete: () => void;
|
|
10
10
|
};
|
|
11
|
-
type
|
|
11
|
+
type SubscribableObservable<T> = {
|
|
12
12
|
subscribe(observer: Observer<T>): Subscription;
|
|
13
13
|
} | {
|
|
14
14
|
subscribe(observer: Partial<Observer<T>>): Subscription;
|
|
@@ -16,6 +16,10 @@ type ObservableLike<T> = {
|
|
|
16
16
|
subscribe(observer: Partial<Observer<T>>): Subscription;
|
|
17
17
|
subscribe(next: (value: T) => void): Subscription;
|
|
18
18
|
};
|
|
19
|
+
type SymbolObservable<T> = {
|
|
20
|
+
[Symbol.observable]: () => SubscribableObservable<T>;
|
|
21
|
+
};
|
|
22
|
+
type ObservableLike<T> = SubscribableObservable<T> | SymbolObservable<T>;
|
|
19
23
|
type SubjectLike<T> = ObservableLike<T> & Observer<T>;
|
|
20
24
|
type Options<Data> = {
|
|
21
25
|
initialValue?: Data | (() => Data);
|
|
@@ -8,7 +8,7 @@ type Observer<T> = {
|
|
|
8
8
|
error: (error: AnyError) => void;
|
|
9
9
|
complete: () => void;
|
|
10
10
|
};
|
|
11
|
-
type
|
|
11
|
+
type SubscribableObservable<T> = {
|
|
12
12
|
subscribe(observer: Observer<T>): Subscription;
|
|
13
13
|
} | {
|
|
14
14
|
subscribe(observer: Partial<Observer<T>>): Subscription;
|
|
@@ -16,6 +16,10 @@ type ObservableLike<T> = {
|
|
|
16
16
|
subscribe(observer: Partial<Observer<T>>): Subscription;
|
|
17
17
|
subscribe(next: (value: T) => void): Subscription;
|
|
18
18
|
};
|
|
19
|
+
type SymbolObservable<T> = {
|
|
20
|
+
[Symbol.observable]: () => SubscribableObservable<T>;
|
|
21
|
+
};
|
|
22
|
+
type ObservableLike<T> = SubscribableObservable<T> | SymbolObservable<T>;
|
|
19
23
|
type SubjectLike<T> = ObservableLike<T> & Observer<T>;
|
|
20
24
|
type Options<Data> = {
|
|
21
25
|
initialValue?: Data | (() => Data);
|
|
@@ -263,6 +263,7 @@
|
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
265
|
if (hasChangedDeps) {
|
|
266
|
+
invalidatedAtoms.set(_a, _aState.n);
|
|
266
267
|
readAtomState(store, _a);
|
|
267
268
|
mountDependencies(store, _a);
|
|
268
269
|
}
|
|
@@ -393,6 +394,7 @@
|
|
|
393
394
|
}
|
|
394
395
|
};
|
|
395
396
|
var prevEpochNumber = atomState.n;
|
|
397
|
+
var prevInvalidated = invalidatedAtoms.get(atom) === prevEpochNumber;
|
|
396
398
|
try {
|
|
397
399
|
if ("development" !== 'production') {
|
|
398
400
|
storeMutationSet.delete(store);
|
|
@@ -424,7 +426,7 @@
|
|
|
424
426
|
return atomState;
|
|
425
427
|
} finally {
|
|
426
428
|
isSync = false;
|
|
427
|
-
if (
|
|
429
|
+
if (atomState.n !== prevEpochNumber && prevInvalidated) {
|
|
428
430
|
invalidatedAtoms.set(atom, atomState.n);
|
|
429
431
|
changedAtoms.add(atom);
|
|
430
432
|
storeHooks.c == null || storeHooks.c(atom);
|
|
@@ -677,17 +679,21 @@
|
|
|
677
679
|
};
|
|
678
680
|
var BUILDING_BLOCK_storeSet = function BUILDING_BLOCK_storeSet(store, atom) {
|
|
679
681
|
var buildingBlocks = getInternalBuildingBlocks(store);
|
|
682
|
+
var changedAtoms = buildingBlocks[3];
|
|
680
683
|
var flushCallbacks = buildingBlocks[12];
|
|
681
684
|
var recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
682
685
|
var writeAtomState = buildingBlocks[16];
|
|
686
|
+
var prevChangedAtomsSize = changedAtoms.size;
|
|
683
687
|
try {
|
|
684
688
|
for (var _len7 = arguments.length, args = new Array(_len7 > 2 ? _len7 - 2 : 0), _key7 = 2; _key7 < _len7; _key7++) {
|
|
685
689
|
args[_key7 - 2] = arguments[_key7];
|
|
686
690
|
}
|
|
687
691
|
return writeAtomState.apply(void 0, [store, atom].concat(args));
|
|
688
692
|
} finally {
|
|
689
|
-
|
|
690
|
-
|
|
693
|
+
if (changedAtoms.size !== prevChangedAtomsSize) {
|
|
694
|
+
recomputeInvalidatedAtoms(store);
|
|
695
|
+
flushCallbacks(store);
|
|
696
|
+
}
|
|
691
697
|
}
|
|
692
698
|
};
|
|
693
699
|
var BUILDING_BLOCK_storeSub = function BUILDING_BLOCK_storeSub(store, atom, listener) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).jotaiVanillaInternals={})}(this,function(n){"use strict";function e(n,e){(null==e||e>n.length)&&(e=n.length);for(var r=0,t=Array(e);r<e;r++)t[r]=n[r];return t}function r(n,r){var t="undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(t)return(t=t.call(n)).next.bind(t);if(Array.isArray(n)||(t=function(n,r){if(n){if("string"==typeof n)return e(n,r);var t={}.toString.call(n).slice(8,-1);return"Object"===t&&n.constructor&&(t=n.constructor.name),"Map"===t||"Set"===t?Array.from(n):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?e(n,r):void 0}}(n))||r){t&&(n=t);var a=0;return function(){return a>=n.length?{done:!0}:{done:!1,value:n[a++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function t(n){return"init"in n}function a(n){return!!n.write}function o(n){return"v"in n||"e"in n}function i(n){if("e"in n)throw n.e;return n.v}function u(n){return"function"==typeof(null==n?void 0:n.then)}function f(n,e,r){if(!r.p.has(n)){r.p.add(n);var t=function(){return r.p.delete(n)};e.then(t,t)}}function l(n,e,t){for(var a,o=new Set,i=r((null==(u=t.get(n))?void 0:u.t)||[]);!(a=i()).done;){var u,f=a.value;o.add(f)}for(var l,d=r(e.p);!(l=d()).done;){var v=l.value;o.add(v)}return o}var d=function(){var n={},e=new WeakMap,r=function(r){var t,a;null==(t=e.get(n))||t.forEach(function(n){return n(r)}),null==(a=e.get(r))||a.forEach(function(n){return n()})};return r.add=function(r,t){var a=r||n,o=e.get(a);return o||(o=new Set,e.set(a,o)),o.add(t),function(){o.delete(t),o.size||e.delete(a)}},r};var v=function(n,e){for(var r=arguments.length,t=new Array(r>2?r-2:0),a=2;a<r;a++)t[a-2]=arguments[a];return e.read.apply(e,t)},c=function(n,e){for(var r=arguments.length,t=new Array(r>2?r-2:0),a=2;a<r;a++)t[a-2]=arguments[a];return e.write.apply(e,t)},s=function(n,e){return null==e.INTERNAL_onInit?void 0:e.INTERNAL_onInit(n)},y=function(n,e,r){return null==e.onMount?void 0:e.onMount(r)},h=function(n,e){var r=
|
|
1
|
+
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).jotaiVanillaInternals={})}(this,function(n){"use strict";function e(n,e){(null==e||e>n.length)&&(e=n.length);for(var r=0,t=Array(e);r<e;r++)t[r]=n[r];return t}function r(n,r){var t="undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(t)return(t=t.call(n)).next.bind(t);if(Array.isArray(n)||(t=function(n,r){if(n){if("string"==typeof n)return e(n,r);var t={}.toString.call(n).slice(8,-1);return"Object"===t&&n.constructor&&(t=n.constructor.name),"Map"===t||"Set"===t?Array.from(n):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?e(n,r):void 0}}(n))||r){t&&(n=t);var a=0;return function(){return a>=n.length?{done:!0}:{done:!1,value:n[a++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function t(n){return"init"in n}function a(n){return!!n.write}function o(n){return"v"in n||"e"in n}function i(n){if("e"in n)throw n.e;return n.v}function u(n){return"function"==typeof(null==n?void 0:n.then)}function f(n,e,r){if(!r.p.has(n)){r.p.add(n);var t=function(){return r.p.delete(n)};e.then(t,t)}}function l(n,e,t){for(var a,o=new Set,i=r((null==(u=t.get(n))?void 0:u.t)||[]);!(a=i()).done;){var u,f=a.value;o.add(f)}for(var l,d=r(e.p);!(l=d()).done;){var v=l.value;o.add(v)}return o}var d=function(){var n={},e=new WeakMap,r=function(r){var t,a;null==(t=e.get(n))||t.forEach(function(n){return n(r)}),null==(a=e.get(r))||a.forEach(function(n){return n()})};return r.add=function(r,t){var a=r||n,o=e.get(a);return o||(o=new Set,e.set(a,o)),o.add(t),function(){o.delete(t),o.size||e.delete(a)}},r};var v=function(n,e){for(var r=arguments.length,t=new Array(r>2?r-2:0),a=2;a<r;a++)t[a-2]=arguments[a];return e.read.apply(e,t)},c=function(n,e){for(var r=arguments.length,t=new Array(r>2?r-2:0),a=2;a<r;a++)t[a-2]=arguments[a];return e.write.apply(e,t)},s=function(n,e){return null==e.INTERNAL_onInit?void 0:e.INTERNAL_onInit(n)},y=function(n,e,r){return null==e.onMount?void 0:e.onMount(r)},h=function(n,e){var r=M(n),t=r[0],a=r[6],o=r[9],i=t.get(e);return i||(i={d:new Map,p:new Set,n:0},t.set(e,i),null==a.i||a.i(e),null==o||o(n,e)),i},p=function(n){var e=M(n),r=e[1],t=e[3],a=e[4],o=e[5],i=e[6],u=e[13],f=[],l=function(n){try{n()}catch(n){f.push(n)}},d=function(){i.f&&l(i.f);var e=new Set,f=e.add.bind(e);t.forEach(function(n){var e;return null==(e=r.get(n))?void 0:e.l.forEach(f)}),t.clear(),o.forEach(f),o.clear(),a.forEach(f),a.clear(),e.forEach(l),t.size&&u(n)};do{d()}while(t.size||o.size||a.size);if(f.length)throw new AggregateError(f)},g=function(n){for(var e=M(n),t=e[1],a=e[2],o=e[3],i=e[11],u=e[14],f=e[17],d=[],v=new WeakSet,c=new WeakSet,s=Array.from(o);s.length;){var y=s[s.length-1],h=i(n,y);if(c.has(y))s.pop();else if(v.has(y))a.get(y)===h.n&&d.push([y,h]),c.add(y),s.pop();else{v.add(y);for(var p,g=r(l(y,h,t));!(p=g()).done;){var w=p.value;v.has(w)||s.push(w)}}}for(var A=d.length-1;A>=0;--A){for(var m,E=d[A],S=E[0],b=E[1],N=!1,k=r(b.d.keys());!(m=k()).done;){var I=m.value;if(I!==S&&o.has(I)){N=!0;break}}N&&(a.set(S,b.n),u(n,S),f(n,S)),a.delete(S)}},w=(new WeakSet,function(n,e){var l=M(n),d=l[1],v=l[2],c=l[3],s=l[6],y=l[7],h=l[11],p=l[12],g=l[13],w=l[14],A=l[16],m=l[17],E=l[20],S=l[26],b=h(n,e);if(o(b)){if(d.has(e)&&v.get(e)!==b.n)return b;for(var N,k=!1,I=r(b.d);!(N=I()).done;){var T=N.value,R=T[0],L=T[1];if(w(n,R).n!==L){k=!0;break}}if(!k)return b}var z,_,W=!0,j=new Set(b.d.keys()),x=new Map,O=function(){for(var n,e=r(j);!(n=e()).done;){var t=n.value;x.has(t)||b.d.delete(t)}},P=function(){if(d.has(e)){var r=!c.size;m(n,e),r&&(g(n),p(n))}},V={get signal(){return z||(z=new AbortController),z.signal},get setSelf(){return!_&&a(e)&&(_=function(){if(!W)try{for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];return A.apply(void 0,[n,e].concat(t))}finally{g(n),p(n)}}),_}},B=b.n,C=v.get(e)===B;try{0;var D=y(n,e,function(r){if(r===e){var a=h(n,r);if(!o(a)){if(!t(r))throw new Error("no atom init");E(n,r,r.init)}return i(a)}var l=w(n,r);try{return i(l)}finally{var v;x.set(r,l.n),b.d.set(r,l.n),u(b.v)&&f(e,b.v,l),d.has(e)&&(null==(v=d.get(r))||v.t.add(e)),W||P()}},V);if(E(n,e,D),u(D)){S(n,D,function(){var n;return null==(n=z)?void 0:n.abort()});var H=function(){O(),P()};D.then(H,H)}else O();return null==s.r||s.r(e),b}catch(n){return delete b.v,b.e=n,++b.n,b}finally{W=!1,b.n!==B&&C&&(v.set(e,b.n),c.add(e),null==s.c||s.c(e))}}),A=function(n,e){for(var t=M(n),a=t[1],o=t[2],i=t[11],u=[e];u.length;)for(var f,d=u.pop(),v=r(l(d,i(n,d),a));!(f=v()).done;){var c=f.value,s=i(n,c);o.get(c)!==s.n&&(o.set(c,s.n),u.push(c))}},m=function(n,e){var r=M(n),a=r[3],o=r[6],u=r[8],f=r[11],l=r[12],d=r[13],v=r[14],c=r[15],s=r[16],y=r[17],h=r[20],p=!0;try{for(var g=arguments.length,w=new Array(g>2?g-2:0),A=2;A<g;A++)w[A-2]=arguments[A];return u.apply(void 0,[n,e,function(e){return i(v(n,e))},function(r){var i=f(n,r);try{for(var u=arguments.length,v=new Array(u>1?u-1:0),g=1;g<u;g++)v[g-1]=arguments[g];if(r===e){if(!t(r))throw new Error("atom not writable");var w=i.n,A=v[0];return h(n,r,A),y(n,r),void(w!==i.n&&(a.add(r),c(n,r),null==o.c||o.c(r)))}return s.apply(void 0,[n,r].concat(v))}finally{p||(d(n),l(n))}}].concat(w))}finally{p=!1}},E=function(n,e){var t=M(n),a=t[1],o=t[3],i=t[6],u=t[11],f=t[15],l=t[18],d=t[19],v=u(n,e),c=a.get(e);if(c){for(var s,y=r(v.d);!(s=y()).done;){var h=s.value,p=h[0],g=h[1];if(!c.d.has(p)){var w=u(n,p);l(n,p).t.add(e),c.d.add(p),g!==w.n&&(o.add(p),f(n,p),null==i.c||i.c(p))}}for(var A,m=r(c.d);!(A=m()).done;){var E=A.value;if(!v.d.has(E)){c.d.delete(E);var S=d(n,E);null==S||S.t.delete(e)}}}},S=function(n,e){var t=M(n),o=t[1],i=t[4],u=t[6],f=t[10],l=t[11],d=t[12],v=t[13],c=t[14],s=t[16],y=t[18],h=l(n,e),p=o.get(e);if(!p){c(n,e);for(var g,w=r(h.d.keys());!(g=w()).done;){var A=g.value;y(n,A).t.add(e)}if(p={l:new Set,d:new Set(h.d.keys()),t:new Set},o.set(e,p),a(e)){i.add(function(){var r=!0;try{var t=f(n,e,function(){try{for(var t=arguments.length,a=new Array(t),o=0;o<t;o++)a[o]=arguments[o];return s.apply(void 0,[n,e].concat(a))}finally{r||(v(n),d(n))}});t&&(p.u=function(){r=!0;try{t()}finally{r=!1}})}finally{r=!1}})}null==u.m||u.m(e)}return p},b=function(n,e){var t=M(n),a=t[1],o=t[5],i=t[6],u=t[11],f=t[19],l=u(n,e),d=a.get(e);if(!d||d.l.size)return d;for(var v,c=!1,s=r(d.t);!(v=s()).done;){var y,h=v.value;if(null!=(y=a.get(h))&&y.d.has(e)){c=!0;break}}if(c)return d;d.u&&o.add(d.u),d=void 0,a.delete(e);for(var p,g=r(l.d.keys());!(p=g()).done;){var w=f(n,p.value);null==w||w.t.delete(e)}null==i.u||i.u(e)},N=function(n,e,t){var a=M(n),o=a[11],i=a[27],l=o(n,e),d="v"in l,v=l.v;if(u(t))for(var c,s=r(l.d.keys());!(c=s()).done;){f(e,t,o(n,c.value))}l.v=t,delete l.e,d&&Object.is(v,l.v)||(++l.n,u(v)&&i(n,v))},k=function(n,e){return i((0,M(n)[14])(n,e))},I=function(n,e){var r=M(n),t=r[3],a=r[12],o=r[13],i=r[16],u=t.size;try{for(var f=arguments.length,l=new Array(f>2?f-2:0),d=2;d<f;d++)l[d-2]=arguments[d];return i.apply(void 0,[n,e].concat(l))}finally{t.size!==u&&(o(n),a(n))}},T=function(n,e,r){var t=M(n),a=t[12],o=t[18],i=t[19],u=o(n,e).l;return u.add(r),a(n),function(){u.delete(r),i(n,e),a(n)}},R=function(n,e,r){var t=M(n)[25],a=t.get(e);if(!a){a=new Set,t.set(e,a);var o=function(){return t.delete(e)};e.then(o,o)}a.add(r)},L=function(n,e){var r=M(n)[25].get(e);null==r||r.forEach(function(n){return n()})},z=new WeakMap,M=function(n){return z.get(n)};n.INTERNAL_addPendingPromiseToDependency=f,n.INTERNAL_buildStoreRev2=function(){for(var n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];var t={get:function(n){return(0,M(t)[21])(t,n)},set:function(n){for(var e=M(t)[22],r=arguments.length,a=new Array(r>1?r-1:0),o=1;o<r;o++)a[o-1]=arguments[o];return e.apply(void 0,[t,n].concat(a))},sub:function(n,e){return(0,M(t)[23])(t,n,e)}},a=[new WeakMap,new WeakMap,new WeakMap,new Set,new Set,new Set,{},v,c,s,y,h,p,g,w,A,m,E,S,b,N,k,I,T,void 0,new WeakMap,R,L].map(function(n,r){return e[r]||n});return z.set(t,Object.freeze(a)),t},n.INTERNAL_getBuildingBlocksRev2=function(n){var e=M(n),r=e[24];return r?r(e):e},n.INTERNAL_getMountedOrPendingDependents=l,n.INTERNAL_hasInitialValue=t,n.INTERNAL_initializeStoreHooksRev2=function(n){var e,r,t,a,o,i,u,f;return(e=n).i||(e.i=d()),(r=n).r||(r.r=d()),(t=n).c||(t.c=d()),(a=n).m||(a.m=d()),(o=n).u||(o.u=d()),(i=n).f||(i.f=(u=new Set,(f=function(){return u.forEach(function(n){return n()})}).add=function(n){return u.add(n),function(){return u.delete(n)}},f)),n},n.INTERNAL_isActuallyWritableAtom=a,n.INTERNAL_isAtomStateInitialized=o,n.INTERNAL_isPromiseLike=u,n.INTERNAL_returnAtomValue=i});
|
|
@@ -514,11 +514,7 @@
|
|
|
514
514
|
}
|
|
515
515
|
baseAtom.onMount = function (setAtom) {
|
|
516
516
|
setAtom(storage.getItem(key, initialValue));
|
|
517
|
-
|
|
518
|
-
if (storage.subscribe) {
|
|
519
|
-
unsub = storage.subscribe(key, setAtom, initialValue);
|
|
520
|
-
}
|
|
521
|
-
return unsub;
|
|
517
|
+
return storage.subscribe == null ? void 0 : storage.subscribe(key, setAtom, initialValue);
|
|
522
518
|
};
|
|
523
519
|
var anAtom = vanilla.atom(function (get) {
|
|
524
520
|
return get(baseAtom);
|
|
@@ -553,10 +549,7 @@
|
|
|
553
549
|
var observableResultAtom = vanilla.atom(function (get) {
|
|
554
550
|
var _Symbol$observable, _ref;
|
|
555
551
|
var observable = getObservable(get);
|
|
556
|
-
var
|
|
557
|
-
if (itself) {
|
|
558
|
-
observable = itself;
|
|
559
|
-
}
|
|
552
|
+
var subscribable = ((_Symbol$observable = (_ref = observable)[Symbol.observable]) == null ? void 0 : _Symbol$observable.call(_ref)) || observable;
|
|
560
553
|
var resolve;
|
|
561
554
|
var makePending = function makePending() {
|
|
562
555
|
return new Promise(function (r) {
|
|
@@ -589,7 +582,7 @@
|
|
|
589
582
|
clearTimeout(timer);
|
|
590
583
|
subscription.unsubscribe();
|
|
591
584
|
}
|
|
592
|
-
subscription =
|
|
585
|
+
subscription = subscribable.subscribe({
|
|
593
586
|
next: function next(d) {
|
|
594
587
|
return listener({
|
|
595
588
|
d: d
|
|
@@ -1 +1 @@
|
|
|
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=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={}.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){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.")}function i(){return i=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var r in e)({}).hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t},i.apply(null,arguments)}var a=function(t,n,e){return(n.has(e)?n:n.set(e,t())).get(e)},u=new WeakMap;var f=new WeakSet,c=function(t){if("object"!=typeof t||null===t)return t;Object.freeze(t);for(var n,e=o(Object.getOwnPropertyNames(t));!(n=e()).done;){var r=n.value;c(t[r])}return t};function l(t){if(f.has(t))return t;f.add(t);var n=t.read;if(t.read=function(t,e){return c(n.call(this,t,e))},"write"in t){var e=t.write;t.write=function(n,r){for(var o=arguments.length,i=new Array(o>2?o-2:0),a=2;a<o;a++)i[a-2]=arguments[a];return e.call.apply(e,[this,n,function(){for(var n=arguments.length,e=new Array(n),o=0;o<n;o++)e[o]=arguments[o];return e[0]===t&&(e[1]=c(e[1])),r.apply(void 0,e)}].concat(i))}}return t}var v=function(t,n,e){return(n.has(e)?n:n.set(e,t())).get(e)},s=new WeakMap,d={},m=function(t){return!!t.write};var h=function(t){return"function"==typeof(null==t?void 0:t.then)};function p(t,n){var e,r;void 0===t&&(t=function(){try{return window.localStorage}catch(t){return}});var o,i={getItem:function(o,i){var a,u,f=function(t){if(e!==(t=t||"")){try{r=JSON.parse(t,null==n?void 0:n.reviver)}catch(t){return i}e=t}return r},c=null!=(a=null==(u=t())?void 0:u.getItem(o))?a:null;return h(c)?c.then(f):f(c)},setItem:function(e,r){var o;return null==(o=t())?void 0:o.setItem(e,JSON.stringify(r,null==n?void 0:n.replacer))},removeItem:function(n){var e;return null==(e=t())?void 0:e.removeItem(n)}};try{var a;o=null==(a=t())?void 0:a.subscribe}catch(t){}return!o&&"undefined"!=typeof window&&"function"==typeof window.addEventListener&&window.Storage&&(o=function(n,e){if(!(t()instanceof window.Storage))return function(){};var r=function(r){r.storageArea===t()&&r.key===n&&e(r.newValue)};return window.addEventListener("storage",r),function(){window.removeEventListener("storage",r)}}),o&&(i.subscribe=function(t){return function(n,e,r){return t(n,function(t){var n;try{n=JSON.parse(t||"")}catch(t){n=r}e(n)})}}(o)),i}var y=p();var b=function(t,n,e){return(n.has(e)?n:n.set(e,t())).get(e)},w=new WeakMap,g=function(){};function O(t,e){return void 0===e&&(e=g),r=function(){var r=new WeakMap,o=new WeakMap,i=n.atom(0),a=n.atom([]);a.INTERNAL_onInit=function(t){t.set(a,[function(){return t.set(i,function(t){return t+1})}])};var u=n.atom(function(n){var f,c;n(i);try{c=n(u)}catch(t){}var l,v=n(t);if("function"!=typeof(null==(l=v)?void 0:l.then))return{v:v};if(v!==(null==(f=c)?void 0:f.p)&&v.then(function(t){o.set(v,t),(0,n(a)[0])()},function(t){r.set(v,t),(0,n(a)[0])()}),r.has(v))throw r.get(v);return o.has(v)?{p:v,v:o.get(v)}:c&&"v"in c?{p:v,f:e(c.v),v:c.v}:{p:v,f:e()}});return u.init=void 0,n.atom(function(t){var n=t(u);return"f"in n?n.f:n.v},function(n,e){for(var r=arguments.length,o=new Array(r>2?r-2:0),i=2;i<r;i++)o[i-2]=arguments[i];return e.apply(void 0,[t].concat(o))})},o=e,i=b(function(){return new WeakMap},w,t),b(r,i,o);var r,o,i}var k=new WeakMap;t.RESET=e,t.atomFamily=function(t,n){var e=null,r=new Map,i=new Set,a=function(i){var f;if(void 0===n)f=r.get(i);else for(var c,l=o(r);!(c=l()).done;){var v=c.value,s=v[0],d=v[1];if(n(s,i)){f=d;break}}if(void 0!==f){if(null==e||!e(f[1],i))return f[0];a.remove(i)}var m=t(i);return r.set(i,[m,Date.now()]),u("CREATE",i,m),m},u=function(t,n,e){for(var r,a=o(i);!(r=a()).done;){(0,r.value)({type:t,param:n,atom:e})}};return a.unstable_listen=function(t){return i.add(t),function(){i.delete(t)}},a.getParams=function(){return r.keys()},a.remove=function(t){if(void 0===n){if(!r.has(t))return;var e=r.get(t)[0];r.delete(t),u("REMOVE",t,e)}else for(var i,a=o(r);!(i=a()).done;){var f=i.value,c=f[0],l=f[1][0];if(n(c,t)){r.delete(c),u("REMOVE",c,l);break}}},a.setShouldRemove=function(t){if(e=t)for(var n,i=o(r);!(n=i()).done;){var a=n.value,f=a[0],c=a[1],l=c[0],v=c[1];e(v,f)&&(r.delete(f),u("REMOVE",f,l))}},a},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){var u="function"==typeof a?a(t(i)):a;n(o,u===e?r:u)});return i},t.atomWithLazy=function(t){var e=n.atom(void 0);return delete e.init,Object.defineProperty(e,"init",{get:function(){return t()}}),e},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,v,s,d=function(){return new Promise(function(t){a=t})},m=e&&"initialValue"in e?{d:"function"==typeof e.initialValue?e.initialValue():e.initialValue}:d(),h=function(t){l=t,null==a||a(t),null==c||c(t)},p=function(){return!c},y=function(){v&&(v.unsubscribe(),v=void 0)},b=function(){v&&(clearTimeout(s),v.unsubscribe()),v=u.subscribe({next:function(t){return h({d:t})},error:function(t){return h({e:t})},complete:function(){}}),p()&&null!=e&&e.unstable_timeout&&(s=setTimeout(y,e.unstable_timeout))};b();var w=n.atom(l||m);return w.onMount=function(t){return c=t,l&&t(l),v?clearTimeout(s):b(),function(){c=void 0,null!=e&&e.unstable_timeout?s=setTimeout(y,e.unstable_timeout):y()}},[w,u,d,b,p]});return n.atom(function(t){var n,e=t(o),i=t(e[0]);return"function"==typeof(null==(n=i)?void 0:n.then)?i.then(r):r(i)},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){return n.atom(t,function(t,n,r){n(this,e(t(this),r))})},t.atomWithRefresh=function(t,e){var r=n.atom(0);return n.atom(function(n,e){return n(r),t(n,e)},function(t,n){for(var o=arguments.length,i=new Array(o>2?o-2:0),a=2;a<o;a++)i[a-2]=arguments[a];if(0===i.length)n(r,function(t){return t+1});else if(e)return e.apply(void 0,[t,n].concat(i))})},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=y);var a=null==i?void 0:i.getOnInit,u=n.atom(a?o.getItem(t,r):r);return u.onMount=function(n){var e;return 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)):h(f)?f.then(function(n){return i(u,n),o.setItem(t,n)}):(i(u,f),o.setItem(t,f))})},t.createJSONStorage=p,t.freezeAtom=l,t.freezeAtomCreator=function(t){return function(){return l(t.apply(void 0,arguments))}},t.loadable=function(t){return e=function(){var e={state:"loading"},r=O(t,function(){return e});return n.atom(function(t){try{var n=t(r);return n===e?e:{state:"hasData",data:n}}catch(t){return{state:"hasError",error:t}}})},r=t,(k.has(r)?k:k.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=n.atom(function(n){var a=n(i);return 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}([n(t),a])});return i.init=o,i},i=e,f=r,c=a(function(){return new WeakMap},u,t),l=a(function(){return new WeakMap},c,i),a(o,l,f);var o,i,f,c,l},t.splitAtom=function(t,e){return r=function(){var r=new WeakMap,o=function(a,u){var f=r.get(a);if(f)return f;var c=u&&r.get(u),l=[],v=[];return a.forEach(function(r,u){var f=e?e(r):u;v[u]=f;var s=c&&c.atomList[c.keyList.indexOf(f)];if(s)l[u]=s;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]=m(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===v.length&&c.keyList.every(function(t,n){return t===v[n]})?c:{arr:a,atomList:l,keyList:v},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=m(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 v=n(t);e(t,c<l?[].concat(v.slice(0,c),v.slice(c+1,l),[v[c]],v.slice(l)):[].concat(v.slice(0,l),[v[c]],v.slice(l,c),v.slice(c+1)))}}}):n.atom(function(t){return t(i).atomList});return a},o=e||d,i=v(function(){return new WeakMap},s,t),v(r,i,o);var r,o,i},t.unstable_withStorageValidator=function(t){return function(n){return i({},n,{getItem:function(e,r){var o=function(n){return t(n)?n:r},i=n.getItem(e,r);return h(i)?i.then(o):o(i)}})}},t.unwrap=O});
|
|
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=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={}.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){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.")}function i(){return i=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var r in e)({}).hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t},i.apply(null,arguments)}var a=function(t,n,e){return(n.has(e)?n:n.set(e,t())).get(e)},u=new WeakMap;var f=new WeakSet,c=function(t){if("object"!=typeof t||null===t)return t;Object.freeze(t);for(var n,e=o(Object.getOwnPropertyNames(t));!(n=e()).done;){var r=n.value;c(t[r])}return t};function l(t){if(f.has(t))return t;f.add(t);var n=t.read;if(t.read=function(t,e){return c(n.call(this,t,e))},"write"in t){var e=t.write;t.write=function(n,r){for(var o=arguments.length,i=new Array(o>2?o-2:0),a=2;a<o;a++)i[a-2]=arguments[a];return e.call.apply(e,[this,n,function(){for(var n=arguments.length,e=new Array(n),o=0;o<n;o++)e[o]=arguments[o];return e[0]===t&&(e[1]=c(e[1])),r.apply(void 0,e)}].concat(i))}}return t}var v=function(t,n,e){return(n.has(e)?n:n.set(e,t())).get(e)},s=new WeakMap,d={},m=function(t){return!!t.write};var h=function(t){return"function"==typeof(null==t?void 0:t.then)};function p(t,n){var e,r;void 0===t&&(t=function(){try{return window.localStorage}catch(t){return}});var o,i={getItem:function(o,i){var a,u,f=function(t){if(e!==(t=t||"")){try{r=JSON.parse(t,null==n?void 0:n.reviver)}catch(t){return i}e=t}return r},c=null!=(a=null==(u=t())?void 0:u.getItem(o))?a:null;return h(c)?c.then(f):f(c)},setItem:function(e,r){var o;return null==(o=t())?void 0:o.setItem(e,JSON.stringify(r,null==n?void 0:n.replacer))},removeItem:function(n){var e;return null==(e=t())?void 0:e.removeItem(n)}};try{var a;o=null==(a=t())?void 0:a.subscribe}catch(t){}return!o&&"undefined"!=typeof window&&"function"==typeof window.addEventListener&&window.Storage&&(o=function(n,e){if(!(t()instanceof window.Storage))return function(){};var r=function(r){r.storageArea===t()&&r.key===n&&e(r.newValue)};return window.addEventListener("storage",r),function(){window.removeEventListener("storage",r)}}),o&&(i.subscribe=function(t){return function(n,e,r){return t(n,function(t){var n;try{n=JSON.parse(t||"")}catch(t){n=r}e(n)})}}(o)),i}var y=p();var b=function(t,n,e){return(n.has(e)?n:n.set(e,t())).get(e)},w=new WeakMap,g=function(){};function O(t,e){return void 0===e&&(e=g),r=function(){var r=new WeakMap,o=new WeakMap,i=n.atom(0),a=n.atom([]);a.INTERNAL_onInit=function(t){t.set(a,[function(){return t.set(i,function(t){return t+1})}])};var u=n.atom(function(n){var f,c;n(i);try{c=n(u)}catch(t){}var l,v=n(t);if("function"!=typeof(null==(l=v)?void 0:l.then))return{v:v};if(v!==(null==(f=c)?void 0:f.p)&&v.then(function(t){o.set(v,t),(0,n(a)[0])()},function(t){r.set(v,t),(0,n(a)[0])()}),r.has(v))throw r.get(v);return o.has(v)?{p:v,v:o.get(v)}:c&&"v"in c?{p:v,f:e(c.v),v:c.v}:{p:v,f:e()}});return u.init=void 0,n.atom(function(t){var n=t(u);return"f"in n?n.f:n.v},function(n,e){for(var r=arguments.length,o=new Array(r>2?r-2:0),i=2;i<r;i++)o[i-2]=arguments[i];return e.apply(void 0,[t].concat(o))})},o=e,i=b(function(){return new WeakMap},w,t),b(r,i,o);var r,o,i}var k=new WeakMap;t.RESET=e,t.atomFamily=function(t,n){var e=null,r=new Map,i=new Set,a=function(i){var f;if(void 0===n)f=r.get(i);else for(var c,l=o(r);!(c=l()).done;){var v=c.value,s=v[0],d=v[1];if(n(s,i)){f=d;break}}if(void 0!==f){if(null==e||!e(f[1],i))return f[0];a.remove(i)}var m=t(i);return r.set(i,[m,Date.now()]),u("CREATE",i,m),m},u=function(t,n,e){for(var r,a=o(i);!(r=a()).done;){(0,r.value)({type:t,param:n,atom:e})}};return a.unstable_listen=function(t){return i.add(t),function(){i.delete(t)}},a.getParams=function(){return r.keys()},a.remove=function(t){if(void 0===n){if(!r.has(t))return;var e=r.get(t)[0];r.delete(t),u("REMOVE",t,e)}else for(var i,a=o(r);!(i=a()).done;){var f=i.value,c=f[0],l=f[1][0];if(n(c,t)){r.delete(c),u("REMOVE",c,l);break}}},a.setShouldRemove=function(t){if(e=t)for(var n,i=o(r);!(n=i()).done;){var a=n.value,f=a[0],c=a[1],l=c[0],v=c[1];e(v,f)&&(r.delete(f),u("REMOVE",f,l))}},a},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){var u="function"==typeof a?a(t(i)):a;n(o,u===e?r:u)});return i},t.atomWithLazy=function(t){var e=n.atom(void 0);return delete e.init,Object.defineProperty(e,"init",{get:function(){return t()}}),e},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,f,c,l,v=t(r),s=(null==(o=(i=v)[Symbol.observable])?void 0:o.call(i))||v,d=function(){return new Promise(function(t){a=t})},m=e&&"initialValue"in e?{d:"function"==typeof e.initialValue?e.initialValue():e.initialValue}:d(),h=function(t){f=t,null==a||a(t),null==u||u(t)},p=function(){return!u},y=function(){c&&(c.unsubscribe(),c=void 0)},b=function(){c&&(clearTimeout(l),c.unsubscribe()),c=s.subscribe({next:function(t){return h({d:t})},error:function(t){return h({e:t})},complete:function(){}}),p()&&null!=e&&e.unstable_timeout&&(l=setTimeout(y,e.unstable_timeout))};b();var w=n.atom(f||m);return w.onMount=function(t){return u=t,f&&t(f),c?clearTimeout(l):b(),function(){u=void 0,null!=e&&e.unstable_timeout?l=setTimeout(y,e.unstable_timeout):y()}},[w,v,d,b,p]});return n.atom(function(t){var n,e=t(o),i=t(e[0]);return"function"==typeof(null==(n=i)?void 0:n.then)?i.then(r):r(i)},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){return n.atom(t,function(t,n,r){n(this,e(t(this),r))})},t.atomWithRefresh=function(t,e){var r=n.atom(0);return n.atom(function(n,e){return n(r),t(n,e)},function(t,n){for(var o=arguments.length,i=new Array(o>2?o-2:0),a=2;a<o;a++)i[a-2]=arguments[a];if(0===i.length)n(r,function(t){return t+1});else if(e)return e.apply(void 0,[t,n].concat(i))})},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=y);var a=null==i?void 0:i.getOnInit,u=n.atom(a?o.getItem(t,r):r);return u.onMount=function(n){return n(o.getItem(t,r)),null==o.subscribe?void 0:o.subscribe(t,n,r)},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)):h(f)?f.then(function(n){return i(u,n),o.setItem(t,n)}):(i(u,f),o.setItem(t,f))})},t.createJSONStorage=p,t.freezeAtom=l,t.freezeAtomCreator=function(t){return function(){return l(t.apply(void 0,arguments))}},t.loadable=function(t){return e=function(){var e={state:"loading"},r=O(t,function(){return e});return n.atom(function(t){try{var n=t(r);return n===e?e:{state:"hasData",data:n}}catch(t){return{state:"hasError",error:t}}})},r=t,(k.has(r)?k:k.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=n.atom(function(n){var a=n(i);return 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}([n(t),a])});return i.init=o,i},i=e,f=r,c=a(function(){return new WeakMap},u,t),l=a(function(){return new WeakMap},c,i),a(o,l,f);var o,i,f,c,l},t.splitAtom=function(t,e){return r=function(){var r=new WeakMap,o=function(a,u){var f=r.get(a);if(f)return f;var c=u&&r.get(u),l=[],v=[];return a.forEach(function(r,u){var f=e?e(r):u;v[u]=f;var s=c&&c.atomList[c.keyList.indexOf(f)];if(s)l[u]=s;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]=m(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===v.length&&c.keyList.every(function(t,n){return t===v[n]})?c:{arr:a,atomList:l,keyList:v},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=m(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 v=n(t);e(t,c<l?[].concat(v.slice(0,c),v.slice(c+1,l),[v[c]],v.slice(l)):[].concat(v.slice(0,l),[v[c]],v.slice(l,c),v.slice(c+1)))}}}):n.atom(function(t){return t(i).atomList});return a},o=e||d,i=v(function(){return new WeakMap},s,t),v(r,i,o);var r,o,i},t.unstable_withStorageValidator=function(t){return function(n){return i({},n,{getItem:function(e,r){var o=function(n){return t(n)?n:r},i=n.getItem(e,r);return h(i)?i.then(o):o(i)}})}},t.unwrap=O});
|
package/vanilla/internals.js
CHANGED
|
@@ -259,6 +259,7 @@ var BUILDING_BLOCK_recomputeInvalidatedAtoms = function BUILDING_BLOCK_recompute
|
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
if (hasChangedDeps) {
|
|
262
|
+
invalidatedAtoms.set(_a, _aState.n);
|
|
262
263
|
readAtomState(store, _a);
|
|
263
264
|
mountDependencies(store, _a);
|
|
264
265
|
}
|
|
@@ -389,6 +390,7 @@ var BUILDING_BLOCK_readAtomState = function BUILDING_BLOCK_readAtomState(store,
|
|
|
389
390
|
}
|
|
390
391
|
};
|
|
391
392
|
var prevEpochNumber = atomState.n;
|
|
393
|
+
var prevInvalidated = invalidatedAtoms.get(atom) === prevEpochNumber;
|
|
392
394
|
try {
|
|
393
395
|
if (process.env.NODE_ENV !== 'production') {
|
|
394
396
|
storeMutationSet.delete(store);
|
|
@@ -420,7 +422,7 @@ var BUILDING_BLOCK_readAtomState = function BUILDING_BLOCK_readAtomState(store,
|
|
|
420
422
|
return atomState;
|
|
421
423
|
} finally {
|
|
422
424
|
isSync = false;
|
|
423
|
-
if (
|
|
425
|
+
if (atomState.n !== prevEpochNumber && prevInvalidated) {
|
|
424
426
|
invalidatedAtoms.set(atom, atomState.n);
|
|
425
427
|
changedAtoms.add(atom);
|
|
426
428
|
storeHooks.c == null || storeHooks.c(atom);
|
|
@@ -673,17 +675,21 @@ var BUILDING_BLOCK_storeGet = function BUILDING_BLOCK_storeGet(store, atom) {
|
|
|
673
675
|
};
|
|
674
676
|
var BUILDING_BLOCK_storeSet = function BUILDING_BLOCK_storeSet(store, atom) {
|
|
675
677
|
var buildingBlocks = getInternalBuildingBlocks(store);
|
|
678
|
+
var changedAtoms = buildingBlocks[3];
|
|
676
679
|
var flushCallbacks = buildingBlocks[12];
|
|
677
680
|
var recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
678
681
|
var writeAtomState = buildingBlocks[16];
|
|
682
|
+
var prevChangedAtomsSize = changedAtoms.size;
|
|
679
683
|
try {
|
|
680
684
|
for (var _len7 = arguments.length, args = new Array(_len7 > 2 ? _len7 - 2 : 0), _key7 = 2; _key7 < _len7; _key7++) {
|
|
681
685
|
args[_key7 - 2] = arguments[_key7];
|
|
682
686
|
}
|
|
683
687
|
return writeAtomState.apply(void 0, [store, atom].concat(args));
|
|
684
688
|
} finally {
|
|
685
|
-
|
|
686
|
-
|
|
689
|
+
if (changedAtoms.size !== prevChangedAtomsSize) {
|
|
690
|
+
recomputeInvalidatedAtoms(store);
|
|
691
|
+
flushCallbacks(store);
|
|
692
|
+
}
|
|
687
693
|
}
|
|
688
694
|
};
|
|
689
695
|
var BUILDING_BLOCK_storeSub = function BUILDING_BLOCK_storeSub(store, atom, listener) {
|
|
@@ -8,7 +8,7 @@ type Observer<T> = {
|
|
|
8
8
|
error: (error: AnyError) => void;
|
|
9
9
|
complete: () => void;
|
|
10
10
|
};
|
|
11
|
-
type
|
|
11
|
+
type SubscribableObservable<T> = {
|
|
12
12
|
subscribe(observer: Observer<T>): Subscription;
|
|
13
13
|
} | {
|
|
14
14
|
subscribe(observer: Partial<Observer<T>>): Subscription;
|
|
@@ -16,6 +16,10 @@ type ObservableLike<T> = {
|
|
|
16
16
|
subscribe(observer: Partial<Observer<T>>): Subscription;
|
|
17
17
|
subscribe(next: (value: T) => void): Subscription;
|
|
18
18
|
};
|
|
19
|
+
type SymbolObservable<T> = {
|
|
20
|
+
[Symbol.observable]: () => SubscribableObservable<T>;
|
|
21
|
+
};
|
|
22
|
+
type ObservableLike<T> = SubscribableObservable<T> | SymbolObservable<T>;
|
|
19
23
|
type SubjectLike<T> = ObservableLike<T> & Observer<T>;
|
|
20
24
|
type Options<Data> = {
|
|
21
25
|
initialValue?: Data | (() => Data);
|
package/vanilla/utils.js
CHANGED
|
@@ -512,11 +512,7 @@ function atomWithStorage(key, initialValue, storage, options) {
|
|
|
512
512
|
}
|
|
513
513
|
baseAtom.onMount = function (setAtom) {
|
|
514
514
|
setAtom(storage.getItem(key, initialValue));
|
|
515
|
-
|
|
516
|
-
if (storage.subscribe) {
|
|
517
|
-
unsub = storage.subscribe(key, setAtom, initialValue);
|
|
518
|
-
}
|
|
519
|
-
return unsub;
|
|
515
|
+
return storage.subscribe == null ? void 0 : storage.subscribe(key, setAtom, initialValue);
|
|
520
516
|
};
|
|
521
517
|
var anAtom = vanilla.atom(function (get) {
|
|
522
518
|
return get(baseAtom);
|
|
@@ -551,10 +547,7 @@ function atomWithObservable(getObservable, options) {
|
|
|
551
547
|
var observableResultAtom = vanilla.atom(function (get) {
|
|
552
548
|
var _Symbol$observable, _ref;
|
|
553
549
|
var observable = getObservable(get);
|
|
554
|
-
var
|
|
555
|
-
if (itself) {
|
|
556
|
-
observable = itself;
|
|
557
|
-
}
|
|
550
|
+
var subscribable = ((_Symbol$observable = (_ref = observable)[Symbol.observable]) == null ? void 0 : _Symbol$observable.call(_ref)) || observable;
|
|
558
551
|
var resolve;
|
|
559
552
|
var makePending = function makePending() {
|
|
560
553
|
return new Promise(function (r) {
|
|
@@ -587,7 +580,7 @@ function atomWithObservable(getObservable, options) {
|
|
|
587
580
|
clearTimeout(timer);
|
|
588
581
|
subscription.unsubscribe();
|
|
589
582
|
}
|
|
590
|
-
subscription =
|
|
583
|
+
subscription = subscribable.subscribe({
|
|
591
584
|
next: function next(d) {
|
|
592
585
|
return listener({
|
|
593
586
|
d: d
|