@but212/atom-effect 0.19.0 → 0.19.1
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/dist/atom-effect.min.js +1 -1
- package/dist/atom-effect.min.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +13 -66
- package/dist/index.mjs +200 -215
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
const tt = {
|
|
2
2
|
ONE_SECOND_MS: 1e3
|
|
3
|
-
},
|
|
3
|
+
}, k = {
|
|
4
4
|
IDLE: "idle",
|
|
5
5
|
PENDING: "pending",
|
|
6
6
|
RESOLVED: "resolved",
|
|
7
7
|
REJECTED: "rejected"
|
|
8
|
-
},
|
|
8
|
+
}, w = {
|
|
9
9
|
DISPOSED: 1
|
|
10
|
-
},
|
|
11
|
-
...
|
|
10
|
+
}, l = {
|
|
11
|
+
...w,
|
|
12
12
|
EXECUTING: 8
|
|
13
13
|
}, o = {
|
|
14
|
-
...
|
|
14
|
+
...w,
|
|
15
|
+
/** Marker bit: identifies this node as a computed. */
|
|
16
|
+
IS_COMPUTED: 2,
|
|
15
17
|
DIRTY: 8,
|
|
16
18
|
IDLE: 16,
|
|
17
19
|
PENDING: 32,
|
|
@@ -20,10 +22,10 @@ const tt = {
|
|
|
20
22
|
RECOMPUTING: 256,
|
|
21
23
|
HAS_ERROR: 512
|
|
22
24
|
}, d = {
|
|
23
|
-
...
|
|
25
|
+
...w,
|
|
24
26
|
SYNC: 8,
|
|
25
27
|
NOTIFICATION_SCHEDULED: 16
|
|
26
|
-
},
|
|
28
|
+
}, It = {
|
|
27
29
|
MAX_SIZE: 1e3,
|
|
28
30
|
WARMUP_SIZE: 100,
|
|
29
31
|
ENABLE_STATS: !1
|
|
@@ -40,7 +42,7 @@ const tt = {
|
|
|
40
42
|
BATCH_QUEUE_SHRINK_THRESHOLD: 1e3
|
|
41
43
|
}, et = {
|
|
42
44
|
WARN_INFINITE_LOOP: !0
|
|
43
|
-
},
|
|
45
|
+
}, y = 1073741823, _ = typeof process < "u" && process.env && process.env.NODE_ENV !== "production" || typeof __DEV__ < "u" && !!__DEV__, st = Object.freeze([]);
|
|
44
46
|
class T extends Error {
|
|
45
47
|
constructor(t, e = null, s = !0) {
|
|
46
48
|
super(t), this.cause = e, this.recoverable = s, this.timestamp = /* @__PURE__ */ new Date(), this.name = "AtomError";
|
|
@@ -56,7 +58,7 @@ class S extends T {
|
|
|
56
58
|
super(t, e, !1), this.name = "EffectError";
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
|
-
class
|
|
61
|
+
class b extends T {
|
|
60
62
|
constructor(t, e = null) {
|
|
61
63
|
super(t, e, !1), this.name = "SchedulerError";
|
|
62
64
|
}
|
|
@@ -104,7 +106,7 @@ function j(i, t, e) {
|
|
|
104
106
|
const c = e[r];
|
|
105
107
|
if (c && c.fn === n) return;
|
|
106
108
|
}
|
|
107
|
-
e.push(new
|
|
109
|
+
e.push(new P(n, void 0));
|
|
108
110
|
return;
|
|
109
111
|
}
|
|
110
112
|
if ("addDependency" in t) {
|
|
@@ -116,33 +118,29 @@ function j(i, t, e) {
|
|
|
116
118
|
const h = e[n];
|
|
117
119
|
if (h && h.sub === s) return;
|
|
118
120
|
}
|
|
119
|
-
e.push(new
|
|
121
|
+
e.push(new P(void 0, s));
|
|
120
122
|
}
|
|
121
123
|
function ht(i, t, e) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const h = r.node;
|
|
136
|
-
h._tempUnsub !== void 0 && (h._tempUnsub(), h._tempUnsub = void 0), r.unsub = void 0;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
124
|
+
const s = /* @__PURE__ */ new Map();
|
|
125
|
+
for (let n = 0, r = t.length; n < r; n++) {
|
|
126
|
+
const h = t[n];
|
|
127
|
+
h?.unsub && (s.set(h.node, h.unsub), h.unsub = void 0);
|
|
128
|
+
}
|
|
129
|
+
for (let n = 0, r = i.length; n < r; n++) {
|
|
130
|
+
const h = i[n];
|
|
131
|
+
if (!h) continue;
|
|
132
|
+
const c = h.node, E = s.get(c);
|
|
133
|
+
E !== void 0 ? (h.unsub = E, s.delete(c)) : (g.checkCircular(c, e), h.unsub = c.subscribe(e));
|
|
134
|
+
}
|
|
135
|
+
for (const n of s.values())
|
|
136
|
+
n();
|
|
139
137
|
}
|
|
140
|
-
class
|
|
138
|
+
class R {
|
|
141
139
|
constructor(t, e, s = void 0) {
|
|
142
140
|
this.node = t, this.version = e, this.unsub = s;
|
|
143
141
|
}
|
|
144
142
|
}
|
|
145
|
-
class
|
|
143
|
+
class P {
|
|
146
144
|
constructor(t, e) {
|
|
147
145
|
this.fn = t, this.sub = e;
|
|
148
146
|
}
|
|
@@ -181,7 +179,7 @@ function C(i, t, e) {
|
|
|
181
179
|
}
|
|
182
180
|
class q {
|
|
183
181
|
constructor() {
|
|
184
|
-
this.flags = 0, this.version = 0, this._lastSeenEpoch = -1, this._modifiedAtEpoch = -1, this.id = ot() &
|
|
182
|
+
this.flags = 0, this.version = 0, this._lastSeenEpoch = -1, this._modifiedAtEpoch = -1, this.id = ot() & y;
|
|
185
183
|
}
|
|
186
184
|
}
|
|
187
185
|
class $ extends q {
|
|
@@ -203,7 +201,7 @@ class $ extends q {
|
|
|
203
201
|
return _ && console.warn("Duplicate subscription ignored."), () => {
|
|
204
202
|
};
|
|
205
203
|
}
|
|
206
|
-
const n = new
|
|
204
|
+
const n = new P(
|
|
207
205
|
e ? t : void 0,
|
|
208
206
|
e ? void 0 : t
|
|
209
207
|
);
|
|
@@ -235,144 +233,131 @@ class $ extends q {
|
|
|
235
233
|
console.error(C(t, T, u.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED));
|
|
236
234
|
}
|
|
237
235
|
}
|
|
238
|
-
let
|
|
239
|
-
const J = () => (
|
|
240
|
-
let
|
|
236
|
+
let A = 0;
|
|
237
|
+
const J = () => (A = A + 1 & y || 1, A), ct = () => A, v = (i) => i + 1 & y;
|
|
238
|
+
let M = 0, B = 0, L = !1;
|
|
241
239
|
function H() {
|
|
242
|
-
return
|
|
240
|
+
return L ? (_ && console.warn("startFlush() called during flush - ignored"), !1) : (L = !0, M = M + 1 & y || 1, B = 0, !0);
|
|
243
241
|
}
|
|
244
242
|
const X = () => {
|
|
245
|
-
|
|
246
|
-
}, ut = () =>
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
/** Epoch counter */
|
|
252
|
-
_epoch: 0,
|
|
253
|
-
/** State flags */
|
|
254
|
-
_isProcessing: !1,
|
|
255
|
-
_isBatching: !1,
|
|
256
|
-
_isFlushingSync: !1,
|
|
257
|
-
/** Batching state */
|
|
258
|
-
_batchDepth: 0,
|
|
259
|
-
_batchQueue: [],
|
|
260
|
-
_batchQueueSize: 0,
|
|
261
|
-
/** Config */
|
|
262
|
-
_maxFlushIterations: I.MAX_FLUSH_ITERATIONS,
|
|
243
|
+
L = !1;
|
|
244
|
+
}, ut = () => L ? ++B : 0;
|
|
245
|
+
class _t {
|
|
246
|
+
constructor() {
|
|
247
|
+
this._queueBuffer = [[], []], this._bufferIndex = 0, this._size = 0, this._epoch = 0, this._isProcessing = !1, this._isBatching = !1, this._isFlushingSync = !1, this._batchDepth = 0, this._batchQueue = [], this._batchQueueSize = 0, this._maxFlushIterations = I.MAX_FLUSH_ITERATIONS, this.onOverflow = null, this._boundRunLoop = this._runLoop.bind(this);
|
|
248
|
+
}
|
|
263
249
|
get phase() {
|
|
264
250
|
return this._isProcessing || this._isFlushingSync ? 2 : this._isBatching ? 1 : 0;
|
|
265
|
-
}
|
|
251
|
+
}
|
|
266
252
|
get queueSize() {
|
|
267
253
|
return this._size;
|
|
268
|
-
}
|
|
254
|
+
}
|
|
269
255
|
get isBatching() {
|
|
270
256
|
return this._isBatching;
|
|
271
|
-
}
|
|
257
|
+
}
|
|
272
258
|
/**
|
|
273
259
|
* Schedules job.
|
|
274
260
|
*/
|
|
275
|
-
schedule(
|
|
276
|
-
if (_ && typeof
|
|
277
|
-
throw new
|
|
278
|
-
if (
|
|
279
|
-
if (
|
|
280
|
-
this._batchQueue[this._batchQueueSize++] =
|
|
261
|
+
schedule(t) {
|
|
262
|
+
if (_ && typeof t != "function")
|
|
263
|
+
throw new b("Scheduler callback must be a function");
|
|
264
|
+
if (t._nextEpoch !== this._epoch) {
|
|
265
|
+
if (t._nextEpoch = this._epoch, this._isBatching || this._isFlushingSync) {
|
|
266
|
+
this._batchQueue[this._batchQueueSize++] = t;
|
|
281
267
|
return;
|
|
282
268
|
}
|
|
283
|
-
this._queueBuffer[this._bufferIndex][this._size++] =
|
|
269
|
+
this._queueBuffer[this._bufferIndex][this._size++] = t, this._isProcessing || this._flush();
|
|
284
270
|
}
|
|
285
|
-
}
|
|
271
|
+
}
|
|
286
272
|
/**
|
|
287
273
|
* Triggers flush.
|
|
288
274
|
*/
|
|
289
275
|
_flush() {
|
|
290
|
-
this._isProcessing || this._size === 0 || (this._isProcessing = !0, queueMicrotask(this.
|
|
291
|
-
}
|
|
276
|
+
this._isProcessing || this._size === 0 || (this._isProcessing = !0, queueMicrotask(this._boundRunLoop));
|
|
277
|
+
}
|
|
292
278
|
/**
|
|
293
279
|
* Scheduler loop.
|
|
294
280
|
*/
|
|
295
|
-
_runLoop
|
|
281
|
+
_runLoop() {
|
|
296
282
|
try {
|
|
297
|
-
if (
|
|
298
|
-
const
|
|
299
|
-
|
|
283
|
+
if (this._size === 0) return;
|
|
284
|
+
const t = H();
|
|
285
|
+
this._drainQueue(), t && X();
|
|
300
286
|
} finally {
|
|
301
|
-
|
|
287
|
+
this._isProcessing = !1, this._size > 0 && !this._isBatching && this._flush();
|
|
302
288
|
}
|
|
303
|
-
}
|
|
289
|
+
}
|
|
304
290
|
_flushSync() {
|
|
305
291
|
this._isFlushingSync = !0;
|
|
306
|
-
const
|
|
292
|
+
const t = H();
|
|
307
293
|
try {
|
|
308
294
|
this._mergeBatchQueue(), this._drainQueue();
|
|
309
295
|
} finally {
|
|
310
|
-
this._isFlushingSync = !1,
|
|
296
|
+
this._isFlushingSync = !1, t && X();
|
|
311
297
|
}
|
|
312
|
-
}
|
|
298
|
+
}
|
|
313
299
|
_mergeBatchQueue() {
|
|
314
300
|
if (this._batchQueueSize === 0) return;
|
|
315
|
-
const
|
|
316
|
-
let
|
|
317
|
-
for (let
|
|
318
|
-
const
|
|
319
|
-
|
|
301
|
+
const t = ++this._epoch, e = this._batchQueue, s = this._queueBuffer[this._bufferIndex];
|
|
302
|
+
let n = this._size;
|
|
303
|
+
for (let r = 0; r < this._batchQueueSize; r++) {
|
|
304
|
+
const h = e[r];
|
|
305
|
+
h._nextEpoch !== t && (h._nextEpoch = t, s[n++] = h);
|
|
320
306
|
}
|
|
321
|
-
this._size =
|
|
322
|
-
}
|
|
307
|
+
this._size = n, this._batchQueueSize = 0, e.length > I.BATCH_QUEUE_SHRINK_THRESHOLD && (e.length = 0);
|
|
308
|
+
}
|
|
323
309
|
_drainQueue() {
|
|
324
|
-
let
|
|
310
|
+
let t = 0;
|
|
325
311
|
for (; this._size > 0; ) {
|
|
326
|
-
if (++
|
|
312
|
+
if (++t > this._maxFlushIterations) {
|
|
327
313
|
this._handleFlushOverflow();
|
|
328
314
|
return;
|
|
329
315
|
}
|
|
330
316
|
this._processQueue(), this._mergeBatchQueue();
|
|
331
317
|
}
|
|
332
|
-
}
|
|
318
|
+
}
|
|
333
319
|
_processQueue() {
|
|
334
|
-
const
|
|
335
|
-
this._bufferIndex =
|
|
336
|
-
for (let
|
|
320
|
+
const t = this._bufferIndex, e = this._queueBuffer[t], s = this._size;
|
|
321
|
+
this._bufferIndex = t ^ 1, this._size = 0, this._epoch++;
|
|
322
|
+
for (let n = 0; n < s; n++)
|
|
337
323
|
try {
|
|
338
|
-
|
|
339
|
-
} catch (
|
|
340
|
-
console.error(new
|
|
324
|
+
e[n]();
|
|
325
|
+
} catch (r) {
|
|
326
|
+
console.error(new b("Error occurred during scheduler execution", r));
|
|
341
327
|
}
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
/** Overflow callback */
|
|
345
|
-
onOverflow: null,
|
|
328
|
+
e.length = 0;
|
|
329
|
+
}
|
|
346
330
|
_handleFlushOverflow() {
|
|
347
|
-
const
|
|
331
|
+
const t = this._size + this._batchQueueSize;
|
|
348
332
|
if (console.error(
|
|
349
|
-
new
|
|
350
|
-
u.SCHEDULER_FLUSH_OVERFLOW(this._maxFlushIterations,
|
|
333
|
+
new b(
|
|
334
|
+
u.SCHEDULER_FLUSH_OVERFLOW(this._maxFlushIterations, t)
|
|
351
335
|
)
|
|
352
336
|
), this._size = 0, this._queueBuffer[this._bufferIndex].length = 0, this._batchQueueSize = 0, this.onOverflow)
|
|
353
337
|
try {
|
|
354
|
-
this.onOverflow(
|
|
338
|
+
this.onOverflow(t);
|
|
355
339
|
} catch {
|
|
356
340
|
}
|
|
357
|
-
}
|
|
341
|
+
}
|
|
358
342
|
startBatch() {
|
|
359
343
|
this._batchDepth++, this._isBatching = !0;
|
|
360
|
-
}
|
|
344
|
+
}
|
|
361
345
|
endBatch() {
|
|
362
346
|
if (this._batchDepth === 0) {
|
|
363
347
|
_ && console.warn("endBatch() called without matching startBatch(). Ignoring.");
|
|
364
348
|
return;
|
|
365
349
|
}
|
|
366
350
|
--this._batchDepth === 0 && (this._flushSync(), this._isBatching = !1);
|
|
367
|
-
}
|
|
368
|
-
setMaxFlushIterations(
|
|
369
|
-
if (
|
|
370
|
-
throw new
|
|
351
|
+
}
|
|
352
|
+
setMaxFlushIterations(t) {
|
|
353
|
+
if (t < I.MIN_FLUSH_ITERATIONS)
|
|
354
|
+
throw new b(
|
|
371
355
|
`Max flush iterations must be at least ${I.MIN_FLUSH_ITERATIONS}`
|
|
372
356
|
);
|
|
373
|
-
this._maxFlushIterations =
|
|
357
|
+
this._maxFlushIterations = t;
|
|
374
358
|
}
|
|
375
|
-
}
|
|
359
|
+
}
|
|
360
|
+
const O = new _t(), f = {
|
|
376
361
|
/** Active listener. */
|
|
377
362
|
current: null,
|
|
378
363
|
/**
|
|
@@ -392,35 +377,35 @@ const X = () => {
|
|
|
392
377
|
}
|
|
393
378
|
}
|
|
394
379
|
};
|
|
395
|
-
function
|
|
396
|
-
const t =
|
|
380
|
+
function Dt(i) {
|
|
381
|
+
const t = f.current;
|
|
397
382
|
if (t === null) return i();
|
|
398
|
-
|
|
383
|
+
f.current = null;
|
|
399
384
|
try {
|
|
400
385
|
return i();
|
|
401
386
|
} finally {
|
|
402
|
-
|
|
387
|
+
f.current = t;
|
|
403
388
|
}
|
|
404
389
|
}
|
|
405
|
-
class
|
|
390
|
+
class lt extends $ {
|
|
406
391
|
constructor(t, e) {
|
|
407
392
|
super(), this._pendingOldValue = void 0, this._notifyTask = void 0, this._subscribers = [], this._value = t, e && (this.flags |= d.SYNC), g.attachDebugInfo(this, "atom", this.id);
|
|
408
393
|
}
|
|
409
394
|
get value() {
|
|
410
|
-
const t =
|
|
395
|
+
const t = f.current;
|
|
411
396
|
return t && j(this, t, this._subscribers), this._value;
|
|
412
397
|
}
|
|
413
398
|
set value(t) {
|
|
414
399
|
const e = this._value;
|
|
415
400
|
if (Object.is(e, t)) return;
|
|
416
|
-
this._value = t, this.version =
|
|
401
|
+
this._value = t, this.version = v(this.version);
|
|
417
402
|
const s = this.flags;
|
|
418
403
|
if (!(this._subscribers.length === 0 || s & d.NOTIFICATION_SCHEDULED)) {
|
|
419
|
-
if (this._pendingOldValue = e, this.flags = s | d.NOTIFICATION_SCHEDULED, s & d.SYNC && !
|
|
404
|
+
if (this._pendingOldValue = e, this.flags = s | d.NOTIFICATION_SCHEDULED, s & d.SYNC && !O.isBatching) {
|
|
420
405
|
this._flushNotifications();
|
|
421
406
|
return;
|
|
422
407
|
}
|
|
423
|
-
this._notifyTask || (this._notifyTask = () => this._flushNotifications()),
|
|
408
|
+
this._notifyTask || (this._notifyTask = () => this._flushNotifications()), O.schedule(this._notifyTask);
|
|
424
409
|
}
|
|
425
410
|
}
|
|
426
411
|
/**
|
|
@@ -440,10 +425,10 @@ class _t extends $ {
|
|
|
440
425
|
this.flags & d.DISPOSED || (this._subscribers.length = 0, this.flags |= d.DISPOSED, this._value = void 0, this._pendingOldValue = void 0, this._notifyTask = void 0);
|
|
441
426
|
}
|
|
442
427
|
}
|
|
443
|
-
function
|
|
444
|
-
return new
|
|
428
|
+
function St(i, t = {}) {
|
|
429
|
+
return new lt(i, t.sync ?? !1);
|
|
445
430
|
}
|
|
446
|
-
class
|
|
431
|
+
class at {
|
|
447
432
|
/**
|
|
448
433
|
* @param limit - Max unique arrays to hold (default: 50). Prevents the pool itself from consuming too much memory.
|
|
449
434
|
* @param capacity - Max length of an array to accept (default: 256).
|
|
@@ -510,42 +495,42 @@ class lt {
|
|
|
510
495
|
});
|
|
511
496
|
}
|
|
512
497
|
}
|
|
513
|
-
const
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
const
|
|
519
|
-
function
|
|
498
|
+
const N = (i) => Object.freeze(i);
|
|
499
|
+
N([]);
|
|
500
|
+
N([]);
|
|
501
|
+
N([]);
|
|
502
|
+
N([]);
|
|
503
|
+
const a = N([]), D = new at();
|
|
504
|
+
function ft(i) {
|
|
520
505
|
return i !== null && typeof i == "object" && "value" in i && typeof i.subscribe == "function";
|
|
521
506
|
}
|
|
522
|
-
function St(i) {
|
|
523
|
-
return at(i) && typeof i.invalidate == "function";
|
|
524
|
-
}
|
|
525
507
|
function gt(i) {
|
|
508
|
+
return ft(i) && typeof i.invalidate == "function";
|
|
509
|
+
}
|
|
510
|
+
function Ct(i) {
|
|
526
511
|
return i !== null && typeof i == "object" && typeof i.dispose == "function" && typeof i.run == "function";
|
|
527
512
|
}
|
|
528
513
|
function K(i) {
|
|
529
514
|
return i !== null && typeof i == "object" && typeof i.then == "function";
|
|
530
515
|
}
|
|
531
|
-
const W = o.RESOLVED | o.PENDING | o.REJECTED,
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
const
|
|
516
|
+
const W = o.RESOLVED | o.PENDING | o.REJECTED, m = Array(W + 1).fill(k.IDLE);
|
|
517
|
+
m[o.RESOLVED] = k.RESOLVED;
|
|
518
|
+
m[o.PENDING] = k.PENDING;
|
|
519
|
+
m[o.REJECTED] = k.REJECTED;
|
|
520
|
+
const Et = 3, Y = Number.MAX_SAFE_INTEGER - 1, dt = o.REJECTED | o.HAS_ERROR;
|
|
536
521
|
class Z extends $ {
|
|
537
522
|
constructor(t, e = {}) {
|
|
538
523
|
if (typeof t != "function") throw new p(u.COMPUTED_MUST_BE_FUNCTION);
|
|
539
|
-
super(), this._error = null, this._promiseId = 0, this._subscribers = [], this._links =
|
|
524
|
+
super(), this._error = null, this._promiseId = 0, this._subscribers = [], this._links = a, this._cachedErrors = null, this._errorCacheEpoch = -1, this._asyncStartAggregateVersion = 0, this._asyncRetryCount = 0, this._errorDepCount = 0, this._trackEpoch = -1, this._trackLinks = a, this._trackCount = 0, this._value = void 0, this.flags = o.IS_COMPUTED | o.DIRTY | o.IDLE, this._equal = e.equal ?? Object.is, this._fn = t, this._defaultValue = "defaultValue" in e ? e.defaultValue : x, this._onError = e.onError ?? null;
|
|
540
525
|
const s = e.maxAsyncRetries;
|
|
541
|
-
if (this._maxAsyncRetries = s != null && s >= 0 ? s :
|
|
526
|
+
if (this._maxAsyncRetries = s != null && s >= 0 ? s : Et, g.attachDebugInfo(this, "computed", this.id), e.lazy === !1)
|
|
542
527
|
try {
|
|
543
528
|
this._recompute();
|
|
544
529
|
} catch {
|
|
545
530
|
}
|
|
546
531
|
}
|
|
547
532
|
_track() {
|
|
548
|
-
const t =
|
|
533
|
+
const t = f.current;
|
|
549
534
|
t && j(this, t, this._subscribers);
|
|
550
535
|
}
|
|
551
536
|
get value() {
|
|
@@ -576,7 +561,7 @@ class Z extends $ {
|
|
|
576
561
|
return this._value;
|
|
577
562
|
}
|
|
578
563
|
get state() {
|
|
579
|
-
return this._track(),
|
|
564
|
+
return this._track(), m[this.flags & W];
|
|
580
565
|
}
|
|
581
566
|
get hasError() {
|
|
582
567
|
if (this._track(), this.flags & (o.REJECTED | o.HAS_ERROR) || this._errorDepCount > 0) return !0;
|
|
@@ -601,12 +586,12 @@ class Z extends $ {
|
|
|
601
586
|
for (let r = 0, h = s.length; r < h; r++) {
|
|
602
587
|
const c = s[r].node;
|
|
603
588
|
if (c.flags & o.HAS_ERROR) {
|
|
604
|
-
const
|
|
605
|
-
if (
|
|
606
|
-
const V =
|
|
607
|
-
for (let
|
|
608
|
-
const
|
|
609
|
-
|
|
589
|
+
const E = c;
|
|
590
|
+
if (E.errors) {
|
|
591
|
+
const V = E.errors;
|
|
592
|
+
for (let F = 0; F < V.length; F++) {
|
|
593
|
+
const U = V[F];
|
|
594
|
+
U && e.indexOf(U) === -1 && e.push(U);
|
|
610
595
|
}
|
|
611
596
|
}
|
|
612
597
|
}
|
|
@@ -629,10 +614,10 @@ class Z extends $ {
|
|
|
629
614
|
dispose() {
|
|
630
615
|
if (this.flags & o.DISPOSED) return;
|
|
631
616
|
const t = this._links;
|
|
632
|
-
if (t !==
|
|
617
|
+
if (t !== a) {
|
|
633
618
|
for (let e = 0, s = t.length; e < s; e++)
|
|
634
619
|
t[e].unsub?.();
|
|
635
|
-
D.release(t), this._links =
|
|
620
|
+
D.release(t), this._links = a;
|
|
636
621
|
}
|
|
637
622
|
this._subscribers.length = 0, this.flags = o.DISPOSED | o.DIRTY | o.IDLE, this._error = null, this._value = void 0, this._promiseId = (this._promiseId + 1) % Y, this._cachedErrors = null, this._errorCacheEpoch = -1;
|
|
638
623
|
}
|
|
@@ -642,7 +627,7 @@ class Z extends $ {
|
|
|
642
627
|
const e = this._trackLinks[this._trackCount];
|
|
643
628
|
e.node = t, e.version = t.version;
|
|
644
629
|
} else
|
|
645
|
-
this._trackLinks.push(new
|
|
630
|
+
this._trackLinks.push(new R(t, t.version));
|
|
646
631
|
this._trackCount++;
|
|
647
632
|
}
|
|
648
633
|
}
|
|
@@ -665,7 +650,7 @@ class Z extends $ {
|
|
|
665
650
|
this._trackEpoch = J(), this._trackLinks = D.acquire(), this._trackCount = 0;
|
|
666
651
|
let e = !1;
|
|
667
652
|
try {
|
|
668
|
-
const s =
|
|
653
|
+
const s = f.run(this, this._fn);
|
|
669
654
|
this._commitDeps(t), e = !0, this._updateErrorDepCount(), K(s) ? this._handleAsyncComputation(s) : this._finalizeResolution(s);
|
|
670
655
|
} catch (s) {
|
|
671
656
|
if (!e)
|
|
@@ -676,7 +661,7 @@ class Z extends $ {
|
|
|
676
661
|
}
|
|
677
662
|
this._handleError(s, u.COMPUTED_COMPUTATION_FAILED, !0);
|
|
678
663
|
} finally {
|
|
679
|
-
e && t !==
|
|
664
|
+
e && t !== a ? D.release(t) : e || D.release(this._trackLinks), this._trackEpoch = -1, this._trackLinks = a, this._trackCount = 0, this.flags &= -257;
|
|
680
665
|
}
|
|
681
666
|
}
|
|
682
667
|
_handleAsyncComputation(t) {
|
|
@@ -702,12 +687,12 @@ class Z extends $ {
|
|
|
702
687
|
let t = 0;
|
|
703
688
|
const e = this._links;
|
|
704
689
|
for (let s = 0, n = e.length; s < n; s++)
|
|
705
|
-
t = ((t << 5) - t | 0) + e[s].node.version &
|
|
690
|
+
t = ((t << 5) - t | 0) + e[s].node.version & y;
|
|
706
691
|
return t;
|
|
707
692
|
}
|
|
708
693
|
_handleError(t, e, s = !1) {
|
|
709
694
|
const n = C(t, p, e);
|
|
710
|
-
if (!s && !(this.flags & o.REJECTED) && (this.version =
|
|
695
|
+
if (!s && !(this.flags & o.REJECTED) && (this.version = v(this.version)), this._error = n, this.flags = this.flags & -121 | dt, this._onError)
|
|
711
696
|
try {
|
|
712
697
|
this._onError(n);
|
|
713
698
|
} catch (r) {
|
|
@@ -717,7 +702,7 @@ class Z extends $ {
|
|
|
717
702
|
this._notifySubscribers(void 0, void 0);
|
|
718
703
|
}
|
|
719
704
|
_finalizeResolution(t) {
|
|
720
|
-
(!(this.flags & o.RESOLVED) || !this._equal(this._value, t)) && (this.version =
|
|
705
|
+
(!(this.flags & o.RESOLVED) || !this._equal(this._value, t)) && (this.version = v(this.version)), this._value = t, this._error = null, this.flags = (this.flags | o.RESOLVED) & -697, this._cachedErrors = null, this._errorCacheEpoch = -1;
|
|
721
706
|
}
|
|
722
707
|
execute() {
|
|
723
708
|
this._markDirty();
|
|
@@ -728,64 +713,67 @@ class Z extends $ {
|
|
|
728
713
|
}
|
|
729
714
|
}
|
|
730
715
|
Object.freeze(Z.prototype);
|
|
731
|
-
function
|
|
716
|
+
function Tt(i, t = {}) {
|
|
732
717
|
return new Z(i, t);
|
|
733
718
|
}
|
|
734
|
-
class
|
|
719
|
+
class pt extends q {
|
|
735
720
|
constructor(t, e = {}) {
|
|
736
|
-
super(), this._cleanup = null, this._links =
|
|
721
|
+
super(), this._cleanup = null, this._links = a, this._nextLinks = null, this._parkedUnsubs = null, this._currentEpoch = -1, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._executionCount = 0, this._historyPtr = 0, this._execId = 0, this._fn = t, this._onError = e.onError ?? null, this._sync = e.sync ?? !1, this._maxExecutions = e.maxExecutionsPerSecond ?? I.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = e.maxExecutionsPerFlush ?? I.MAX_EXECUTIONS_PER_EFFECT, this._trackModifications = e.trackModifications ?? !1;
|
|
737
722
|
const s = Number.isFinite(this._maxExecutions), n = s ? Math.min(this._maxExecutions + 1, I.MAX_EXECUTIONS_PER_SECOND + 1) : 0;
|
|
738
723
|
this._historyCapacity = n, this._history = _ && s && n > 0 ? new Array(n).fill(0) : null, g.attachDebugInfo(this, "effect", this.id);
|
|
739
724
|
}
|
|
740
725
|
run() {
|
|
741
|
-
if (this.flags &
|
|
726
|
+
if (this.flags & l.DISPOSED)
|
|
742
727
|
throw new S(u.EFFECT_DISPOSED);
|
|
743
728
|
this.execute(!0);
|
|
744
729
|
}
|
|
745
730
|
dispose() {
|
|
746
|
-
this.flags &
|
|
731
|
+
this.flags & l.DISPOSED || (this.flags |= l.DISPOSED, this._execCleanup(), this._releaseLinks(this._links), this._links = a, this._executeTask = void 0);
|
|
747
732
|
}
|
|
748
733
|
addDependency(t) {
|
|
749
|
-
if (!(this.flags &
|
|
734
|
+
if (!(this.flags & l.EXECUTING) || t._lastSeenEpoch === this._currentEpoch) return;
|
|
750
735
|
t._lastSeenEpoch = this._currentEpoch;
|
|
751
|
-
const e = this._nextLinks;
|
|
752
|
-
if (
|
|
753
|
-
e.push(new
|
|
736
|
+
const e = this._nextLinks, s = this._parkedUnsubs?.get(t);
|
|
737
|
+
if (s) {
|
|
738
|
+
e.push(new R(t, t.version, s)), this._parkedUnsubs.delete(t);
|
|
754
739
|
return;
|
|
755
740
|
}
|
|
756
741
|
try {
|
|
757
|
-
const
|
|
758
|
-
if (this._trackModifications && this.flags &
|
|
759
|
-
this._executeTask || (this._executeTask = () => this.execute()),
|
|
742
|
+
const n = t.subscribe(() => {
|
|
743
|
+
if (this._trackModifications && this.flags & l.EXECUTING && (t._modifiedAtEpoch = this._currentEpoch), this._sync) return this.execute();
|
|
744
|
+
this._executeTask || (this._executeTask = () => this.execute()), O.schedule(this._executeTask);
|
|
760
745
|
});
|
|
761
|
-
e.push(new
|
|
762
|
-
} catch (
|
|
763
|
-
const
|
|
764
|
-
if (console.error(
|
|
746
|
+
e.push(new R(t, t.version, n));
|
|
747
|
+
} catch (n) {
|
|
748
|
+
const r = C(n, S, u.EFFECT_EXECUTION_FAILED);
|
|
749
|
+
if (console.error(r), this._onError)
|
|
765
750
|
try {
|
|
766
|
-
this._onError(
|
|
751
|
+
this._onError(r);
|
|
767
752
|
} catch {
|
|
768
753
|
}
|
|
769
|
-
e.push(new
|
|
754
|
+
e.push(new R(t, t.version, void 0));
|
|
770
755
|
}
|
|
771
756
|
}
|
|
772
757
|
/**
|
|
773
758
|
* Executes effect with tracking.
|
|
774
759
|
*/
|
|
775
760
|
execute(t = !1) {
|
|
776
|
-
if (this.flags & (
|
|
777
|
-
this._checkInfiniteLoops(), this.flags |=
|
|
761
|
+
if (this.flags & (l.DISPOSED | l.EXECUTING) || !t && this._links.length > 0 && !this._isDirty()) return;
|
|
762
|
+
this._checkInfiniteLoops(), this.flags |= l.EXECUTING, this._execCleanup();
|
|
778
763
|
const e = this._links;
|
|
779
|
-
if (e !==
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
764
|
+
if (e !== a) {
|
|
765
|
+
const r = /* @__PURE__ */ new Map();
|
|
766
|
+
for (let h = 0, c = e.length; h < c; h++) {
|
|
767
|
+
const E = e[h];
|
|
768
|
+
E?.unsub && r.set(E.node, E.unsub);
|
|
783
769
|
}
|
|
770
|
+
this._parkedUnsubs = r;
|
|
771
|
+
}
|
|
784
772
|
const s = D.acquire();
|
|
785
773
|
this._nextLinks = s, this._currentEpoch = J();
|
|
786
774
|
let n = !1;
|
|
787
775
|
try {
|
|
788
|
-
const r =
|
|
776
|
+
const r = f.run(this, this._fn);
|
|
789
777
|
this._links = s, n = !0, this._checkLoopWarnings(), K(r) ? this._handleAsyncResult(r) : this._cleanup = typeof r == "function" ? r : null;
|
|
790
778
|
} catch (r) {
|
|
791
779
|
n = !0, this._handleExecutionError(r), this._cleanup = null;
|
|
@@ -797,7 +785,7 @@ class dt extends q {
|
|
|
797
785
|
const e = ++this._execId;
|
|
798
786
|
t.then(
|
|
799
787
|
(s) => {
|
|
800
|
-
if (e !== this._execId || this.flags &
|
|
788
|
+
if (e !== this._execId || this.flags & l.DISPOSED) {
|
|
801
789
|
if (typeof s == "function")
|
|
802
790
|
try {
|
|
803
791
|
s();
|
|
@@ -813,31 +801,28 @@ class dt extends q {
|
|
|
813
801
|
}
|
|
814
802
|
_finalizeDependencies(t, e, s) {
|
|
815
803
|
if (this._nextLinks = null, t) {
|
|
816
|
-
if (
|
|
817
|
-
for (
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
} else if (this._releaseLinks(s), D.release(s), e !== l)
|
|
824
|
-
for (let n = 0, r = e.length; n < r; n++)
|
|
825
|
-
e[n] && (e[n].node._tempUnsub = void 0);
|
|
804
|
+
if (this._parkedUnsubs)
|
|
805
|
+
for (const n of this._parkedUnsubs.values())
|
|
806
|
+
n();
|
|
807
|
+
e !== a && D.release(e);
|
|
808
|
+
} else
|
|
809
|
+
this._releaseLinks(s), D.release(s);
|
|
810
|
+
this._parkedUnsubs = null;
|
|
826
811
|
}
|
|
827
812
|
_releaseLinks(t) {
|
|
828
|
-
if (t !==
|
|
813
|
+
if (t !== a) {
|
|
829
814
|
for (let e = 0, s = t.length; e < s; e++)
|
|
830
815
|
t[e]?.unsub?.();
|
|
831
816
|
D.release(t);
|
|
832
817
|
}
|
|
833
818
|
}
|
|
834
819
|
_isDirty() {
|
|
835
|
-
const t = this._links, e =
|
|
836
|
-
|
|
820
|
+
const t = this._links, e = f.current;
|
|
821
|
+
f.current = null;
|
|
837
822
|
try {
|
|
838
823
|
for (let s = 0, n = t.length; s < n; s++) {
|
|
839
824
|
const r = t[s], h = r.node;
|
|
840
|
-
if (
|
|
825
|
+
if (h.flags & o.IS_COMPUTED)
|
|
841
826
|
try {
|
|
842
827
|
h.value;
|
|
843
828
|
} catch {
|
|
@@ -847,7 +832,7 @@ class dt extends q {
|
|
|
847
832
|
}
|
|
848
833
|
return !1;
|
|
849
834
|
} finally {
|
|
850
|
-
|
|
835
|
+
f.current = e;
|
|
851
836
|
}
|
|
852
837
|
}
|
|
853
838
|
_execCleanup() {
|
|
@@ -861,7 +846,7 @@ class dt extends q {
|
|
|
861
846
|
}
|
|
862
847
|
}
|
|
863
848
|
_checkInfiniteLoops() {
|
|
864
|
-
const t =
|
|
849
|
+
const t = M;
|
|
865
850
|
if (this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), ut() > I.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++, this._history) {
|
|
866
851
|
const e = Date.now();
|
|
867
852
|
this._history[this._historyPtr] = e, this._historyPtr = (this._historyPtr + 1) % this._historyCapacity;
|
|
@@ -873,17 +858,17 @@ class dt extends q {
|
|
|
873
858
|
}
|
|
874
859
|
}
|
|
875
860
|
get isDisposed() {
|
|
876
|
-
return (this.flags &
|
|
861
|
+
return (this.flags & l.DISPOSED) !== 0;
|
|
877
862
|
}
|
|
878
863
|
get executionCount() {
|
|
879
864
|
return this._executionCount;
|
|
880
865
|
}
|
|
881
866
|
get isExecuting() {
|
|
882
|
-
return (this.flags &
|
|
867
|
+
return (this.flags & l.EXECUTING) !== 0;
|
|
883
868
|
}
|
|
884
869
|
_throwInfiniteLoopError(t) {
|
|
885
870
|
const e = new S(
|
|
886
|
-
`Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${
|
|
871
|
+
`Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${B}`
|
|
887
872
|
);
|
|
888
873
|
throw this.dispose(), console.error(e), e;
|
|
889
874
|
}
|
|
@@ -909,40 +894,40 @@ class dt extends q {
|
|
|
909
894
|
}
|
|
910
895
|
}
|
|
911
896
|
}
|
|
912
|
-
function
|
|
897
|
+
function Ot(i, t = {}) {
|
|
913
898
|
if (typeof i != "function")
|
|
914
899
|
throw new S(u.EFFECT_MUST_BE_FUNCTION);
|
|
915
|
-
const e = new
|
|
900
|
+
const e = new pt(i, t);
|
|
916
901
|
return e.execute(), e;
|
|
917
902
|
}
|
|
918
|
-
function
|
|
903
|
+
function yt(i) {
|
|
919
904
|
if (typeof i != "function")
|
|
920
905
|
throw new TypeError("Batch callback must be a function");
|
|
921
|
-
|
|
906
|
+
O.startBatch();
|
|
922
907
|
try {
|
|
923
908
|
return i();
|
|
924
909
|
} finally {
|
|
925
|
-
|
|
910
|
+
O.endBatch();
|
|
926
911
|
}
|
|
927
912
|
}
|
|
928
913
|
export {
|
|
929
|
-
|
|
914
|
+
k as AsyncState,
|
|
930
915
|
T as AtomError,
|
|
931
916
|
p as ComputedError,
|
|
932
917
|
et as DEBUG_CONFIG,
|
|
933
918
|
g as DEBUG_RUNTIME,
|
|
934
919
|
S as EffectError,
|
|
935
|
-
|
|
920
|
+
It as POOL_CONFIG,
|
|
936
921
|
I as SCHEDULER_CONFIG,
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
922
|
+
b as SchedulerError,
|
|
923
|
+
St as atom,
|
|
924
|
+
yt as batch,
|
|
925
|
+
Tt as computed,
|
|
926
|
+
Ot as effect,
|
|
927
|
+
ft as isAtom,
|
|
928
|
+
gt as isComputed,
|
|
929
|
+
Ct as isEffect,
|
|
930
|
+
O as scheduler,
|
|
931
|
+
Dt as untracked
|
|
947
932
|
};
|
|
948
933
|
//# sourceMappingURL=index.mjs.map
|