@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 +2 -2
- package/changes.json +1 -1
- package/esm/react/useAtomValue.d.mts +1 -0
- package/esm/react.mjs +22 -0
- package/esm/vanilla/internals.d.mts +5 -1
- package/esm/vanilla/internals.mjs +28 -5
- package/esm/vanilla/utils/atomWithObservable.d.mts +5 -1
- package/esm/vanilla/utils.mjs +5 -11
- package/package.json +12 -9
- package/react/useAtomValue.d.ts +1 -0
- package/react.js +1 -0
- package/system/react.development.js +22 -0
- package/system/react.production.js +22 -1
- package/system/vanilla/internals.development.js +28 -5
- 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/react/useAtomValue.d.ts +1 -0
- package/ts3.8/esm/vanilla/internals.d.ts +7 -1
- package/ts3.8/esm/vanilla/utils/atomWithObservable.d.ts +5 -1
- package/ts3.8/react/useAtomValue.d.ts +1 -0
- package/ts3.8/vanilla/internals.d.ts +7 -1
- package/ts3.8/vanilla/utils/atomWithObservable.d.ts +5 -1
- package/umd/react.development.js +1 -0
- package/umd/react.production.js +1 -1
- package/umd/vanilla/internals.development.js +23 -9
- 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.d.ts +5 -1
- package/vanilla/internals.js +23 -9
- package/vanilla/utils/atomWithObservable.d.ts +5 -1
- package/vanilla/utils.js +3 -10
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.
|
|
17
|
-
| Processed | 2026-03-
|
|
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,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 (
|
|
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 (
|
|
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
|
-
|
|
600
|
-
|
|
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
|
|
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
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@depup/jotai",
|
|
3
|
-
"description": "
|
|
4
|
-
"private": false,
|
|
3
|
+
"description": "👻 Primitive and flexible state management for React (with updated dependencies)",
|
|
5
4
|
"type": "commonjs",
|
|
6
|
-
"version": "2.
|
|
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.
|
|
122
|
-
"processedAt": "2026-03-
|
|
124
|
+
"originalVersion": "2.19.0",
|
|
125
|
+
"processedAt": "2026-03-24T08:21:54.402Z",
|
|
123
126
|
"smokeTest": "failed"
|
|
124
127
|
}
|
|
125
128
|
}
|
package/react/useAtomValue.d.ts
CHANGED
|
@@ -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(
|
|
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 (
|
|
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 (
|
|
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
|
-
|
|
618
|
-
|
|
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(
|
|
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
|
-
|
|
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}})}}));
|
|
@@ -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
|
};
|