@depup/jotai 2.18.1-depup.0 → 2.19.1-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/benchmarks/diamond.d.ts +2 -0
- package/benchmarks/read-write.d.ts +2 -0
- package/benchmarks/run-all.d.ts +2 -0
- package/benchmarks/select-atom.d.ts +2 -0
- package/benchmarks/subscription.d.ts +2 -0
- package/benchmarks/wide-fan-out.d.ts +2 -0
- 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 +10 -3
- package/esm/vanilla/internals.mjs +84 -34
- package/esm/vanilla/utils/atomWithObservable.d.mts +1 -1
- 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 +84 -34
- package/system/vanilla/internals.production.js +1 -1
- package/system/vanilla/utils.production.js +1 -1
- package/ts3.8/benchmarks/diamond.d.ts +3 -0
- package/ts3.8/benchmarks/read-write.d.ts +3 -0
- package/ts3.8/benchmarks/run-all.d.ts +3 -0
- package/ts3.8/benchmarks/select-atom.d.ts +3 -0
- package/ts3.8/benchmarks/subscription.d.ts +3 -0
- package/ts3.8/benchmarks/wide-fan-out.d.ts +3 -0
- package/ts3.8/esm/react/useAtomValue.d.ts +1 -0
- package/ts3.8/esm/vanilla/internals.d.ts +11 -2
- package/ts3.8/esm/vanilla/utils/atomWithObservable.d.ts +1 -1
- package/ts3.8/react/useAtomValue.d.ts +1 -0
- package/ts3.8/vanilla/internals.d.ts +11 -2
- package/ts3.8/vanilla/utils/atomWithObservable.d.ts +1 -1
- package/umd/react.development.js +1 -0
- package/umd/react.production.js +1 -1
- package/umd/vanilla/internals.development.js +114 -73
- package/umd/vanilla/internals.production.js +1 -1
- package/vanilla/internals.d.ts +10 -3
- package/vanilla/internals.js +114 -73
- package/vanilla/utils/atomWithObservable.d.ts +1 -1
- /package/benchmarks/{simple-read.d.ts → atom-creation.d.ts} +0 -0
- /package/benchmarks/{simple-write.d.ts → computed-read.d.ts} +0 -0
- /package/benchmarks/{subscribe-write.d.ts → derived-chain.d.ts} +0 -0
- /package/ts3.8/benchmarks/{simple-read.d.ts → atom-creation.d.ts} +0 -0
- /package/ts3.8/benchmarks/{simple-write.d.ts → computed-read.d.ts} +0 -0
- /package/ts3.8/benchmarks/{subscribe-write.d.ts → derived-chain.d.ts} +0 -0
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-
|
|
16
|
+
| Original | [jotai](https://www.npmjs.com/package/jotai) @ 2.19.1 |
|
|
17
|
+
| Processed | 2026-04-07 |
|
|
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
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Atom, type WritableAtom } from './atom.mjs';
|
|
2
2
|
type AnyValue = unknown;
|
|
3
3
|
type AnyError = unknown;
|
|
4
4
|
type AnyAtom = Atom<AnyValue>;
|
|
5
5
|
type AnyWritableAtom = WritableAtom<AnyValue, unknown[], unknown>;
|
|
6
|
+
type WritableAtomWithOnMount<Value, Args extends unknown[], Result> = Omit<WritableAtom<Value, Args, Result>, 'onMount'> & {
|
|
7
|
+
onMount: NonNullable<WritableAtom<Value, Args, Result>['onMount']>;
|
|
8
|
+
};
|
|
6
9
|
type OnUnmount = () => void;
|
|
7
10
|
type EpochNumber = number;
|
|
8
11
|
/**
|
|
@@ -27,6 +30,8 @@ type AtomState<Value = AnyValue> = {
|
|
|
27
30
|
readonly p: Set<AnyAtom>;
|
|
28
31
|
/** The epoch number of the atom. */
|
|
29
32
|
n: EpochNumber;
|
|
33
|
+
/** The store epoch number that last validated the atom. */
|
|
34
|
+
m?: EpochNumber;
|
|
30
35
|
/** Atom value */
|
|
31
36
|
v?: Value;
|
|
32
37
|
/** Atom error */
|
|
@@ -71,7 +76,7 @@ type Callbacks = SetLike<() => void>;
|
|
|
71
76
|
type AtomRead = <Value>(store: Store, atom: Atom<Value>, ...params: Parameters<Atom<Value>['read']>) => Value;
|
|
72
77
|
type AtomWrite = <Value, Args extends unknown[], Result>(store: Store, atom: WritableAtom<Value, Args, Result>, ...params: Parameters<WritableAtom<Value, Args, Result>['write']>) => Result;
|
|
73
78
|
type AtomOnInit = <Value>(store: Store, atom: Atom<Value>) => void;
|
|
74
|
-
type AtomOnMount = <Value, Args extends unknown[], Result>(store: Store, atom:
|
|
79
|
+
type AtomOnMount = <Value, Args extends unknown[], Result>(store: Store, atom: WritableAtomWithOnMount<Value, Args, Result>, setAtom: (...args: Args) => Result) => OnUnmount | void;
|
|
75
80
|
type EnsureAtomState = <Value>(store: Store, atom: Atom<Value>) => AtomState<Value>;
|
|
76
81
|
type FlushCallbacks = (store: Store) => void;
|
|
77
82
|
type RecomputeInvalidatedAtoms = (store: Store) => void;
|
|
@@ -89,6 +94,7 @@ type EnhanceBuildingBlocks = (buildingBlocks: Readonly<BuildingBlocks>) => Reado
|
|
|
89
94
|
type AbortHandlersMap = WeakMapLike<PromiseLike<unknown>, Set<() => void>>;
|
|
90
95
|
type RegisterAbortHandler = <T>(store: Store, promise: PromiseLike<T>, abortHandler: () => void) => void;
|
|
91
96
|
type AbortPromise = <T>(store: Store, promise: PromiseLike<T>) => void;
|
|
97
|
+
type StoreEpochHolder = [n: EpochNumber];
|
|
92
98
|
type Store = {
|
|
93
99
|
get: <Value>(atom: Atom<Value>) => Value;
|
|
94
100
|
set: <Value, Args extends unknown[], Result>(atom: WritableAtom<Value, Args, Result>, ...args: Args) => Result;
|
|
@@ -122,7 +128,8 @@ type BuildingBlocks = [
|
|
|
122
128
|
enhanceBuildingBlocks: EnhanceBuildingBlocks | undefined,
|
|
123
129
|
abortHandlersMap: AbortHandlersMap,
|
|
124
130
|
registerAbortHandler: RegisterAbortHandler,
|
|
125
|
-
abortPromise: AbortPromise
|
|
131
|
+
abortPromise: AbortPromise,
|
|
132
|
+
storeEpochHolder: StoreEpochHolder
|
|
126
133
|
];
|
|
127
134
|
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
135
|
declare function hasInitialValue<T extends Atom<AnyValue>>(atom: T): atom is T & (T extends Atom<infer Value> ? {
|
|
@@ -4,6 +4,9 @@ function hasInitialValue(atom) {
|
|
|
4
4
|
function isActuallyWritableAtom(atom) {
|
|
5
5
|
return !!atom.write;
|
|
6
6
|
}
|
|
7
|
+
function hasOnMount(atom) {
|
|
8
|
+
return !!atom.onMount;
|
|
9
|
+
}
|
|
7
10
|
function isAtomStateInitialized(atomState) {
|
|
8
11
|
return "v" in atomState || "e" in atomState;
|
|
9
12
|
}
|
|
@@ -27,13 +30,18 @@ function addPendingPromiseToDependency(atom, promise, dependencyAtomState) {
|
|
|
27
30
|
}
|
|
28
31
|
}
|
|
29
32
|
function getMountedOrPendingDependents(atom, atomState, mountedMap) {
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
const mounted = mountedMap.get(atom);
|
|
34
|
+
const mountedDependents = mounted == null ? void 0 : mounted.t;
|
|
35
|
+
const pendingDependents = atomState.p;
|
|
36
|
+
if (!(mountedDependents == null ? void 0 : mountedDependents.size)) {
|
|
37
|
+
return pendingDependents;
|
|
38
|
+
}
|
|
39
|
+
if (!pendingDependents.size) {
|
|
40
|
+
return mountedDependents;
|
|
34
41
|
}
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
const dependents = new Set(mountedDependents);
|
|
43
|
+
for (const a of pendingDependents) {
|
|
44
|
+
dependents.add(a);
|
|
37
45
|
}
|
|
38
46
|
return dependents;
|
|
39
47
|
}
|
|
@@ -109,6 +117,7 @@ const BUILDING_BLOCK_ensureAtomState = (store, atom) => {
|
|
|
109
117
|
return atomState;
|
|
110
118
|
};
|
|
111
119
|
const BUILDING_BLOCK_flushCallbacks = (store) => {
|
|
120
|
+
var _a;
|
|
112
121
|
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
113
122
|
const mountedMap = buildingBlocks[1];
|
|
114
123
|
const changedAtoms = buildingBlocks[3];
|
|
@@ -116,6 +125,9 @@ const BUILDING_BLOCK_flushCallbacks = (store) => {
|
|
|
116
125
|
const unmountCallbacks = buildingBlocks[5];
|
|
117
126
|
const storeHooks = buildingBlocks[6];
|
|
118
127
|
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
128
|
+
if (!storeHooks.f && !changedAtoms.size && !mountCallbacks.size && !unmountCallbacks.size) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
119
131
|
const errors = [];
|
|
120
132
|
const call = (fn) => {
|
|
121
133
|
try {
|
|
@@ -129,17 +141,26 @@ const BUILDING_BLOCK_flushCallbacks = (store) => {
|
|
|
129
141
|
call(storeHooks.f);
|
|
130
142
|
}
|
|
131
143
|
const callbacks = /* @__PURE__ */ new Set();
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
144
|
+
for (const atom of changedAtoms) {
|
|
145
|
+
const listeners = (_a = mountedMap.get(atom)) == null ? void 0 : _a.l;
|
|
146
|
+
if (listeners) {
|
|
147
|
+
for (const listener of listeners) {
|
|
148
|
+
callbacks.add(listener);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
137
152
|
changedAtoms.clear();
|
|
138
|
-
unmountCallbacks
|
|
153
|
+
for (const fn of unmountCallbacks) {
|
|
154
|
+
callbacks.add(fn);
|
|
155
|
+
}
|
|
139
156
|
unmountCallbacks.clear();
|
|
140
|
-
mountCallbacks
|
|
157
|
+
for (const fn of mountCallbacks) {
|
|
158
|
+
callbacks.add(fn);
|
|
159
|
+
}
|
|
141
160
|
mountCallbacks.clear();
|
|
142
|
-
callbacks
|
|
161
|
+
for (const fn of callbacks) {
|
|
162
|
+
call(fn);
|
|
163
|
+
}
|
|
143
164
|
if (changedAtoms.size) {
|
|
144
165
|
recomputeInvalidatedAtoms(store);
|
|
145
166
|
}
|
|
@@ -156,36 +177,51 @@ const BUILDING_BLOCK_recomputeInvalidatedAtoms = (store) => {
|
|
|
156
177
|
const ensureAtomState = buildingBlocks[11];
|
|
157
178
|
const readAtomState = buildingBlocks[14];
|
|
158
179
|
const mountDependencies = buildingBlocks[17];
|
|
159
|
-
|
|
180
|
+
if (!changedAtoms.size) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const sortedReversedAtoms = [];
|
|
184
|
+
const sortedReversedStates = [];
|
|
160
185
|
const visiting = /* @__PURE__ */ new WeakSet();
|
|
161
186
|
const visited = /* @__PURE__ */ new WeakSet();
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
187
|
+
const stackAtoms = [];
|
|
188
|
+
const stackStates = [];
|
|
189
|
+
for (const atom of changedAtoms) {
|
|
190
|
+
stackAtoms.push(atom);
|
|
191
|
+
stackStates.push(ensureAtomState(store, atom));
|
|
192
|
+
}
|
|
193
|
+
while (stackAtoms.length) {
|
|
194
|
+
const top = stackAtoms.length - 1;
|
|
195
|
+
const a = stackAtoms[top];
|
|
196
|
+
const aState = stackStates[top];
|
|
166
197
|
if (visited.has(a)) {
|
|
167
|
-
|
|
198
|
+
stackAtoms.pop();
|
|
199
|
+
stackStates.pop();
|
|
168
200
|
continue;
|
|
169
201
|
}
|
|
170
202
|
if (visiting.has(a)) {
|
|
171
203
|
if (invalidatedAtoms.get(a) === aState.n) {
|
|
172
|
-
|
|
204
|
+
sortedReversedAtoms.push(a);
|
|
205
|
+
sortedReversedStates.push(aState);
|
|
173
206
|
} else if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production" && invalidatedAtoms.has(a)) {
|
|
174
207
|
throw new Error("[Bug] invalidated atom exists");
|
|
175
208
|
}
|
|
176
209
|
visited.add(a);
|
|
177
|
-
|
|
210
|
+
stackAtoms.pop();
|
|
211
|
+
stackStates.pop();
|
|
178
212
|
continue;
|
|
179
213
|
}
|
|
180
214
|
visiting.add(a);
|
|
181
215
|
for (const d of getMountedOrPendingDependents(a, aState, mountedMap)) {
|
|
182
216
|
if (!visiting.has(d)) {
|
|
183
|
-
|
|
217
|
+
stackAtoms.push(d);
|
|
218
|
+
stackStates.push(ensureAtomState(store, d));
|
|
184
219
|
}
|
|
185
220
|
}
|
|
186
221
|
}
|
|
187
|
-
for (let i =
|
|
188
|
-
const
|
|
222
|
+
for (let i = sortedReversedAtoms.length - 1; i >= 0; --i) {
|
|
223
|
+
const a = sortedReversedAtoms[i];
|
|
224
|
+
const aState = sortedReversedStates[i];
|
|
189
225
|
let hasChangedDeps = false;
|
|
190
226
|
for (const dep of aState.d.keys()) {
|
|
191
227
|
if (dep !== a && changedAtoms.has(dep)) {
|
|
@@ -218,9 +254,19 @@ const BUILDING_BLOCK_readAtomState = (store, atom) => {
|
|
|
218
254
|
const mountDependencies = buildingBlocks[17];
|
|
219
255
|
const setAtomStateValueOrPromise = buildingBlocks[20];
|
|
220
256
|
const registerAbortHandler = buildingBlocks[26];
|
|
257
|
+
const storeEpochHolder = buildingBlocks[28];
|
|
221
258
|
const atomState = ensureAtomState(store, atom);
|
|
259
|
+
const storeEpochNumber = storeEpochHolder[0];
|
|
222
260
|
if (isAtomStateInitialized(atomState)) {
|
|
223
|
-
if (
|
|
261
|
+
if (
|
|
262
|
+
// If the atom is mounted, we can use cached atom state,
|
|
263
|
+
// because it should have been updated by dependencies.
|
|
264
|
+
// We can't use the cache if the atom is invalidated.
|
|
265
|
+
mountedMap.has(atom) && invalidatedAtoms.get(atom) !== atomState.n || // If atom is not mounted, we can use cached atom state,
|
|
266
|
+
// only if store hasn't been mutated.
|
|
267
|
+
atomState.m === storeEpochNumber
|
|
268
|
+
) {
|
|
269
|
+
atomState.m = storeEpochNumber;
|
|
224
270
|
return atomState;
|
|
225
271
|
}
|
|
226
272
|
let hasChangedDeps = false;
|
|
@@ -231,17 +277,15 @@ const BUILDING_BLOCK_readAtomState = (store, atom) => {
|
|
|
231
277
|
}
|
|
232
278
|
}
|
|
233
279
|
if (!hasChangedDeps) {
|
|
280
|
+
atomState.m = storeEpochNumber;
|
|
234
281
|
return atomState;
|
|
235
282
|
}
|
|
236
283
|
}
|
|
237
284
|
let isSync = true;
|
|
238
285
|
const prevDeps = new Set(atomState.d.keys());
|
|
239
|
-
const nextDeps = /* @__PURE__ */ new Map();
|
|
240
286
|
const pruneDependencies = () => {
|
|
241
287
|
for (const a of prevDeps) {
|
|
242
|
-
|
|
243
|
-
atomState.d.delete(a);
|
|
244
|
-
}
|
|
288
|
+
atomState.d.delete(a);
|
|
245
289
|
}
|
|
246
290
|
};
|
|
247
291
|
const mountDependenciesIfAsync = () => {
|
|
@@ -271,7 +315,7 @@ const BUILDING_BLOCK_readAtomState = (store, atom) => {
|
|
|
271
315
|
try {
|
|
272
316
|
return returnAtomValue(aState);
|
|
273
317
|
} finally {
|
|
274
|
-
|
|
318
|
+
prevDeps.delete(a);
|
|
275
319
|
atomState.d.set(a, aState.n);
|
|
276
320
|
if (isPromiseLike(atomState.v)) {
|
|
277
321
|
addPendingPromiseToDependency(atom, atomState.v, aState);
|
|
@@ -344,11 +388,13 @@ const BUILDING_BLOCK_readAtomState = (store, atom) => {
|
|
|
344
388
|
pruneDependencies();
|
|
345
389
|
}
|
|
346
390
|
(_a = storeHooks.r) == null ? void 0 : _a.call(storeHooks, atom);
|
|
391
|
+
atomState.m = storeEpochNumber;
|
|
347
392
|
return atomState;
|
|
348
393
|
} catch (error) {
|
|
349
394
|
delete atomState.v;
|
|
350
395
|
atomState.e = error;
|
|
351
396
|
++atomState.n;
|
|
397
|
+
atomState.m = storeEpochNumber;
|
|
352
398
|
return atomState;
|
|
353
399
|
} finally {
|
|
354
400
|
isSync = false;
|
|
@@ -390,6 +436,7 @@ const BUILDING_BLOCK_writeAtomState = (store, atom, ...args) => {
|
|
|
390
436
|
const writeAtomState = buildingBlocks[16];
|
|
391
437
|
const mountDependencies = buildingBlocks[17];
|
|
392
438
|
const setAtomStateValueOrPromise = buildingBlocks[20];
|
|
439
|
+
const storeEpochHolder = buildingBlocks[28];
|
|
393
440
|
let isSync = true;
|
|
394
441
|
const getter = (a) => returnAtomValue(readAtomState(store, a));
|
|
395
442
|
const setter = (a, ...args2) => {
|
|
@@ -408,6 +455,7 @@ const BUILDING_BLOCK_writeAtomState = (store, atom, ...args) => {
|
|
|
408
455
|
setAtomStateValueOrPromise(store, a, v);
|
|
409
456
|
mountDependencies(store, a);
|
|
410
457
|
if (prevEpochNumber !== aState.n) {
|
|
458
|
+
++storeEpochHolder[0];
|
|
411
459
|
changedAtoms.add(a);
|
|
412
460
|
invalidateDependents(store, a);
|
|
413
461
|
(_a = storeHooks.c) == null ? void 0 : _a.call(storeHooks, a);
|
|
@@ -441,7 +489,7 @@ const BUILDING_BLOCK_mountDependencies = (store, atom) => {
|
|
|
441
489
|
const unmountAtom = buildingBlocks[19];
|
|
442
490
|
const atomState = ensureAtomState(store, atom);
|
|
443
491
|
const mounted = mountedMap.get(atom);
|
|
444
|
-
if (mounted) {
|
|
492
|
+
if (mounted && atomState.d.size > 0) {
|
|
445
493
|
for (const [a, n] of atomState.d) {
|
|
446
494
|
if (!mounted.d.has(a)) {
|
|
447
495
|
const aState = ensureAtomState(store, a);
|
|
@@ -491,7 +539,7 @@ const BUILDING_BLOCK_mountAtom = (store, atom) => {
|
|
|
491
539
|
t: /* @__PURE__ */ new Set()
|
|
492
540
|
};
|
|
493
541
|
mountedMap.set(atom, mounted);
|
|
494
|
-
if (isActuallyWritableAtom(atom)) {
|
|
542
|
+
if (isActuallyWritableAtom(atom) && hasOnMount(atom)) {
|
|
495
543
|
const processOnMount = () => {
|
|
496
544
|
let isSync = true;
|
|
497
545
|
const setAtom = (...args) => {
|
|
@@ -712,7 +760,9 @@ function buildStore(...buildArgs) {
|
|
|
712
760
|
/* @__PURE__ */ new WeakMap(),
|
|
713
761
|
// abortHandlersMap
|
|
714
762
|
BUILDING_BLOCK_registerAbortHandler,
|
|
715
|
-
BUILDING_BLOCK_abortPromise
|
|
763
|
+
BUILDING_BLOCK_abortPromise,
|
|
764
|
+
// store epoch
|
|
765
|
+
[0]
|
|
716
766
|
].map((fn, i) => buildArgs[i] || fn);
|
|
717
767
|
buildingBlockMap.set(store, Object.freeze(buildingBlocks));
|
|
718
768
|
return store;
|
|
@@ -17,7 +17,7 @@ type SubscribableObservable<T> = {
|
|
|
17
17
|
subscribe(next: (value: T) => void): Subscription;
|
|
18
18
|
};
|
|
19
19
|
type SymbolObservable<T> = {
|
|
20
|
-
[
|
|
20
|
+
[key: symbol]: () => SubscribableObservable<T>;
|
|
21
21
|
};
|
|
22
22
|
type ObservableLike<T> = SubscribableObservable<T> | SymbolObservable<T>;
|
|
23
23
|
type SubjectLike<T> = ObservableLike<T> & Observer<T>;
|
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.1-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-
|
|
124
|
+
"originalVersion": "2.19.1",
|
|
125
|
+
"processedAt": "2026-04-07T16:33:28.631Z",
|
|
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)]}})}}));
|