@depup/jotai 2.18.0-depup.0 → 2.19.0-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,8 +13,8 @@ npm install @depup/jotai
13
13
 
14
14
  | Field | Value |
15
15
  |-------|-------|
16
- | Original | [jotai](https://www.npmjs.com/package/jotai) @ 2.18.0 |
17
- | Processed | 2026-03-09 |
16
+ | Original | [jotai](https://www.npmjs.com/package/jotai) @ 2.19.0 |
17
+ | Processed | 2026-03-24 |
18
18
  | Smoke test | failed |
19
19
  | Deps updated | 0 |
20
20
 
package/changes.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "bumped": {},
3
- "timestamp": "2026-03-09T03:53:56.313Z",
3
+ "timestamp": "2026-03-24T08:21:53.715Z",
4
4
  "totalUpdated": 0
5
5
  }
@@ -1,6 +1,7 @@
1
1
  import type { Atom, ExtractAtomValue } from 'jotai/vanilla';
2
2
  import { useStore } from './Provider.mjs';
3
3
  type Options = Parameters<typeof useStore>[0] & {
4
+ /** @deprecated delay option is deprecated and will be removed in v3. https://github.com/pmndrs/jotai/pull/3264 */
4
5
  delay?: number;
5
6
  unstable_promiseStatus?: boolean;
6
7
  };
package/esm/react.mjs CHANGED
@@ -134,6 +134,28 @@ function useAtomValue(atom, options) {
134
134
  }
135
135
  }
136
136
  if (typeof delay === "number") {
137
+ console.warn(`[DEPRECATED] delay option is deprecated and will be removed in v3.
138
+
139
+ Migration guide:
140
+
141
+ Create a custom hook like the following.
142
+
143
+ function useAtomValueWithDelay<Value>(
144
+ atom: Atom<Value>,
145
+ options: { delay: number },
146
+ ): Value {
147
+ const { delay } = options
148
+ const store = useStore(options)
149
+ const [value, setValue] = useState(() => store.get(atom))
150
+ useEffect(() => {
151
+ const unsub = store.sub(atom, () => {
152
+ setTimeout(() => setValue(store.get(atom)), delay)
153
+ })
154
+ return unsub
155
+ }, [store, atom, delay])
156
+ return value
157
+ }
158
+ `);
137
159
  setTimeout(rerender, delay);
138
160
  return;
139
161
  }
@@ -27,6 +27,8 @@ type AtomState<Value = AnyValue> = {
27
27
  readonly p: Set<AnyAtom>;
28
28
  /** The epoch number of the atom. */
29
29
  n: EpochNumber;
30
+ /** The store epoch number that last validated the atom. */
31
+ m?: EpochNumber;
30
32
  /** Atom value */
31
33
  v?: Value;
32
34
  /** Atom error */
@@ -89,6 +91,7 @@ type EnhanceBuildingBlocks = (buildingBlocks: Readonly<BuildingBlocks>) => Reado
89
91
  type AbortHandlersMap = WeakMapLike<PromiseLike<unknown>, Set<() => void>>;
90
92
  type RegisterAbortHandler = <T>(store: Store, promise: PromiseLike<T>, abortHandler: () => void) => void;
91
93
  type AbortPromise = <T>(store: Store, promise: PromiseLike<T>) => void;
94
+ type StoreEpochHolder = [n: EpochNumber];
92
95
  type Store = {
93
96
  get: <Value>(atom: Atom<Value>) => Value;
94
97
  set: <Value, Args extends unknown[], Result>(atom: WritableAtom<Value, Args, Result>, ...args: Args) => Result;
@@ -122,7 +125,8 @@ type BuildingBlocks = [
122
125
  enhanceBuildingBlocks: EnhanceBuildingBlocks | undefined,
123
126
  abortHandlersMap: AbortHandlersMap,
124
127
  registerAbortHandler: RegisterAbortHandler,
125
- abortPromise: AbortPromise
128
+ abortPromise: AbortPromise,
129
+ storeEpochHolder: StoreEpochHolder
126
130
  ];
127
131
  export type { AtomState as INTERNAL_AtomState, Mounted as INTERNAL_Mounted, AtomStateMap as INTERNAL_AtomStateMap, MountedMap as INTERNAL_MountedMap, InvalidatedAtoms as INTERNAL_InvalidatedAtoms, ChangedAtoms as INTERNAL_ChangedAtoms, Callbacks as INTERNAL_Callbacks, AtomRead as INTERNAL_AtomRead, AtomWrite as INTERNAL_AtomWrite, AtomOnInit as INTERNAL_AtomOnInit, AtomOnMount as INTERNAL_AtomOnMount, EnsureAtomState as INTERNAL_EnsureAtomState, FlushCallbacks as INTERNAL_FlushCallbacks, RecomputeInvalidatedAtoms as INTERNAL_RecomputeInvalidatedAtoms, ReadAtomState as INTERNAL_ReadAtomState, InvalidateDependents as INTERNAL_InvalidateDependents, WriteAtomState as INTERNAL_WriteAtomState, MountDependencies as INTERNAL_MountDependencies, MountAtom as INTERNAL_MountAtom, UnmountAtom as INTERNAL_UnmountAtom, Store as INTERNAL_Store, BuildingBlocks as INTERNAL_BuildingBlocks, StoreHooks as INTERNAL_StoreHooks, };
128
132
  declare function hasInitialValue<T extends Atom<AnyValue>>(atom: T): atom is T & (T extends Atom<infer Value> ? {
@@ -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
  }
@@ -217,9 +218,19 @@ const BUILDING_BLOCK_readAtomState = (store, atom) => {
217
218
  const mountDependencies = buildingBlocks[17];
218
219
  const setAtomStateValueOrPromise = buildingBlocks[20];
219
220
  const registerAbortHandler = buildingBlocks[26];
221
+ const storeEpochHolder = buildingBlocks[28];
220
222
  const atomState = ensureAtomState(store, atom);
223
+ const storeEpochNumber = storeEpochHolder[0];
221
224
  if (isAtomStateInitialized(atomState)) {
222
- if (mountedMap.has(atom) && invalidatedAtoms.get(atom) !== atomState.n) {
225
+ if (
226
+ // If the atom is mounted, we can use cached atom state,
227
+ // because it should have been updated by dependencies.
228
+ // We can't use the cache if the atom is invalidated.
229
+ mountedMap.has(atom) && invalidatedAtoms.get(atom) !== atomState.n || // If atom is not mounted, we can use cached atom state,
230
+ // only if store hasn't been mutated.
231
+ atomState.m === storeEpochNumber
232
+ ) {
233
+ atomState.m = storeEpochNumber;
223
234
  return atomState;
224
235
  }
225
236
  let hasChangedDeps = false;
@@ -230,6 +241,7 @@ const BUILDING_BLOCK_readAtomState = (store, atom) => {
230
241
  }
231
242
  }
232
243
  if (!hasChangedDeps) {
244
+ atomState.m = storeEpochNumber;
233
245
  return atomState;
234
246
  }
235
247
  }
@@ -320,6 +332,7 @@ const BUILDING_BLOCK_readAtomState = (store, atom) => {
320
332
  }
321
333
  };
322
334
  const prevEpochNumber = atomState.n;
335
+ const prevInvalidated = invalidatedAtoms.get(atom) === prevEpochNumber;
323
336
  try {
324
337
  if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
325
338
  storeMutationSet.delete(store);
@@ -342,15 +355,17 @@ const BUILDING_BLOCK_readAtomState = (store, atom) => {
342
355
  pruneDependencies();
343
356
  }
344
357
  (_a = storeHooks.r) == null ? void 0 : _a.call(storeHooks, atom);
358
+ atomState.m = storeEpochNumber;
345
359
  return atomState;
346
360
  } catch (error) {
347
361
  delete atomState.v;
348
362
  atomState.e = error;
349
363
  ++atomState.n;
364
+ atomState.m = storeEpochNumber;
350
365
  return atomState;
351
366
  } finally {
352
367
  isSync = false;
353
- if (prevEpochNumber !== atomState.n && invalidatedAtoms.get(atom) === prevEpochNumber) {
368
+ if (atomState.n !== prevEpochNumber && prevInvalidated) {
354
369
  invalidatedAtoms.set(atom, atomState.n);
355
370
  changedAtoms.add(atom);
356
371
  (_b = storeHooks.c) == null ? void 0 : _b.call(storeHooks, atom);
@@ -388,6 +403,7 @@ const BUILDING_BLOCK_writeAtomState = (store, atom, ...args) => {
388
403
  const writeAtomState = buildingBlocks[16];
389
404
  const mountDependencies = buildingBlocks[17];
390
405
  const setAtomStateValueOrPromise = buildingBlocks[20];
406
+ const storeEpochHolder = buildingBlocks[28];
391
407
  let isSync = true;
392
408
  const getter = (a) => returnAtomValue(readAtomState(store, a));
393
409
  const setter = (a, ...args2) => {
@@ -406,6 +422,7 @@ const BUILDING_BLOCK_writeAtomState = (store, atom, ...args) => {
406
422
  setAtomStateValueOrPromise(store, a, v);
407
423
  mountDependencies(store, a);
408
424
  if (prevEpochNumber !== aState.n) {
425
+ ++storeEpochHolder[0];
409
426
  changedAtoms.add(a);
410
427
  invalidateDependents(store, a);
411
428
  (_a = storeHooks.c) == null ? void 0 : _a.call(storeHooks, a);
@@ -590,14 +607,18 @@ const BUILDING_BLOCK_storeGet = (store, atom) => {
590
607
  };
591
608
  const BUILDING_BLOCK_storeSet = (store, atom, ...args) => {
592
609
  const buildingBlocks = getInternalBuildingBlocks(store);
610
+ const changedAtoms = buildingBlocks[3];
593
611
  const flushCallbacks = buildingBlocks[12];
594
612
  const recomputeInvalidatedAtoms = buildingBlocks[13];
595
613
  const writeAtomState = buildingBlocks[16];
614
+ const prevChangedAtomsSize = changedAtoms.size;
596
615
  try {
597
616
  return writeAtomState(store, atom, ...args);
598
617
  } finally {
599
- recomputeInvalidatedAtoms(store);
600
- flushCallbacks(store);
618
+ if (changedAtoms.size !== prevChangedAtomsSize) {
619
+ recomputeInvalidatedAtoms(store);
620
+ flushCallbacks(store);
621
+ }
601
622
  }
602
623
  };
603
624
  const BUILDING_BLOCK_storeSub = (store, atom, listener) => {
@@ -706,7 +727,9 @@ function buildStore(...buildArgs) {
706
727
  /* @__PURE__ */ new WeakMap(),
707
728
  // abortHandlersMap
708
729
  BUILDING_BLOCK_registerAbortHandler,
709
- BUILDING_BLOCK_abortPromise
730
+ BUILDING_BLOCK_abortPromise,
731
+ // store epoch
732
+ [0]
710
733
  ].map((fn, i) => buildArgs[i] || fn);
711
734
  buildingBlockMap.set(store, Object.freeze(buildingBlocks));
712
735
  return store;
@@ -8,7 +8,7 @@ type Observer<T> = {
8
8
  error: (error: AnyError) => void;
9
9
  complete: () => void;
10
10
  };
11
- type ObservableLike<T> = {
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);
@@ -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
- let unsub;
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
- let observable = getObservable(get);
497
- const itself = (_a = observable[Symbol.observable]) == null ? void 0 : _a.call(observable);
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 = observable.subscribe({
523
+ subscription = subscribable.subscribe({
530
524
  next: (d) => listener({ d }),
531
525
  error: (e) => listener({ e }),
532
526
  complete: () => {
package/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "@depup/jotai",
3
- "description": "[DepUp] 👻 Primitive and flexible state management for React",
4
- "private": false,
3
+ "description": "👻 Primitive and flexible state management for React (with updated dependencies)",
5
4
  "type": "commonjs",
6
- "version": "2.18.0-depup.0",
5
+ "version": "2.19.0-depup.0",
7
6
  "main": "./index.js",
8
7
  "types": "./index.d.ts",
9
8
  "typesVersions": {
@@ -64,7 +63,9 @@
64
63
  }
65
64
  },
66
65
  "files": [
67
- "**"
66
+ "**",
67
+ "changes.json",
68
+ "README.md"
68
69
  ],
69
70
  "sideEffects": false,
70
71
  "engines": {
@@ -75,10 +76,12 @@
75
76
  "url": "git+https://github.com/pmndrs/jotai.git"
76
77
  },
77
78
  "keywords": [
78
- "depup",
79
- "dependency-bumped",
80
- "updated-deps",
81
79
  "jotai",
80
+ "depup",
81
+ "updated-dependencies",
82
+ "security",
83
+ "latest",
84
+ "patched",
82
85
  "react",
83
86
  "state",
84
87
  "manager",
@@ -118,8 +121,8 @@
118
121
  "changes": {},
119
122
  "depsUpdated": 0,
120
123
  "originalPackage": "jotai",
121
- "originalVersion": "2.18.0",
122
- "processedAt": "2026-03-09T03:53:57.128Z",
124
+ "originalVersion": "2.19.0",
125
+ "processedAt": "2026-03-24T08:21:54.402Z",
123
126
  "smokeTest": "failed"
124
127
  }
125
128
  }
@@ -1,6 +1,7 @@
1
1
  import type { Atom, ExtractAtomValue } from 'jotai/vanilla';
2
2
  import { useStore } from './Provider';
3
3
  type Options = Parameters<typeof useStore>[0] & {
4
+ /** @deprecated delay option is deprecated and will be removed in v3. https://github.com/pmndrs/jotai/pull/3264 */
4
5
  delay?: number;
5
6
  unstable_promiseStatus?: boolean;
6
7
  };
package/react.js CHANGED
@@ -136,6 +136,7 @@ function useAtomValue(atom, options) {
136
136
  } catch (_unused) {}
137
137
  }
138
138
  if (typeof delay === 'number') {
139
+ console.warn("[DEPRECATED] delay option is deprecated and will be removed in v3.\n\nMigration guide:\n\nCreate a custom hook like the following.\n\nfunction useAtomValueWithDelay<Value>(\n atom: Atom<Value>,\n options: { delay: number },\n): Value {\n const { delay } = options\n const store = useStore(options)\n const [value, setValue] = useState(() => store.get(atom))\n useEffect(() => {\n const unsub = store.sub(atom, () => {\n setTimeout(() => setValue(store.get(atom)), delay)\n })\n return unsub\n }, [store, atom, delay])\n return value\n}\n");
139
140
  setTimeout(rerender, delay);
140
141
  return;
141
142
  }
@@ -160,6 +160,28 @@ System.register(['react', 'jotai/vanilla', 'jotai/vanilla/internals'], (function
160
160
  }
161
161
  }
162
162
  if (typeof delay === "number") {
163
+ console.warn(`[DEPRECATED] delay option is deprecated and will be removed in v3.
164
+
165
+ Migration guide:
166
+
167
+ Create a custom hook like the following.
168
+
169
+ function useAtomValueWithDelay<Value>(
170
+ atom: Atom<Value>,
171
+ options: { delay: number },
172
+ ): Value {
173
+ const { delay } = options
174
+ const store = useStore(options)
175
+ const [value, setValue] = useState(() => store.get(atom))
176
+ useEffect(() => {
177
+ const unsub = store.sub(atom, () => {
178
+ setTimeout(() => setValue(store.get(atom)), delay)
179
+ })
180
+ return unsub
181
+ }, [store, atom, delay])
182
+ return value
183
+ }
184
+ `);
163
185
  setTimeout(rerender, delay);
164
186
  return;
165
187
  }
@@ -1,2 +1,23 @@
1
1
  'use client';
2
- System.register(["react","jotai/vanilla","jotai/vanilla/internals"],(function(V){"use strict";var y,k,p,v,d,C,E,j,m,x,P,w;return{setters:[function(s){y=s.createContext,k=s.useContext,p=s.useRef,v=s.createElement,d=s.default,C=s.useReducer,E=s.useEffect,j=s.useDebugValue,m=s.useCallback},function(s){x=s.getDefaultStore,P=s.createStore},function(s){w=s.INTERNAL_getBuildingBlocksRev2}],execute:(function(){V({Provider:L,useAtom:_,useAtomValue:D,useSetAtom:N,useStore:S});const s=y(void 0);function S(t){const e=k(s);return(t==null?void 0:t.store)||e||x()}function L({children:t,store:e}){const n=p(null);return e?v(s.Provider,{value:e},t):(n.current===null&&(n.current=P()),v(s.Provider,{value:n.current},t))}const h=t=>typeof(t==null?void 0:t.then)=="function",A=t=>{t.status||(t.status="pending",t.then(e=>{t.status="fulfilled",t.value=e},e=>{t.status="rejected",t.reason=e}))},T=d.use||(t=>{if(t.status==="pending")throw t;if(t.status==="fulfilled")return t.value;throw t.status==="rejected"?t.reason:(A(t),t)}),b=new WeakMap,B=(t,e,n)=>{const c=w(t)[26];let r=b.get(e);return r||(r=new Promise((f,g)=>{let l=e;const i=u=>R=>{l===u&&f(R)},a=u=>R=>{l===u&&g(R)},o=()=>{try{const u=n();h(u)?(b.set(u,r),l=u,u.then(i(u),a(u)),c(t,u,o)):f(u)}catch(u){g(u)}};e.then(i(e),a(e)),c(t,e,o)}),b.set(e,r)),r};function D(t,e){const{delay:n,unstable_promiseStatus:c=!d.use}=e||{},r=S(e),[[f,g,l],i]=C(o=>{const u=r.get(t);return Object.is(o[0],u)&&o[1]===r&&o[2]===t?o:[u,r,t]},void 0,()=>[r.get(t),r,t]);let a=f;if((g!==r||l!==t)&&(i(),a=r.get(t)),E(()=>{const o=r.sub(t,()=>{if(c)try{const u=r.get(t);h(u)&&A(B(r,u,()=>r.get(t)))}catch(u){}if(typeof n=="number"){setTimeout(i,n);return}i()});return i(),o},[r,t,n,c]),j(a),h(a)){const o=B(r,a,()=>r.get(t));return c&&A(o),T(o)}return a}function N(t,e){const n=S(e);return m((...c)=>n.set(t,...c),[n,t])}function _(t,e){return[D(t,e),N(t,e)]}})}}));
2
+ System.register(["react","jotai/vanilla","jotai/vanilla/internals"],(function(B){"use strict";var S,p,E,d,v,V,R,k,C,w,D,P;return{setters:[function(n){S=n.createContext,p=n.useContext,E=n.useRef,d=n.createElement,v=n.default,V=n.useReducer,R=n.useEffect,k=n.useDebugValue,C=n.useCallback},function(n){w=n.getDefaultStore,D=n.createStore},function(n){P=n.INTERNAL_getBuildingBlocksRev2}],execute:(function(){B({Provider:N,useAtom:I,useAtomValue:j,useSetAtom:x,useStore:m});const n=S(void 0);function m(t){const e=p(n);return(t==null?void 0:t.store)||e||w()}function N({children:t,store:e}){const o=E(null);return e?d(n.Provider,{value:e},t):(o.current===null&&(o.current=D()),d(n.Provider,{value:o.current},t))}const b=t=>typeof(t==null?void 0:t.then)=="function",h=t=>{t.status||(t.status="pending",t.then(e=>{t.status="fulfilled",t.value=e},e=>{t.status="rejected",t.reason=e}))},_=v.use||(t=>{if(t.status==="pending")throw t;if(t.status==="fulfilled")return t.value;throw t.status==="rejected"?t.reason:(h(t),t)}),y=new WeakMap,T=(t,e,o)=>{const a=P(t)[26];let u=y.get(e);return u||(u=new Promise((f,g)=>{let l=e;const i=s=>A=>{l===s&&f(A)},c=s=>A=>{l===s&&g(A)},r=()=>{try{const s=o();b(s)?(y.set(s,u),l=s,s.then(i(s),c(s)),a(t,s,r)):f(s)}catch(s){g(s)}};e.then(i(e),c(e)),a(t,e,r)}),y.set(e,u)),u};function j(t,e){const{delay:o,unstable_promiseStatus:a=!v.use}=e||{},u=m(e),[[f,g,l],i]=V(r=>{const s=u.get(t);return Object.is(r[0],s)&&r[1]===u&&r[2]===t?r:[s,u,t]},void 0,()=>[u.get(t),u,t]);let c=f;if((g!==u||l!==t)&&(i(),c=u.get(t)),R(()=>{const r=u.sub(t,()=>{if(a)try{const s=u.get(t);b(s)&&h(T(u,s,()=>u.get(t)))}catch(s){}if(typeof o=="number"){console.warn(`[DEPRECATED] delay option is deprecated and will be removed in v3.
3
+
4
+ Migration guide:
5
+
6
+ Create a custom hook like the following.
7
+
8
+ function useAtomValueWithDelay<Value>(
9
+ atom: Atom<Value>,
10
+ options: { delay: number },
11
+ ): Value {
12
+ const { delay } = options
13
+ const store = useStore(options)
14
+ const [value, setValue] = useState(() => store.get(atom))
15
+ useEffect(() => {
16
+ const unsub = store.sub(atom, () => {
17
+ setTimeout(() => setValue(store.get(atom)), delay)
18
+ })
19
+ return unsub
20
+ }, [store, atom, delay])
21
+ return value
22
+ }
23
+ `),setTimeout(i,o);return}i()});return i(),r},[u,t,o,a]),k(c),b(c)){const r=T(u,c,()=>u.get(t));return a&&h(r),_(r)}return c}function x(t,e){const o=m(e);return C((...a)=>o.set(t,...a),[o,t])}function I(t,e){return[j(t,e),x(t,e)]}})}}));
@@ -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
  }
@@ -235,9 +236,19 @@ System.register([], (function (exports) {
235
236
  const mountDependencies = buildingBlocks[17];
236
237
  const setAtomStateValueOrPromise = buildingBlocks[20];
237
238
  const registerAbortHandler = buildingBlocks[26];
239
+ const storeEpochHolder = buildingBlocks[28];
238
240
  const atomState = ensureAtomState(store, atom);
241
+ const storeEpochNumber = storeEpochHolder[0];
239
242
  if (isAtomStateInitialized(atomState)) {
240
- if (mountedMap.has(atom) && invalidatedAtoms.get(atom) !== atomState.n) {
243
+ if (
244
+ // If the atom is mounted, we can use cached atom state,
245
+ // because it should have been updated by dependencies.
246
+ // We can't use the cache if the atom is invalidated.
247
+ mountedMap.has(atom) && invalidatedAtoms.get(atom) !== atomState.n || // If atom is not mounted, we can use cached atom state,
248
+ // only if store hasn't been mutated.
249
+ atomState.m === storeEpochNumber
250
+ ) {
251
+ atomState.m = storeEpochNumber;
241
252
  return atomState;
242
253
  }
243
254
  let hasChangedDeps = false;
@@ -248,6 +259,7 @@ System.register([], (function (exports) {
248
259
  }
249
260
  }
250
261
  if (!hasChangedDeps) {
262
+ atomState.m = storeEpochNumber;
251
263
  return atomState;
252
264
  }
253
265
  }
@@ -338,6 +350,7 @@ System.register([], (function (exports) {
338
350
  }
339
351
  };
340
352
  const prevEpochNumber = atomState.n;
353
+ const prevInvalidated = invalidatedAtoms.get(atom) === prevEpochNumber;
341
354
  try {
342
355
  if (true) {
343
356
  storeMutationSet.delete(store);
@@ -360,15 +373,17 @@ System.register([], (function (exports) {
360
373
  pruneDependencies();
361
374
  }
362
375
  (_a = storeHooks.r) == null ? void 0 : _a.call(storeHooks, atom);
376
+ atomState.m = storeEpochNumber;
363
377
  return atomState;
364
378
  } catch (error) {
365
379
  delete atomState.v;
366
380
  atomState.e = error;
367
381
  ++atomState.n;
382
+ atomState.m = storeEpochNumber;
368
383
  return atomState;
369
384
  } finally {
370
385
  isSync = false;
371
- if (prevEpochNumber !== atomState.n && invalidatedAtoms.get(atom) === prevEpochNumber) {
386
+ if (atomState.n !== prevEpochNumber && prevInvalidated) {
372
387
  invalidatedAtoms.set(atom, atomState.n);
373
388
  changedAtoms.add(atom);
374
389
  (_b = storeHooks.c) == null ? void 0 : _b.call(storeHooks, atom);
@@ -406,6 +421,7 @@ System.register([], (function (exports) {
406
421
  const writeAtomState = buildingBlocks[16];
407
422
  const mountDependencies = buildingBlocks[17];
408
423
  const setAtomStateValueOrPromise = buildingBlocks[20];
424
+ const storeEpochHolder = buildingBlocks[28];
409
425
  let isSync = true;
410
426
  const getter = (a) => returnAtomValue(readAtomState(store, a));
411
427
  const setter = (a, ...args2) => {
@@ -424,6 +440,7 @@ System.register([], (function (exports) {
424
440
  setAtomStateValueOrPromise(store, a, v);
425
441
  mountDependencies(store, a);
426
442
  if (prevEpochNumber !== aState.n) {
443
+ ++storeEpochHolder[0];
427
444
  changedAtoms.add(a);
428
445
  invalidateDependents(store, a);
429
446
  (_a = storeHooks.c) == null ? void 0 : _a.call(storeHooks, a);
@@ -608,14 +625,18 @@ System.register([], (function (exports) {
608
625
  };
609
626
  const BUILDING_BLOCK_storeSet = (store, atom, ...args) => {
610
627
  const buildingBlocks = getInternalBuildingBlocks(store);
628
+ const changedAtoms = buildingBlocks[3];
611
629
  const flushCallbacks = buildingBlocks[12];
612
630
  const recomputeInvalidatedAtoms = buildingBlocks[13];
613
631
  const writeAtomState = buildingBlocks[16];
632
+ const prevChangedAtomsSize = changedAtoms.size;
614
633
  try {
615
634
  return writeAtomState(store, atom, ...args);
616
635
  } finally {
617
- recomputeInvalidatedAtoms(store);
618
- flushCallbacks(store);
636
+ if (changedAtoms.size !== prevChangedAtomsSize) {
637
+ recomputeInvalidatedAtoms(store);
638
+ flushCallbacks(store);
639
+ }
619
640
  }
620
641
  };
621
642
  const BUILDING_BLOCK_storeSub = (store, atom, listener) => {
@@ -724,7 +745,9 @@ System.register([], (function (exports) {
724
745
  /* @__PURE__ */ new WeakMap(),
725
746
  // abortHandlersMap
726
747
  BUILDING_BLOCK_registerAbortHandler,
727
- BUILDING_BLOCK_abortPromise
748
+ BUILDING_BLOCK_abortPromise,
749
+ // store epoch
750
+ [0]
728
751
  ].map((fn, i) => buildArgs[i] || fn);
729
752
  buildingBlockMap.set(store, Object.freeze(buildingBlocks));
730
753
  return store;
@@ -1 +1 @@
1
- System.register([],(function(C){"use strict";return{execute:(function(){C({INTERNAL_addPendingPromiseToDependency:B,INTERNAL_buildStoreRev2:un,INTERNAL_getBuildingBlocksRev2:fn,INTERNAL_getMountedOrPendingDependents:O,INTERNAL_hasInitialValue:W,INTERNAL_initializeStoreHooksRev2:q,INTERNAL_isActuallyWritableAtom:b,INTERNAL_isAtomStateInitialized:P,INTERNAL_isPromiseLike:R,INTERNAL_returnAtomValue:I});function W(n){return"init"in n}function b(n){return!!n.write}function P(n){return"v"in n||"e"in n}function I(n){if("e"in n)throw n.e;return n.v}function R(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},L=()=>{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=L()),n.r||(n.r=L()),n.c||(n.c=L()),n.m||(n.m=L()),n.u||(n.u=L()),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=p(n),r=t[0],l=t[6],s=t[9];let u=r.get(e);return u||(u={d:new Map,p:new Set,n:0},r.set(e,u),(o=l.i)==null||o.call(l,e),s==null||s(n,e)),u},U=n=>{const e=p(n),o=e[1],t=e[3],r=e[4],l=e[5],s=e[6],u=e[13],d=[],g=w=>{try{w()}catch(c){d.push(c)}};do{s.f&&g(s.f);const w=new Set,c=w.add.bind(w);t.forEach(f=>{var a;return(a=o.get(f))==null?void 0:a.l.forEach(c)}),t.clear(),l.forEach(c),l.clear(),r.forEach(c),r.clear(),w.forEach(g),t.size&&u(n)}while(t.size||l.size||r.size);if(d.length)throw new AggregateError(d)},X=n=>{const e=p(n),o=e[1],t=e[2],r=e[3],l=e[11],s=e[14],u=e[17],d=[],g=new WeakSet,w=new WeakSet,c=Array.from(r);for(;c.length;){const f=c[c.length-1],a=l(n,f);if(w.has(f)){c.pop();continue}if(g.has(f)){t.get(f)===a.n&&d.push([f,a]),w.add(f),c.pop();continue}g.add(f);for(const v of O(f,a,o))g.has(v)||c.push(v)}for(let f=d.length-1;f>=0;--f){const[a,v]=d[f];let y=!1;for(const S of v.d.keys())if(S!==a&&r.has(S)){y=!0;break}y&&(s(n,a),u(n,a)),t.delete(a)}},Y=(n,e)=>{var o,t;const r=p(n),l=r[1],s=r[2],u=r[3],d=r[6],g=r[7],w=r[11],c=r[12],f=r[13],a=r[14],v=r[16],y=r[17],S=r[20],E=r[26],i=w(n,e);if(P(i)){if(l.has(e)&&s.get(e)!==i.n)return i;let h=!1;for(const[N,k]of i.d)if(a(n,N).n!==k){h=!0;break}if(!h)return i}let A=!0;const z=new Set(i.d.keys()),T=new Map,M=()=>{for(const h of z)T.has(h)||i.d.delete(h)},m=()=>{if(l.has(e)){const h=!u.size;y(n,e),h&&(f(n),c(n))}},dn=h=>{var N;if(h===e){const x=w(n,h);if(!P(x))if(W(h))S(n,h,h.init);else throw new Error("no atom init");return I(x)}const k=a(n,h);try{return I(k)}finally{T.set(h,k.n),i.d.set(h,k.n),R(i.v)&&B(e,i.v,k),l.has(e)&&((N=l.get(h))==null||N.t.add(e)),A||m()}};let _,j;const hn={get signal(){return _||(_=new AbortController),_.signal},get setSelf(){return!j&&b(e)&&(j=(...h)=>{if(!A)try{return v(n,e,...h)}finally{f(n),c(n)}}),j}},V=i.n;try{const h=g(n,e,dn,hn);if(S(n,e,h),R(h)){E(n,h,()=>_==null?void 0:_.abort());const N=()=>{M(),m()};h.then(N,N)}else M();return(o=d.r)==null||o.call(d,e),i}catch(h){return delete i.v,i.e=h,++i.n,i}finally{A=!1,V!==i.n&&s.get(e)===V&&(s.set(e,i.n),u.add(e),(t=d.c)==null||t.call(d,e))}},Z=(n,e)=>{const o=p(n),t=o[1],r=o[2],l=o[11],s=[e];for(;s.length;){const u=s.pop(),d=l(n,u);for(const g of O(u,d,t)){const w=l(n,g);r.get(g)!==w.n&&(r.set(g,w.n),s.push(g))}}},$=(n,e,...o)=>{const t=p(n),r=t[3],l=t[6],s=t[8],u=t[11],d=t[12],g=t[13],w=t[14],c=t[15],f=t[16],a=t[17],v=t[20];let y=!0;const S=i=>I(w(n,i)),E=(i,...A)=>{var z;const T=u(n,i);try{if(i===e){if(!W(i))throw new Error("atom not writable");const M=T.n,m=A[0];v(n,i,m),a(n,i),M!==T.n&&(r.add(i),c(n,i),(z=l.c)==null||z.call(l,i));return}else return f(n,i,...A)}finally{y||(g(n),d(n))}};try{return s(n,e,S,E,...o)}finally{y=!1}},nn=(n,e)=>{var o;const t=p(n),r=t[1],l=t[3],s=t[6],u=t[11],d=t[15],g=t[18],w=t[19],c=u(n,e),f=r.get(e);if(f){for(const[a,v]of c.d)if(!f.d.has(a)){const y=u(n,a);g(n,a).t.add(e),f.d.add(a),v!==y.n&&(l.add(a),d(n,a),(o=s.c)==null||o.call(s,a))}for(const a of f.d)if(!c.d.has(a)){f.d.delete(a);const v=w(n,a);v==null||v.t.delete(e)}}},en=(n,e)=>{var o;const t=p(n),r=t[1],l=t[4],s=t[6],u=t[10],d=t[11],g=t[12],w=t[13],c=t[14],f=t[16],a=t[18],v=d(n,e);let y=r.get(e);if(!y){c(n,e);for(const S of v.d.keys())a(n,S).t.add(e);if(y={l:new Set,d:new Set(v.d.keys()),t:new Set},r.set(e,y),b(e)){const S=()=>{let E=!0;const i=(...A)=>{try{return f(n,e,...A)}finally{E||(w(n),g(n))}};try{const A=u(n,e,i);A&&(y.u=()=>{E=!0;try{A()}finally{E=!1}})}finally{E=!1}};l.add(S)}(o=s.m)==null||o.call(s,e)}return y},tn=(n,e)=>{var o,t;const r=p(n),l=r[1],s=r[5],u=r[6],d=r[11],g=r[19],w=d(n,e);let c=l.get(e);if(!c||c.l.size)return c;let f=!1;for(const a of c.t)if((o=l.get(a))!=null&&o.d.has(e)){f=!0;break}if(!f){c.u&&s.add(c.u),c=void 0,l.delete(e);for(const a of w.d.keys()){const v=g(n,a);v==null||v.t.delete(e)}(t=u.u)==null||t.call(u,e);return}return c},rn=(n,e,o)=>{const t=p(n),r=t[11],l=t[27],s=r(n,e),u="v"in s,d=s.v;if(R(o))for(const g of s.d.keys())B(e,o,r(n,g));s.v=o,delete s.e,(!u||!Object.is(d,s.v))&&(++s.n,R(d)&&l(n,d))},on=(n,e)=>{const o=p(n)[14];return I(o(n,e))},ln=(n,e,...o)=>{const t=p(n),r=t[12],l=t[13],s=t[16];try{return s(n,e,...o)}finally{l(n),r(n)}},sn=(n,e,o)=>{const t=p(n),r=t[12],l=t[18],s=t[19],u=l(n,e).l;return u.add(o),r(n),()=>{u.delete(o),s(n,e),r(n)}},an=(n,e,o)=>{const t=p(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=p(n)[25].get(e);o==null||o.forEach(t=>t())},D=new WeakMap,p=n=>D.get(n);function fn(n){const e=p(n),o=e[24];return o?o(e):e}function un(...n){const e={get(t){const r=p(e)[21];return r(e,t)},set(t,...r){const l=p(e)[22];return l(e,t,...r)},sub(t,r){const l=p(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}})}}));
1
+ System.register([],(function(q){"use strict";return{execute:(function(){q({INTERNAL_addPendingPromiseToDependency:O,INTERNAL_buildStoreRev2:hn,INTERNAL_getBuildingBlocksRev2:dn,INTERNAL_getMountedOrPendingDependents:V,INTERNAL_hasInitialValue:W,INTERNAL_initializeStoreHooksRev2:G,INTERNAL_isActuallyWritableAtom:P,INTERNAL_isAtomStateInitialized:B,INTERNAL_isPromiseLike:R,INTERNAL_returnAtomValue:I});function W(n){return"init"in n}function P(n){return!!n.write}function B(n){return"v"in n||"e"in n}function I(n){if("e"in n)throw n.e;return n.v}function R(n){return typeof(n==null?void 0:n.then)=="function"}function O(n,e,o){if(!o.p.has(n)){o.p.add(n);const t=()=>o.p.delete(n);e.then(t,t)}}function V(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 F=()=>{const n=new Set,e=()=>n.forEach(o=>o());return e.add=o=>(n.add(o),()=>n.delete(o)),e},b=()=>{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 G(n){return n.i||(n.i=b()),n.r||(n.r=b()),n.c||(n.c=b()),n.m||(n.m=b()),n.u||(n.u=b()),n.f||(n.f=F()),n}const J=(n,e,...o)=>e.read(...o),K=(n,e,...o)=>e.write(...o),Q=(n,e)=>{var o;return(o=e.INTERNAL_onInit)==null?void 0:o.call(e,n)},U=(n,e,o)=>{var t;return(t=e.onMount)==null?void 0:t.call(e,o)},X=(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},Y=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 i;return(i=o.get(f))==null?void 0:i.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)},Z=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],i=l(n,f);if(p.has(f)){u.pop();continue}if(g.has(f)){t.get(f)===i.n&&d.push([f,i]),p.add(f),u.pop();continue}g.add(f);for(const w of V(f,i,o))g.has(w)||u.push(w)}for(let f=d.length-1;f>=0;--f){const[i,w]=d[f];let m=!1;for(const A of w.d.keys())if(A!==i&&r.has(A)){m=!0;break}m&&(t.set(i,w.n),s(n,i),c(n,i)),t.delete(i)}},$=(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],i=r[14],w=r[16],m=r[17],A=r[20],k=r[26],z=r[28],a=p(n,e),y=z[0];if(B(a)){if(l.has(e)&&s.get(e)!==a.n||a.m===y)return a.m=y,a;let h=!1;for(const[N,S]of a.d)if(i(n,N).n!==S){h=!0;break}if(!h)return a.m=y,a}let E=!0;const T=new Set(a.d.keys()),_=new Map,M=()=>{for(const h of T)_.has(h)||a.d.delete(h)},x=()=>{if(l.has(e)){const h=!c.size;m(n,e),h&&(f(n),u(n))}},gn=h=>{var N;if(h===e){const H=p(n,h);if(!B(H))if(W(h))A(n,h,h.init);else throw new Error("no atom init");return I(H)}const S=i(n,h);try{return I(S)}finally{_.set(h,S.n),a.d.set(h,S.n),R(a.v)&&O(e,a.v,S),l.has(e)&&((N=l.get(h))==null||N.t.add(e)),E||x()}};let L,j;const pn={get signal(){return L||(L=new AbortController),L.signal},get setSelf(){return!j&&P(e)&&(j=(...h)=>{if(!E)try{return w(n,e,...h)}finally{f(n),u(n)}}),j}},C=a.n,wn=s.get(e)===C;try{const h=g(n,e,gn,pn);if(A(n,e,h),R(h)){k(n,h,()=>L==null?void 0:L.abort());const N=()=>{M(),x()};h.then(N,N)}else M();return(o=d.r)==null||o.call(d,e),a.m=y,a}catch(h){return delete a.v,a.e=h,++a.n,a.m=y,a}finally{E=!1,a.n!==C&&wn&&(s.set(e,a.n),c.add(e),(t=d.c)==null||t.call(d,e))}},nn=(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 V(c,d,t)){const p=l(n,g);r.get(g)!==p.n&&(r.set(g,p.n),s.push(g))}}},en=(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],i=t[17],w=t[20],m=t[28];let A=!0;const k=a=>I(p(n,a)),z=(a,...y)=>{var E;const T=c(n,a);try{if(a===e){if(!W(a))throw new Error("atom not writable");const _=T.n,M=y[0];w(n,a,M),i(n,a),_!==T.n&&(++m[0],r.add(a),u(n,a),(E=l.c)==null||E.call(l,a));return}else return f(n,a,...y)}finally{A||(g(n),d(n))}};try{return s(n,e,k,z,...o)}finally{A=!1}},tn=(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[i,w]of u.d)if(!f.d.has(i)){const m=c(n,i);g(n,i).t.add(e),f.d.add(i),w!==m.n&&(l.add(i),d(n,i),(o=s.c)==null||o.call(s,i))}for(const i of f.d)if(!u.d.has(i)){f.d.delete(i);const w=p(n,i);w==null||w.t.delete(e)}}},rn=(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],i=t[18],w=d(n,e);let m=r.get(e);if(!m){u(n,e);for(const A of w.d.keys())i(n,A).t.add(e);if(m={l:new Set,d:new Set(w.d.keys()),t:new Set},r.set(e,m),P(e)){const A=()=>{let k=!0;const z=(...a)=>{try{return f(n,e,...a)}finally{k||(p(n),g(n))}};try{const a=c(n,e,z);a&&(m.u=()=>{k=!0;try{a()}finally{k=!1}})}finally{k=!1}};l.add(A)}(o=s.m)==null||o.call(s,e)}return m},on=(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 i of u.t)if((o=l.get(i))!=null&&o.d.has(e)){f=!0;break}if(!f){u.u&&s.add(u.u),u=void 0,l.delete(e);for(const i of p.d.keys()){const w=g(n,i);w==null||w.t.delete(e)}(t=c.u)==null||t.call(c,e);return}return u},ln=(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(R(o))for(const g of s.d.keys())O(e,o,r(n,g));s.v=o,delete s.e,(!c||!Object.is(d,s.v))&&(++s.n,R(d)&&l(n,d))},sn=(n,e)=>{const o=v(n)[14];return I(o(n,e))},an=(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))}},cn=(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)}},un=(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)},fn=(n,e)=>{const o=v(n)[25].get(e);o==null||o.forEach(t=>t())},D=new WeakMap,v=n=>D.get(n);function dn(n){const e=v(n),o=e[24];return o?o(e):e}function hn(...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,{},J,K,Q,U,X,Y,Z,$,nn,en,tn,rn,on,ln,sn,an,cn,void 0,new WeakMap,un,fn,[0]].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
- let unsub;
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
- let observable = getObservable(get);
523
- const itself = (_a = observable[Symbol.observable]) == null ? void 0 : _a.call(observable);
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 = observable.subscribe({
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:D,atomWithRefresh:at,atomWithReset:P,atomWithStorage:tt,createJSONStorage:V,freezeAtom:T,freezeAtomCreator:q,loadable:ct,selectAtom:K,splitAtom:U,unstable_withStorageValidator:Y,unwrap:_});const O=x("RESET",Symbol(""));function P(t){const e=m(t,(s,u,c)=>{const a=typeof c=="function"?c(s(e)):c;u(e,a===O?t:a)});return e}function D(t,e){return m(t,function(s,u,c){u(this,e(s(this),c))})}function $(t,e){let s=null;const u=new Map,c=new Set,a=i=>{let n;if(e===void 0)n=u.get(i);else for(const[l,f]of u)if(e(l,i)){n=f;break}if(n!==void 0)if(s!=null&&s(n[1],i))a.remove(i);else return n[0];const r=t(i);return u.set(i,[r,Date.now()]),o("CREATE",i,r),r},o=(i,n,r)=>{for(const l of c)l({type:i,param:n,atom:r})};return a.unstable_listen=i=>(c.add(i),()=>{c.delete(i)}),a.getParams=()=>u.keys(),a.remove=i=>{if(e===void 0){if(!u.has(i))return;const[n]=u.get(i);u.delete(i),o("REMOVE",i,n)}else for(const[n,[r]]of u)if(e(n,i)){u.delete(n),o("REMOVE",n,r);break}},a.setShouldRemove=i=>{if(s=i,!!s)for(const[n,[r,l]]of u)s(l,n)&&(u.delete(n),o("REMOVE",n,r))},a}const I=(t,e,s)=>(e.has(s)?e:e.set(s,t())).get(s),C=new WeakMap,F=(t,e,s,u)=>{const c=I(()=>new WeakMap,C,e),a=I(()=>new WeakMap,c,s);return I(t,a,u)};function K(t,e,s=Object.is){return F(()=>{const u=Symbol(),c=([o,i])=>{if(i===u)return e(o);const n=e(o,i);return s(i,n)?i:n},a=m(o=>{const i=o(a),n=o(t);return c([n,i])});return a.init=u,a},t,e,s)}const A=new WeakSet,L=t=>{if(typeof t!="object"||t===null)return t;Object.freeze(t);const e=Object.getOwnPropertyNames(t);for(const s of e)L(t[s]);return t};function T(t){if(A.has(t))return t;A.add(t);const e=t.read;if(t.read=function(s,u){return L(e.call(this,s,u))},"write"in t){const s=t.write;t.write=function(u,c,...a){return s.call(this,u,(...o)=>(o[0]===t&&(o[1]=L(o[1])),c(...o)),...a)}}return t}function q(t){return((...e)=>T(t(...e)))}const j=(t,e,s)=>(e.has(s)?e:e.set(s,t())).get(s),B=new WeakMap,G=(t,e,s)=>{const u=j(()=>new WeakMap,B,e);return j(t,u,s)},H={},N=t=>!!t.write,Q=t=>typeof t=="function";function U(t,e){return G(()=>{const s=new WeakMap,u=(o,i)=>{let n=s.get(o);if(n)return n;const r=i&&s.get(i),l=[],f=[];return o.forEach((b,v)=>{const d=e?e(b):v;f[v]=d;const g=r&&r.atomList[r.keyList.indexOf(d)];if(g){l[v]=g;return}const W=w=>{const y=w(c),h=w(t),k=u(h,y==null?void 0:y.arr).keyList.indexOf(d);if(k<0||k>=h.length){const p=o[u(o).keyList.indexOf(d)];if(p)return p;throw new Error("splitAtom: index out of bounds for read")}return h[k]},E=(w,y,h)=>{const k=w(c),p=w(t),S=u(p,k==null?void 0:k.arr).keyList.indexOf(d);if(S<0||S>=p.length)throw new Error("splitAtom: index out of bounds for write");const J=Q(h)?h(p[S]):h;Object.is(p[S],J)||y(t,[...p.slice(0,S),J,...p.slice(S+1)])};l[v]=N(t)?m(W,E):m(W)}),r&&r.keyList.length===f.length&&r.keyList.every((b,v)=>b===f[v])?n=r:n={arr:o,atomList:l,keyList:f},s.set(o,n),n},c=m(o=>{const i=o(c),n=o(t);return u(n,i==null?void 0:i.arr)});c.init=void 0;const a=N(t)?m(o=>o(c).atomList,(o,i,n)=>{switch(n.type){case"remove":{const r=o(a).indexOf(n.atom);if(r>=0){const l=o(t);i(t,[...l.slice(0,r),...l.slice(r+1)])}break}case"insert":{const r=n.before?o(a).indexOf(n.before):o(a).length;if(r>=0){const l=o(t);i(t,[...l.slice(0,r),n.value,...l.slice(r)])}break}case"move":{const r=o(a).indexOf(n.atom),l=n.before?o(a).indexOf(n.before):o(a).length;if(r>=0&&l>=0){const f=o(t);r<l?i(t,[...f.slice(0,r),...f.slice(r+1,l),f[r],...f.slice(l)]):i(t,[...f.slice(0,l),f[r],...f.slice(l,r),...f.slice(r+1)])}break}}}):m(o=>o(c).atomList);return a},t,e||H)}function X(t){const e=Symbol(),s=m(e),u=m((c,a)=>{const o=c(s);return o!==e?o:t(c,a)},(c,a,o)=>{const i=typeof o=="function"?o(c(u)):o;a(s,i===O?e:i)});return u}const M=t=>typeof(t==null?void 0:t.then)=="function";function Y(t){return e=>({...e,getItem:(s,u)=>{const c=o=>t(o)?o:u,a=e.getItem(s,u);return M(a)?a.then(c):c(a)}})}function V(t=()=>{try{return window.localStorage}catch(s){return}},e){var s;let u,c;const a={getItem:(n,r)=>{var l,f;const b=d=>{if(d=d||"",u!==d){try{c=JSON.parse(d,e==null?void 0:e.reviver)}catch(g){return r}u=d}return c},v=(f=(l=t())==null?void 0:l.getItem(n))!=null?f:null;return M(v)?v.then(b):b(v)},setItem:(n,r)=>{var l;return(l=t())==null?void 0:l.setItem(n,JSON.stringify(r,e==null?void 0:e.replacer))},removeItem:n=>{var r;return(r=t())==null?void 0:r.removeItem(n)}},o=n=>(r,l,f)=>n(r,b=>{let v;try{v=JSON.parse(b||"")}catch(d){v=f}l(v)});let i;try{i=(s=t())==null?void 0:s.subscribe}catch(n){}return!i&&typeof window!="undefined"&&typeof window.addEventListener=="function"&&window.Storage&&(i=(n,r)=>{if(!(t()instanceof window.Storage))return()=>{};const l=f=>{f.storageArea===t()&&f.key===n&&r(f.newValue)};return window.addEventListener("storage",l),()=>{window.removeEventListener("storage",l)}}),i&&(a.subscribe=o(i)),a}const Z=V();function tt(t,e,s=Z,u){const c=u==null?void 0:u.getOnInit,a=m(c?s.getItem(t,e):e);return a.onMount=o=>{o(s.getItem(t,e));let i;return s.subscribe&&(i=s.subscribe(t,o,e)),i},m(o=>o(a),(o,i,n)=>{const r=typeof n=="function"?n(o(a)):n;return r===O?(i(a,e),s.removeItem(t)):M(r)?r.then(l=>(i(a,l),s.setItem(t,l))):(i(a,r),s.setItem(t,r))})}const et=t=>typeof(t==null?void 0:t.then)=="function";function nt(t,e){const s=c=>{if("e"in c)throw c.e;return c.d},u=m(c=>{var a;let o=t(c);const i=(a=o[Symbol.observable])==null?void 0:a.call(o);i&&(o=i);let n;const r=()=>new Promise(h=>{n=h}),l=e&&"initialValue"in e?{d:typeof e.initialValue=="function"?e.initialValue():e.initialValue}:r();let f,b;const v=h=>{b=h,n==null||n(h),f==null||f(h)};let d,g;const W=()=>!f,E=()=>{d&&(d.unsubscribe(),d=void 0)},w=()=>{d&&(clearTimeout(g),d.unsubscribe()),d=o.subscribe({next:h=>v({d:h}),error:h=>v({e:h}),complete:()=>{}}),W()&&e!=null&&e.unstable_timeout&&(g=setTimeout(E,e.unstable_timeout))};w();const y=m(b||l);return y.onMount=h=>(f=h,b&&h(b),d?clearTimeout(g):w(),()=>{f=void 0,e!=null&&e.unstable_timeout?g=setTimeout(E,e.unstable_timeout):E()}),[y,o,r,w,W]});return m(c=>{const[a]=c(u),o=c(a);return et(o)?o.then(s):s(o)},(c,a,o)=>{const[i,n,r,l,f]=c(u);if("next"in n)f()&&(a(i,r()),l()),n.next(o);else throw new Error("observable is not subject")})}const z=(t,e,s)=>(e.has(s)?e:e.set(s,t())).get(s),ot=new WeakMap,rt=(t,e,s)=>{const u=z(()=>new WeakMap,ot,e);return z(t,u,s)},it=t=>typeof(t==null?void 0:t.then)=="function",st=()=>{};function _(t,e=st){return rt(()=>{const s=new WeakMap,u=new WeakMap,c=m(0),a=m([]);a.INTERNAL_onInit=i=>{i.set(a,[()=>i.set(c,n=>n+1)])};const o=m(i=>{i(c);let n;try{n=i(o)}catch(l){}const r=i(t);if(!it(r))return{v:r};if(r!==(n==null?void 0:n.p)&&r.then(l=>{u.set(r,l);const[f]=i(a);f()},l=>{s.set(r,l);const[f]=i(a);f()}),s.has(r))throw s.get(r);return u.has(r)?{p:r,v:u.get(r)}:n&&"v"in n?{p:r,f:e(n.v),v:n.v}:{p:r,f:e()}});return o.init=void 0,m(i=>{const n=i(o);return"f"in n?n.f:n.v},(i,n,...r)=>n(t,...r))},t,e)}const R=new WeakMap,ut=(t,e)=>(R.has(e)?R:R.set(e,t())).get(e);function ct(t){return ut(()=>{const e={state:"loading"},s=_(t,()=>e);return m(u=>{try{const c=u(s);return c===e?e:{state:"hasData",data:c}}catch(c){return{state:"hasError",error:c}}})},t)}function at(t,e){const s=m(0);return m((u,c)=>(u(s),t(u,c)),(u,c,...a)=>{if(a.length===0)c(s,o=>o+1);else if(e)return e(u,c,...a)})}function lt(t){const e=m(void 0);return delete e.init,Object.defineProperty(e,"init",{get(){return t()}}),e}})}}));
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}})}}));
@@ -1,6 +1,7 @@
1
1
  import type { Atom, ExtractAtomValue } from 'jotai/vanilla';
2
2
  import { useStore } from './Provider';
3
3
  type Options = Parameters<typeof useStore>[0] & {
4
+ /** @deprecated delay option is deprecated and will be removed in v3. https://github.com/pmndrs/jotai/pull/3264 */
4
5
  delay?: number;
5
6
  unstable_promiseStatus?: boolean;
6
7
  };