@but212/atom-effect 0.28.0 → 0.29.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/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 +0 -2
- package/dist/index.mjs +356 -410
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var y = {
|
|
2
2
|
IDLE: "idle",
|
|
3
3
|
PENDING: "pending",
|
|
4
4
|
RESOLVED: "resolved",
|
|
@@ -6,7 +6,7 @@ var A = {
|
|
|
6
6
|
}, I = {
|
|
7
7
|
DISPOSED: 1,
|
|
8
8
|
EXECUTING: 8
|
|
9
|
-
},
|
|
9
|
+
}, B = {
|
|
10
10
|
DISPOSED: 1,
|
|
11
11
|
IS_COMPUTED: 2,
|
|
12
12
|
DIRTY: 8,
|
|
@@ -28,49 +28,29 @@ var A = {
|
|
|
28
28
|
MAX_FLUSH_ITERATIONS: 1e3,
|
|
29
29
|
MIN_FLUSH_ITERATIONS: 10,
|
|
30
30
|
BATCH_QUEUE_SHRINK_THRESHOLD: 1e3
|
|
31
|
-
},
|
|
31
|
+
}, Z = {
|
|
32
32
|
WARN_INFINITE_LOOP: !0,
|
|
33
33
|
EFFECT_FREQUENCY_WINDOW: 1e3
|
|
34
|
-
},
|
|
35
|
-
MAX_ASYNC_RETRIES: 3,
|
|
36
|
-
MAX_PROMISE_ID: Number.MAX_SAFE_INTEGER - 1
|
|
37
|
-
}, T = {
|
|
34
|
+
}, ut = { MAX_PROMISE_ID: Number.MAX_SAFE_INTEGER - 1 }, b = {
|
|
38
35
|
UNINITIALIZED: -1,
|
|
39
36
|
MIN: 1
|
|
40
|
-
},
|
|
41
|
-
constructor(t, s, e = void 0) {
|
|
42
|
-
this.node = t, this.version = s, this.unsub = e;
|
|
43
|
-
}
|
|
44
|
-
}, dt = class {
|
|
45
|
-
constructor(t, s) {
|
|
46
|
-
this.fn = t, this.sub = s;
|
|
47
|
-
}
|
|
48
|
-
notify(t, s) {
|
|
49
|
-
const e = this.fn;
|
|
50
|
-
if (e !== void 0) {
|
|
51
|
-
e(t, s);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
const i = this.sub;
|
|
55
|
-
i !== void 0 && i.execute();
|
|
56
|
-
}
|
|
57
|
-
}, N = class extends Error {
|
|
37
|
+
}, X = 1073741823, Tt = (typeof process < "u" && process.env, !1), Y = Object.freeze([]), T = class extends Error {
|
|
58
38
|
constructor(t, s = null, e = !0) {
|
|
59
39
|
super(t), this.cause = s, this.recoverable = e, this.name = "AtomError";
|
|
60
40
|
}
|
|
61
|
-
},
|
|
41
|
+
}, m = class extends T {
|
|
62
42
|
constructor(t, s = null) {
|
|
63
43
|
super(t, s, !0), this.name = "ComputedError";
|
|
64
44
|
}
|
|
65
|
-
}, v = class extends
|
|
45
|
+
}, v = class extends T {
|
|
66
46
|
constructor(t, s = null) {
|
|
67
47
|
super(t, s, !1), this.name = "EffectError";
|
|
68
48
|
}
|
|
69
|
-
},
|
|
49
|
+
}, U = class extends T {
|
|
70
50
|
constructor(t, s = null) {
|
|
71
51
|
super(t, s, !1), this.name = "SchedulerError";
|
|
72
52
|
}
|
|
73
|
-
},
|
|
53
|
+
}, c = {
|
|
74
54
|
COMPUTED_MUST_BE_FUNCTION: "Computed target must be a function",
|
|
75
55
|
COMPUTED_ASYNC_PENDING_NO_DEFAULT: "Async computation pending with no default value",
|
|
76
56
|
COMPUTED_COMPUTATION_FAILED: "Computation execution failed",
|
|
@@ -89,7 +69,27 @@ var A = {
|
|
|
89
69
|
SCHEDULER_CALLBACK_MUST_BE_FUNCTION: "Scheduler callback must be a function",
|
|
90
70
|
SCHEDULER_END_BATCH_WITHOUT_START: "endBatch() called without matching startBatch(). Ignoring.",
|
|
91
71
|
BATCH_CALLBACK_MUST_BE_FUNCTION: "Batch callback must be a function"
|
|
92
|
-
}
|
|
72
|
+
};
|
|
73
|
+
function g(t, s, e) {
|
|
74
|
+
return t instanceof T ? t : t instanceof Error ? new s(`${t.name || t.constructor.name || "Error"} (${e}): ${t.message}`, t) : new s(`Unexpected error (${e}): ${String(t)}`);
|
|
75
|
+
}
|
|
76
|
+
var q = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), lt = /* @__PURE__ */ Symbol("AtomEffect.Id"), j = /* @__PURE__ */ Symbol("AtomEffect.Type"), L = /* @__PURE__ */ Symbol("AtomEffect.NoDefaultValue"), ht = class {
|
|
77
|
+
constructor() {
|
|
78
|
+
this.enabled = !1, this.warnInfiniteLoop = Z.WARN_INFINITE_LOOP;
|
|
79
|
+
}
|
|
80
|
+
warn(t, s) {
|
|
81
|
+
}
|
|
82
|
+
attachDebugInfo(t, s, e) {
|
|
83
|
+
}
|
|
84
|
+
getDebugName(t) {
|
|
85
|
+
if (t != null)
|
|
86
|
+
return t[q];
|
|
87
|
+
}
|
|
88
|
+
getDebugType(t) {
|
|
89
|
+
if (t != null)
|
|
90
|
+
return t[j];
|
|
91
|
+
}
|
|
92
|
+
}, G = new ht(), ct = 1, _t = () => ct++ | 0, J = class {
|
|
93
93
|
constructor() {
|
|
94
94
|
this._s0 = null, this._s1 = null, this._s2 = null, this._s3 = null, this._count = 0, this._overflow = null, this._freeIndices = null;
|
|
95
95
|
}
|
|
@@ -240,8 +240,8 @@ var A = {
|
|
|
240
240
|
return;
|
|
241
241
|
const u = this._overflow;
|
|
242
242
|
if (u != null) for (let l = 0, h = u.length; l < h; l++) {
|
|
243
|
-
const
|
|
244
|
-
if (
|
|
243
|
+
const f = u[l];
|
|
244
|
+
if (f != null && (t(f), ++e === s))
|
|
245
245
|
return;
|
|
246
246
|
}
|
|
247
247
|
}
|
|
@@ -263,8 +263,8 @@ var A = {
|
|
|
263
263
|
return e;
|
|
264
264
|
const u = this._overflow;
|
|
265
265
|
if (u != null) for (let l = 0, h = u.length; l < h; l++) {
|
|
266
|
-
const
|
|
267
|
-
if (
|
|
266
|
+
const f = u[l];
|
|
267
|
+
if (f != null && (t(f), ++e === s))
|
|
268
268
|
return e;
|
|
269
269
|
}
|
|
270
270
|
return e;
|
|
@@ -288,44 +288,201 @@ var A = {
|
|
|
288
288
|
dispose() {
|
|
289
289
|
this.clear();
|
|
290
290
|
}
|
|
291
|
-
},
|
|
292
|
-
constructor() {
|
|
293
|
-
this.
|
|
291
|
+
}, tt = class extends J {
|
|
292
|
+
constructor(...t) {
|
|
293
|
+
super(...t), this._map = null, this._SCAN_THRESHOLD = 32, this.hasComputeds = !1;
|
|
294
294
|
}
|
|
295
|
-
|
|
295
|
+
prepareTracking() {
|
|
296
|
+
this.hasComputeds = !1;
|
|
296
297
|
}
|
|
297
|
-
|
|
298
|
+
_onItemRemoved(t) {
|
|
299
|
+
const s = t.unsub;
|
|
300
|
+
s && s();
|
|
298
301
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
+
claimExisting(t, s) {
|
|
303
|
+
const e = this._count;
|
|
304
|
+
if (s >= e) return !1;
|
|
305
|
+
const i = e - s;
|
|
306
|
+
if (this._map !== null || i > this._SCAN_THRESHOLD) return this._claimViaMap(t, s);
|
|
307
|
+
if (s < 4) switch (s) {
|
|
308
|
+
case 0: {
|
|
309
|
+
const n = this._s0;
|
|
310
|
+
if (n && n.node === t && n.unsub)
|
|
311
|
+
return n.version = t.version, !0;
|
|
312
|
+
}
|
|
313
|
+
case 1:
|
|
314
|
+
if (e > 1) {
|
|
315
|
+
const n = this._s1;
|
|
316
|
+
if (n && n.node === t && n.unsub)
|
|
317
|
+
return n.version = t.version, s !== 1 && (this._s1 = this._s0, this._s0 = n), !0;
|
|
318
|
+
}
|
|
319
|
+
case 2:
|
|
320
|
+
if (e > 2) {
|
|
321
|
+
const n = this._s2;
|
|
322
|
+
if (n && n.node === t && n.unsub) {
|
|
323
|
+
if (n.version = t.version, s !== 2) {
|
|
324
|
+
const o = s === 0 ? this._s0 : this._s1;
|
|
325
|
+
s === 0 ? this._s0 = n : this._s1 = n, this._s2 = o;
|
|
326
|
+
}
|
|
327
|
+
return !0;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
case 3:
|
|
331
|
+
if (e > 3) {
|
|
332
|
+
const n = this._s3;
|
|
333
|
+
if (n && n.node === t && n.unsub) {
|
|
334
|
+
if (n.version = t.version, s !== 3) {
|
|
335
|
+
let o;
|
|
336
|
+
s === 0 ? (o = this._s0, this._s0 = n) : s === 1 ? (o = this._s1, this._s1 = n) : (o = this._s2, this._s2 = n), this._s3 = o;
|
|
337
|
+
}
|
|
338
|
+
return !0;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
const r = this._overflow;
|
|
343
|
+
if (r) {
|
|
344
|
+
const n = t.version, o = s > 4 ? s : 4, u = r.length;
|
|
345
|
+
for (let l = o - 4; l < u; l++) {
|
|
346
|
+
const h = r[l];
|
|
347
|
+
if (h && h.node === t && h.unsub)
|
|
348
|
+
return h.version = n, this._swapGeneral(l + 4, s, h), !0;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return !1;
|
|
302
352
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
353
|
+
_claimViaMap(t, s) {
|
|
354
|
+
let e = this._map;
|
|
355
|
+
if (e === null) {
|
|
356
|
+
e = this._map = /* @__PURE__ */ new Map();
|
|
357
|
+
const n = this._count;
|
|
358
|
+
if (s < 4) {
|
|
359
|
+
const u = this._s0;
|
|
360
|
+
s <= 0 && u?.unsub && e.set(u.node, 0);
|
|
361
|
+
const l = this._s1;
|
|
362
|
+
s <= 1 && l?.unsub && e.set(l.node, 1);
|
|
363
|
+
const h = this._s2;
|
|
364
|
+
s <= 2 && h?.unsub && e.set(h.node, 2);
|
|
365
|
+
const f = this._s3;
|
|
366
|
+
s <= 3 && f?.unsub && e.set(f.node, 3);
|
|
367
|
+
}
|
|
368
|
+
const o = this._overflow;
|
|
369
|
+
if (o && n > 4) {
|
|
370
|
+
const u = s > 4 ? s : 4, l = o.length;
|
|
371
|
+
for (let h = u - 4; h < l; h++) {
|
|
372
|
+
const f = o[h];
|
|
373
|
+
f?.unsub && e.set(f.node, h + 4);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
const i = e.get(t);
|
|
378
|
+
if (i === void 0 || i < s) return !1;
|
|
379
|
+
const r = this.getAt(i);
|
|
380
|
+
if (r == null || !r.unsub) return !1;
|
|
381
|
+
if (r.version = t.version, i !== s) {
|
|
382
|
+
let n;
|
|
383
|
+
s === 0 ? n = this._s0 : s === 1 ? n = this._s1 : s === 2 ? n = this._s2 : s === 3 ? n = this._s3 : n = this._overflow[s - 4] ?? null, this.setAt(s, r), this.setAt(i, n), n?.unsub && e.set(n.node, i), e.set(t, s);
|
|
384
|
+
}
|
|
385
|
+
return !0;
|
|
386
|
+
}
|
|
387
|
+
_swapGeneral(t, s, e) {
|
|
388
|
+
if (t === s) return;
|
|
389
|
+
let i;
|
|
390
|
+
if (s === 0 ? i = this._s0 : s === 1 ? i = this._s1 : s === 2 ? i = this._s2 : s === 3 ? i = this._s3 : i = this._overflow[s - 4] ?? null, this.setAt(s, e), t === 0) this._s0 = i;
|
|
391
|
+
else if (t === 1) this._s1 = i;
|
|
392
|
+
else if (t === 2) this._s2 = i;
|
|
393
|
+
else if (t === 3) this._s3 = i;
|
|
394
|
+
else {
|
|
395
|
+
const r = this._overflow;
|
|
396
|
+
r[t - 4] = i;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
insertNew(t, s) {
|
|
400
|
+
const e = this._count;
|
|
401
|
+
if (t < e) {
|
|
402
|
+
let i;
|
|
403
|
+
t === 0 ? i = this._s0 : t === 1 ? i = this._s1 : t === 2 ? i = this._s2 : t === 3 ? i = this._s3 : i = this._overflow[t - 4] ?? null, i != null && (this._addToOverflow(i), this._map !== null && i.unsub && this._map.set(i.node, this._count - 1));
|
|
404
|
+
}
|
|
405
|
+
if (t === 0) this._s0 = s;
|
|
406
|
+
else if (t === 1) this._s1 = s;
|
|
407
|
+
else if (t === 2) this._s2 = s;
|
|
408
|
+
else if (t === 3) this._s3 = s;
|
|
409
|
+
else {
|
|
410
|
+
let i = this._overflow;
|
|
411
|
+
i || (i = [], this._overflow = i), i[t - 4] = s;
|
|
412
|
+
}
|
|
413
|
+
t >= e && (this._count = t + 1);
|
|
414
|
+
}
|
|
415
|
+
truncateFrom(t) {
|
|
416
|
+
t >= this._count || (super.truncateFrom(t), this._map !== null && (this._map.clear(), this._map = null));
|
|
417
|
+
}
|
|
418
|
+
disposeAll() {
|
|
419
|
+
this._count > 0 && this.truncateFrom(0), this.hasComputeds = !1;
|
|
420
|
+
}
|
|
421
|
+
remove(t) {
|
|
422
|
+
throw new Error("remove() is strictly prohibited in DepSlotBuffer to preserve sequential cache paths.");
|
|
423
|
+
}
|
|
424
|
+
compact() {
|
|
425
|
+
}
|
|
426
|
+
}, z = class {
|
|
427
|
+
constructor(t, s, e = void 0) {
|
|
428
|
+
this.node = t, this.version = s, this.unsub = e;
|
|
429
|
+
}
|
|
430
|
+
}, ft = class {
|
|
431
|
+
constructor(t, s) {
|
|
432
|
+
this.fn = t, this.sub = s;
|
|
433
|
+
}
|
|
434
|
+
notify(t, s) {
|
|
435
|
+
const e = this.fn;
|
|
436
|
+
if (e !== void 0) {
|
|
437
|
+
e(t, s);
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
const i = this.sub;
|
|
441
|
+
i !== void 0 && i.execute();
|
|
442
|
+
}
|
|
443
|
+
}, at = class {
|
|
444
|
+
constructor() {
|
|
445
|
+
this.current = null;
|
|
446
|
+
}
|
|
447
|
+
run(t, s) {
|
|
448
|
+
if (this.current === t) return s();
|
|
449
|
+
const e = this.current;
|
|
450
|
+
this.current = t;
|
|
451
|
+
try {
|
|
452
|
+
return s();
|
|
453
|
+
} finally {
|
|
454
|
+
this.current = e;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}, _ = new at();
|
|
458
|
+
function mt(t) {
|
|
459
|
+
const s = _, e = s.current;
|
|
460
|
+
if (e === null) return t();
|
|
461
|
+
s.current = null;
|
|
462
|
+
try {
|
|
463
|
+
return t();
|
|
464
|
+
} finally {
|
|
465
|
+
s.current = e;
|
|
306
466
|
}
|
|
307
|
-
}, Q = new Ct(), It = 1, Dt = () => It++ | 0;
|
|
308
|
-
function m(t, s, e) {
|
|
309
|
-
return t instanceof N ? t : t instanceof Error ? new s(`${t.name || t.constructor.name || "Error"} (${e}): ${t.message}`, t) : new s(`Unexpected error (${e}): ${String(t)}`);
|
|
310
467
|
}
|
|
311
|
-
var
|
|
468
|
+
var Q = class {
|
|
312
469
|
constructor() {
|
|
313
|
-
this.flags = 0, this.version = 0, this._lastSeenEpoch =
|
|
470
|
+
this.flags = 0, this.version = 0, this._lastSeenEpoch = b.UNINITIALIZED, this._notifying = 0, this._hotIndex = -1, this._slots = null, this._deps = null, this.id = _t() & X;
|
|
314
471
|
}
|
|
315
472
|
get isDisposed() {
|
|
316
|
-
return (this.flags &
|
|
473
|
+
return (this.flags & B.DISPOSED) !== 0;
|
|
317
474
|
}
|
|
318
475
|
get isComputed() {
|
|
319
|
-
return (this.flags &
|
|
476
|
+
return (this.flags & B.IS_COMPUTED) !== 0;
|
|
320
477
|
}
|
|
321
478
|
get hasError() {
|
|
322
479
|
return !1;
|
|
323
480
|
}
|
|
324
481
|
subscribe(t) {
|
|
325
482
|
const s = typeof t == "function";
|
|
326
|
-
if (!s && (!t || typeof t.execute != "function")) throw
|
|
483
|
+
if (!s && (!t || typeof t.execute != "function")) throw g(/* @__PURE__ */ new TypeError("Invalid subscriber"), T, c.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
|
|
327
484
|
let e = this._slots;
|
|
328
|
-
e || (e = new
|
|
485
|
+
e || (e = new J(), this._slots = e);
|
|
329
486
|
let i = !1;
|
|
330
487
|
if (e._s0 != null && (s ? e._s0.fn === t : e._s0.sub === t)) i = !0;
|
|
331
488
|
else if (e._s1 != null && (s ? e._s1.fn === t : e._s1.sub === t)) i = !0;
|
|
@@ -344,7 +501,7 @@ var Y = class {
|
|
|
344
501
|
if (i)
|
|
345
502
|
return () => {
|
|
346
503
|
};
|
|
347
|
-
const r = new
|
|
504
|
+
const r = new ft(s ? t : void 0, s ? void 0 : t);
|
|
348
505
|
return e.add(r), () => this._unsubscribe(r);
|
|
349
506
|
}
|
|
350
507
|
_unsubscribe(t) {
|
|
@@ -396,7 +553,7 @@ var Y = class {
|
|
|
396
553
|
}
|
|
397
554
|
}
|
|
398
555
|
_logNotifyError(t) {
|
|
399
|
-
console.error(
|
|
556
|
+
console.error(g(t, T, c.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED));
|
|
400
557
|
}
|
|
401
558
|
_isDirty() {
|
|
402
559
|
const t = this._deps;
|
|
@@ -406,34 +563,34 @@ var Y = class {
|
|
|
406
563
|
const e = t.getAt(s);
|
|
407
564
|
if (e != null && e.node.version !== e.version) return !0;
|
|
408
565
|
}
|
|
409
|
-
return
|
|
566
|
+
return this._deepDirtyCheck();
|
|
410
567
|
}
|
|
411
|
-
},
|
|
568
|
+
}, $ = /* @__PURE__ */ Symbol.for("atom-effect/atom"), st = /* @__PURE__ */ Symbol.for("atom-effect/computed"), et = /* @__PURE__ */ Symbol.for("atom-effect/effect"), Et = /* @__PURE__ */ Symbol.for("atom-effect/writable"), P = 0;
|
|
412
569
|
function k() {
|
|
413
|
-
const t =
|
|
414
|
-
return
|
|
570
|
+
const t = P + 1 & X;
|
|
571
|
+
return P = t === 0 ? 1 : t, P;
|
|
415
572
|
}
|
|
416
|
-
function
|
|
417
|
-
const s = t + 1 &
|
|
573
|
+
function H(t) {
|
|
574
|
+
const s = t + 1 & X;
|
|
418
575
|
return s === 0 ? 1 : s;
|
|
419
576
|
}
|
|
420
|
-
var V = 0,
|
|
421
|
-
function
|
|
422
|
-
return
|
|
577
|
+
var V = 0, R = !1, it = 0;
|
|
578
|
+
function dt() {
|
|
579
|
+
return it;
|
|
423
580
|
}
|
|
424
|
-
function
|
|
425
|
-
return
|
|
581
|
+
function W() {
|
|
582
|
+
return R ? !1 : (R = !0, it = k(), V = 0, !0);
|
|
426
583
|
}
|
|
427
|
-
function
|
|
428
|
-
|
|
584
|
+
function K() {
|
|
585
|
+
R = !1;
|
|
429
586
|
}
|
|
430
|
-
function
|
|
431
|
-
if (!
|
|
587
|
+
function pt() {
|
|
588
|
+
if (!R) return 0;
|
|
432
589
|
const t = ++V;
|
|
433
590
|
if (t <= C.MAX_EXECUTIONS_PER_FLUSH) return t;
|
|
434
591
|
throw new Error(`[atom-effect] Infinite loop detected: flush execution count exceeded ${C.MAX_EXECUTIONS_PER_FLUSH}`);
|
|
435
592
|
}
|
|
436
|
-
var
|
|
593
|
+
var Ct = class {
|
|
437
594
|
constructor() {
|
|
438
595
|
this._queueBuffer = [[], []], this._bufferIndex = 0, this._size = 0, this._epoch = 0, this._isProcessing = !1, this._isFlushingSync = !1, this._batchDepth = 0, this._batchQueue = [], this._batchQueueSize = 0, this._maxFlushIterations = C.MAX_FLUSH_ITERATIONS, this.onOverflow = null, this._boundRunLoop = this._runLoop.bind(this);
|
|
439
596
|
}
|
|
@@ -459,19 +616,19 @@ var St = class {
|
|
|
459
616
|
_runLoop() {
|
|
460
617
|
try {
|
|
461
618
|
if (this._size === 0) return;
|
|
462
|
-
const t =
|
|
463
|
-
this._drainQueue(), t &&
|
|
619
|
+
const t = W();
|
|
620
|
+
this._drainQueue(), t && K();
|
|
464
621
|
} finally {
|
|
465
622
|
this._isProcessing = !1, this._size > 0 && this._batchDepth === 0 && this._flush();
|
|
466
623
|
}
|
|
467
624
|
}
|
|
468
625
|
_flushSync() {
|
|
469
626
|
this._isFlushingSync = !0;
|
|
470
|
-
const t =
|
|
627
|
+
const t = W();
|
|
471
628
|
try {
|
|
472
629
|
this._mergeBatchQueue(), this._drainQueue();
|
|
473
630
|
} finally {
|
|
474
|
-
this._isFlushingSync = !1, t &&
|
|
631
|
+
this._isFlushingSync = !1, t && K();
|
|
475
632
|
}
|
|
476
633
|
}
|
|
477
634
|
_mergeBatchQueue() {
|
|
@@ -503,14 +660,14 @@ var St = class {
|
|
|
503
660
|
try {
|
|
504
661
|
typeof r == "function" ? r() : r.execute();
|
|
505
662
|
} catch (n) {
|
|
506
|
-
console.error(new
|
|
663
|
+
console.error(new U("Error occurred during scheduler execution", n));
|
|
507
664
|
}
|
|
508
665
|
}
|
|
509
666
|
s.length = 0;
|
|
510
667
|
}
|
|
511
668
|
_handleFlushOverflow() {
|
|
512
669
|
const t = this._size + this._batchQueueSize, s = this._maxFlushIterations;
|
|
513
|
-
console.error(new
|
|
670
|
+
console.error(new U(c.SCHEDULER_FLUSH_OVERFLOW(s, t))), this._size = 0;
|
|
514
671
|
const e = this._bufferIndex;
|
|
515
672
|
this._queueBuffer[e].length = 0, this._batchQueueSize = 0;
|
|
516
673
|
const i = this.onOverflow;
|
|
@@ -526,37 +683,23 @@ var St = class {
|
|
|
526
683
|
this._batchDepth !== 0 && --this._batchDepth === 0 && this._flushSync();
|
|
527
684
|
}
|
|
528
685
|
setMaxFlushIterations(t) {
|
|
529
|
-
if (t < C.MIN_FLUSH_ITERATIONS) throw new
|
|
686
|
+
if (t < C.MIN_FLUSH_ITERATIONS) throw new U(`Max flush iterations must be at least ${C.MIN_FLUSH_ITERATIONS}`);
|
|
530
687
|
this._maxFlushIterations = t;
|
|
531
688
|
}
|
|
532
|
-
}, w = new
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
if (this.current === t) return s();
|
|
538
|
-
const e = this.current;
|
|
539
|
-
this.current = t;
|
|
540
|
-
try {
|
|
541
|
-
return s();
|
|
542
|
-
} finally {
|
|
543
|
-
this.current = e;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
}, f = new Tt();
|
|
547
|
-
function Rt(t) {
|
|
548
|
-
const s = f, e = s.current;
|
|
549
|
-
if (e === null) return t();
|
|
550
|
-
s.current = null;
|
|
689
|
+
}, w = new Ct();
|
|
690
|
+
function Nt(t) {
|
|
691
|
+
if (typeof t != "function") throw new TypeError(c.BATCH_CALLBACK_MUST_BE_FUNCTION);
|
|
692
|
+
const s = w;
|
|
693
|
+
s.startBatch();
|
|
551
694
|
try {
|
|
552
695
|
return t();
|
|
553
696
|
} finally {
|
|
554
|
-
s.
|
|
697
|
+
s.endBatch();
|
|
555
698
|
}
|
|
556
699
|
}
|
|
557
|
-
var
|
|
700
|
+
var It = class extends Q {
|
|
558
701
|
constructor(t, s) {
|
|
559
|
-
super(), this[$] = !0, this[
|
|
702
|
+
super(), this[$] = !0, this[Et] = !0, this._value = t, s && (this.flags |= a.SYNC), G.attachDebugInfo(this, "atom", this.id);
|
|
560
703
|
}
|
|
561
704
|
get isNotificationScheduled() {
|
|
562
705
|
return (this.flags & a.NOTIFICATION_SCHEDULED) !== 0;
|
|
@@ -565,13 +708,13 @@ var mt = class extends Y {
|
|
|
565
708
|
return (this.flags & a.SYNC) !== 0;
|
|
566
709
|
}
|
|
567
710
|
get value() {
|
|
568
|
-
const t =
|
|
711
|
+
const t = _.current;
|
|
569
712
|
return t?.addDependency(this), this._value;
|
|
570
713
|
}
|
|
571
714
|
set value(t) {
|
|
572
715
|
const s = this._value;
|
|
573
716
|
if (Object.is(s, t)) return;
|
|
574
|
-
this._value = t, this.version =
|
|
717
|
+
this._value = t, this.version = H(this.version);
|
|
575
718
|
const e = this.flags;
|
|
576
719
|
if ((e & a.NOTIFICATION_SCHEDULED) !== 0) return;
|
|
577
720
|
const i = this._slots;
|
|
@@ -600,201 +743,25 @@ var mt = class extends Y {
|
|
|
600
743
|
this.dispose();
|
|
601
744
|
}
|
|
602
745
|
};
|
|
603
|
-
function
|
|
604
|
-
return new
|
|
746
|
+
function bt(t, s = {}) {
|
|
747
|
+
return new It(t, s.sync ?? !1);
|
|
605
748
|
}
|
|
606
|
-
|
|
607
|
-
constructor(...t) {
|
|
608
|
-
super(...t), this._map = null, this._SCAN_THRESHOLD = 32, this.hasComputeds = !1, this._depsHash = 0;
|
|
609
|
-
}
|
|
610
|
-
prepareTracking() {
|
|
611
|
-
this.hasComputeds = !1;
|
|
612
|
-
}
|
|
613
|
-
_onItemRemoved(t) {
|
|
614
|
-
const s = t.unsub;
|
|
615
|
-
s && s();
|
|
616
|
-
}
|
|
617
|
-
claimExisting(t, s) {
|
|
618
|
-
const e = this._count;
|
|
619
|
-
if (s >= e) return !1;
|
|
620
|
-
const i = e - s;
|
|
621
|
-
if (this._map !== null || i > this._SCAN_THRESHOLD) return this._claimViaMap(t, s);
|
|
622
|
-
if (s < 4) switch (s) {
|
|
623
|
-
case 0: {
|
|
624
|
-
const n = this._s0;
|
|
625
|
-
if (n && n.node === t && n.unsub)
|
|
626
|
-
return n.version = t.version, !0;
|
|
627
|
-
}
|
|
628
|
-
case 1:
|
|
629
|
-
if (e > 1) {
|
|
630
|
-
const n = this._s1;
|
|
631
|
-
if (n && n.node === t && n.unsub)
|
|
632
|
-
return n.version = t.version, s !== 1 && (this._s1 = this._s0, this._s0 = n), !0;
|
|
633
|
-
}
|
|
634
|
-
case 2:
|
|
635
|
-
if (e > 2) {
|
|
636
|
-
const n = this._s2;
|
|
637
|
-
if (n && n.node === t && n.unsub) {
|
|
638
|
-
if (n.version = t.version, s !== 2) {
|
|
639
|
-
const o = s === 0 ? this._s0 : this._s1;
|
|
640
|
-
s === 0 ? this._s0 = n : this._s1 = n, this._s2 = o;
|
|
641
|
-
}
|
|
642
|
-
return !0;
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
case 3:
|
|
646
|
-
if (e > 3) {
|
|
647
|
-
const n = this._s3;
|
|
648
|
-
if (n && n.node === t && n.unsub) {
|
|
649
|
-
if (n.version = t.version, s !== 3) {
|
|
650
|
-
let o;
|
|
651
|
-
s === 0 ? (o = this._s0, this._s0 = n) : s === 1 ? (o = this._s1, this._s1 = n) : (o = this._s2, this._s2 = n), this._s3 = o;
|
|
652
|
-
}
|
|
653
|
-
return !0;
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
const r = this._overflow;
|
|
658
|
-
if (r) {
|
|
659
|
-
const n = t.version, o = s > 4 ? s : 4, u = r.length;
|
|
660
|
-
for (let l = o - 4; l < u; l++) {
|
|
661
|
-
const h = r[l];
|
|
662
|
-
if (h && h.node === t && h.unsub)
|
|
663
|
-
return h.version = n, this._swapGeneral(l + 4, s, h), !0;
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
return !1;
|
|
667
|
-
}
|
|
668
|
-
_claimViaMap(t, s) {
|
|
669
|
-
let e = this._map;
|
|
670
|
-
if (e === null) {
|
|
671
|
-
e = this._map = /* @__PURE__ */ new Map();
|
|
672
|
-
const n = this._count;
|
|
673
|
-
if (s < 4) {
|
|
674
|
-
const u = this._s0;
|
|
675
|
-
s <= 0 && u?.unsub && e.set(u.node, 0);
|
|
676
|
-
const l = this._s1;
|
|
677
|
-
s <= 1 && l?.unsub && e.set(l.node, 1);
|
|
678
|
-
const h = this._s2;
|
|
679
|
-
s <= 2 && h?.unsub && e.set(h.node, 2);
|
|
680
|
-
const c = this._s3;
|
|
681
|
-
s <= 3 && c?.unsub && e.set(c.node, 3);
|
|
682
|
-
}
|
|
683
|
-
const o = this._overflow;
|
|
684
|
-
if (o && n > 4) {
|
|
685
|
-
const u = s > 4 ? s : 4, l = o.length;
|
|
686
|
-
for (let h = u - 4; h < l; h++) {
|
|
687
|
-
const c = o[h];
|
|
688
|
-
c?.unsub && e.set(c.node, h + 4);
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
const i = e.get(t);
|
|
693
|
-
if (i === void 0 || i < s) return !1;
|
|
694
|
-
const r = this.getAt(i);
|
|
695
|
-
if (r == null || !r.unsub) return !1;
|
|
696
|
-
if (r.version = t.version, i !== s) {
|
|
697
|
-
let n;
|
|
698
|
-
s === 0 ? n = this._s0 : s === 1 ? n = this._s1 : s === 2 ? n = this._s2 : s === 3 ? n = this._s3 : n = this._overflow[s - 4] ?? null, this.setAt(s, r), this.setAt(i, n), n?.unsub && e.set(n.node, i), e.set(t, s);
|
|
699
|
-
}
|
|
700
|
-
return !0;
|
|
701
|
-
}
|
|
702
|
-
_swapGeneral(t, s, e) {
|
|
703
|
-
if (t === s) return;
|
|
704
|
-
let i;
|
|
705
|
-
if (s === 0 ? i = this._s0 : s === 1 ? i = this._s1 : s === 2 ? i = this._s2 : s === 3 ? i = this._s3 : i = this._overflow[s - 4] ?? null, this.setAt(s, e), t === 0) this._s0 = i;
|
|
706
|
-
else if (t === 1) this._s1 = i;
|
|
707
|
-
else if (t === 2) this._s2 = i;
|
|
708
|
-
else if (t === 3) this._s3 = i;
|
|
709
|
-
else {
|
|
710
|
-
const r = this._overflow;
|
|
711
|
-
r[t - 4] = i;
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
insertNew(t, s) {
|
|
715
|
-
const e = this._count;
|
|
716
|
-
if (t < e) {
|
|
717
|
-
let i;
|
|
718
|
-
t === 0 ? i = this._s0 : t === 1 ? i = this._s1 : t === 2 ? i = this._s2 : t === 3 ? i = this._s3 : i = this._overflow[t - 4] ?? null, i != null && (this._addToOverflow(i), this._map !== null && i.unsub && this._map.set(i.node, this._count - 1));
|
|
719
|
-
}
|
|
720
|
-
if (t === 0) this._s0 = s;
|
|
721
|
-
else if (t === 1) this._s1 = s;
|
|
722
|
-
else if (t === 2) this._s2 = s;
|
|
723
|
-
else if (t === 3) this._s3 = s;
|
|
724
|
-
else {
|
|
725
|
-
let i = this._overflow;
|
|
726
|
-
i || (i = [], this._overflow = i), i[t - 4] = s;
|
|
727
|
-
}
|
|
728
|
-
t >= e && (this._count = t + 1);
|
|
729
|
-
}
|
|
730
|
-
truncateFrom(t) {
|
|
731
|
-
t >= this._count || (super.truncateFrom(t), this._map !== null && (this._map.clear(), this._map = null));
|
|
732
|
-
}
|
|
733
|
-
seal() {
|
|
734
|
-
this._depsHash = this._calculateHash(!1);
|
|
735
|
-
}
|
|
736
|
-
isDirtyFast() {
|
|
737
|
-
return this._calculateHash(!0) !== this._depsHash;
|
|
738
|
-
}
|
|
739
|
-
_calculateHash(t) {
|
|
740
|
-
const s = this._count;
|
|
741
|
-
if (s === 0) return 0;
|
|
742
|
-
const e = Et.VERSION_BITS;
|
|
743
|
-
let i = 0;
|
|
744
|
-
const r = this._s0;
|
|
745
|
-
if (r != null) {
|
|
746
|
-
const n = r.node, o = t ? n.version : r.version;
|
|
747
|
-
i = i + (o << e) + n.id | 0;
|
|
748
|
-
const u = this._s1;
|
|
749
|
-
if (s > 1 && u != null) {
|
|
750
|
-
const l = u.node, h = t ? l.version : u.version;
|
|
751
|
-
i = i + (h << e) + l.id | 0;
|
|
752
|
-
const c = this._s2;
|
|
753
|
-
if (s > 2 && c != null) {
|
|
754
|
-
const q = c.node, ft = t ? q.version : c.version;
|
|
755
|
-
i = i + (ft << e) + q.id | 0;
|
|
756
|
-
const L = this._s3;
|
|
757
|
-
if (s > 3 && L != null) {
|
|
758
|
-
const j = L.node, at = t ? j.version : L.version;
|
|
759
|
-
i = i + (at << e) + j.id | 0;
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
if (s > 4) {
|
|
765
|
-
const n = this._overflow;
|
|
766
|
-
for (let o = 0, u = n.length; o < u; o++) {
|
|
767
|
-
const l = n[o], h = l.node, c = t ? h.version : l.version;
|
|
768
|
-
i = i + (c << e) + h.id | 0;
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
return i;
|
|
772
|
-
}
|
|
773
|
-
disposeAll() {
|
|
774
|
-
this._count > 0 && this.truncateFrom(0), this.hasComputeds = !1;
|
|
775
|
-
}
|
|
776
|
-
remove(t) {
|
|
777
|
-
throw new Error("remove() is strictly prohibited in DepSlotBuffer to preserve sequential cache paths.");
|
|
778
|
-
}
|
|
779
|
-
compact() {
|
|
780
|
-
}
|
|
781
|
-
};
|
|
782
|
-
function wt(t) {
|
|
749
|
+
function yt(t) {
|
|
783
750
|
return typeof t == "object" && t !== null && $ in t;
|
|
784
751
|
}
|
|
785
|
-
function
|
|
786
|
-
return typeof t == "object" && t !== null &&
|
|
752
|
+
function At(t) {
|
|
753
|
+
return typeof t == "object" && t !== null && st in t;
|
|
787
754
|
}
|
|
788
|
-
function
|
|
789
|
-
return typeof t == "object" && t !== null &&
|
|
755
|
+
function Ot(t) {
|
|
756
|
+
return typeof t == "object" && t !== null && et in t;
|
|
790
757
|
}
|
|
791
|
-
function
|
|
758
|
+
function nt(t) {
|
|
792
759
|
return typeof t == "object" && t !== null && typeof t.then == "function";
|
|
793
760
|
}
|
|
794
|
-
var { IDLE: p, DIRTY: E, PENDING:
|
|
761
|
+
var { IDLE: p, DIRTY: E, PENDING: S, RESOLVED: d, REJECTED: D, HAS_ERROR: A, RECOMPUTING: N, DISPOSED: M, IS_COMPUTED: O, FORCE_COMPUTE: x } = B, Dt = class extends Q {
|
|
795
762
|
constructor(t, s = {}) {
|
|
796
|
-
if (typeof t != "function") throw new
|
|
797
|
-
if (super(), this[$] = !0, this[
|
|
763
|
+
if (typeof t != "function") throw new m(c.COMPUTED_MUST_BE_FUNCTION);
|
|
764
|
+
if (super(), this[$] = !0, this[st] = !0, this._error = null, this._promiseId = 0, this._deps = new tt(), this._trackEpoch = b.UNINITIALIZED, this._trackCount = 0, this._value = void 0, this.flags = O | E | p, this._equal = s.equal ?? Object.is, this._fn = t, this._defaultValue = "defaultValue" in s ? s.defaultValue : L, this._onError = s.onError ?? null, G.attachDebugInfo(this, "computed", this.id), s.lazy === !1) try {
|
|
798
765
|
this._recompute();
|
|
799
766
|
} catch {
|
|
800
767
|
}
|
|
@@ -806,33 +773,33 @@ var { IDLE: p, DIRTY: E, PENDING: g, RESOLVED: d, REJECTED: D, HAS_ERROR: b, REC
|
|
|
806
773
|
return (this.flags & D) !== 0;
|
|
807
774
|
}
|
|
808
775
|
get isRecomputing() {
|
|
809
|
-
return (this.flags &
|
|
776
|
+
return (this.flags & N) !== 0;
|
|
810
777
|
}
|
|
811
778
|
get _hasErrorInternal() {
|
|
812
|
-
return (this.flags &
|
|
779
|
+
return (this.flags & A) !== 0;
|
|
813
780
|
}
|
|
814
781
|
_track() {
|
|
815
|
-
|
|
782
|
+
_.current?.addDependency(this);
|
|
816
783
|
}
|
|
817
784
|
get value() {
|
|
818
|
-
const t =
|
|
785
|
+
const t = _.current;
|
|
819
786
|
t?.addDependency(this);
|
|
820
787
|
let s = this.flags;
|
|
821
788
|
if ((s & (d | E | p)) === d) return this._value;
|
|
822
|
-
if ((s &
|
|
823
|
-
if ((s &
|
|
789
|
+
if ((s & M) !== 0) throw new m(c.COMPUTED_DISPOSED);
|
|
790
|
+
if ((s & N) !== 0) {
|
|
824
791
|
const r = this._defaultValue;
|
|
825
|
-
if (r !==
|
|
826
|
-
throw new
|
|
792
|
+
if (r !== L) return r;
|
|
793
|
+
throw new m(c.COMPUTED_CIRCULAR_DEPENDENCY);
|
|
827
794
|
}
|
|
828
795
|
if ((s & (E | p)) !== 0) {
|
|
829
796
|
const r = this._deps;
|
|
830
|
-
if ((s & p) === 0 && (s &
|
|
797
|
+
if ((s & p) === 0 && (s & x) === 0 && r.size > 0 && !this._isDirty() ? s = this.flags &= ~E : (this._recompute(), s = this.flags), (s & d) !== 0) return this._value;
|
|
831
798
|
}
|
|
832
|
-
const e = this._defaultValue, i = e !==
|
|
833
|
-
if ((s &
|
|
799
|
+
const e = this._defaultValue, i = e !== L;
|
|
800
|
+
if ((s & S) !== 0) {
|
|
834
801
|
if (i) return e;
|
|
835
|
-
throw new
|
|
802
|
+
throw new m(c.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
|
|
836
803
|
}
|
|
837
804
|
if ((s & D) !== 0) {
|
|
838
805
|
if (i) return e;
|
|
@@ -844,14 +811,14 @@ var { IDLE: p, DIRTY: E, PENDING: g, RESOLVED: d, REJECTED: D, HAS_ERROR: b, REC
|
|
|
844
811
|
return this._value;
|
|
845
812
|
}
|
|
846
813
|
get state() {
|
|
847
|
-
const t =
|
|
814
|
+
const t = _.current;
|
|
848
815
|
t?.addDependency(this);
|
|
849
816
|
const s = this.flags;
|
|
850
|
-
return (s & d) !== 0 ?
|
|
817
|
+
return (s & d) !== 0 ? y.RESOLVED : (s & S) !== 0 ? y.PENDING : (s & D) !== 0 ? y.REJECTED : y.IDLE;
|
|
851
818
|
}
|
|
852
819
|
get hasError() {
|
|
853
|
-
const t =
|
|
854
|
-
if (t?.addDependency(this), (this.flags & (D |
|
|
820
|
+
const t = _.current;
|
|
821
|
+
if (t?.addDependency(this), (this.flags & (D | A)) !== 0) return !0;
|
|
855
822
|
const s = this._deps;
|
|
856
823
|
if (!s.hasComputeds) return !1;
|
|
857
824
|
const e = s.size;
|
|
@@ -862,11 +829,11 @@ var { IDLE: p, DIRTY: E, PENDING: g, RESOLVED: d, REJECTED: D, HAS_ERROR: b, REC
|
|
|
862
829
|
return !this.hasError;
|
|
863
830
|
}
|
|
864
831
|
get errors() {
|
|
865
|
-
const t =
|
|
832
|
+
const t = _.current;
|
|
866
833
|
t?.addDependency(this);
|
|
867
834
|
const s = this._error, e = this._deps;
|
|
868
835
|
if (!e.hasComputeds)
|
|
869
|
-
return s == null ?
|
|
836
|
+
return s == null ? Y : Object.freeze([s]);
|
|
870
837
|
const i = [];
|
|
871
838
|
s != null && i.push(s);
|
|
872
839
|
const r = e.size;
|
|
@@ -876,7 +843,7 @@ var { IDLE: p, DIRTY: E, PENDING: g, RESOLVED: d, REJECTED: D, HAS_ERROR: b, REC
|
|
|
876
843
|
const u = o.node;
|
|
877
844
|
(u.flags & O) !== 0 && u.hasError && this._collectErrorsFromDep(u, i);
|
|
878
845
|
}
|
|
879
|
-
return i.length === 0 ?
|
|
846
|
+
return i.length === 0 ? Y : Object.freeze(i);
|
|
880
847
|
}
|
|
881
848
|
_collectErrorsFromDep(t, s) {
|
|
882
849
|
const e = t.errors, i = e.length;
|
|
@@ -886,22 +853,22 @@ var { IDLE: p, DIRTY: E, PENDING: g, RESOLVED: d, REJECTED: D, HAS_ERROR: b, REC
|
|
|
886
853
|
}
|
|
887
854
|
}
|
|
888
855
|
get lastError() {
|
|
889
|
-
const t =
|
|
856
|
+
const t = _.current;
|
|
890
857
|
return t?.addDependency(this), this._error;
|
|
891
858
|
}
|
|
892
859
|
get isPending() {
|
|
893
|
-
const t =
|
|
894
|
-
return t?.addDependency(this), (this.flags &
|
|
860
|
+
const t = _.current;
|
|
861
|
+
return t?.addDependency(this), (this.flags & S) !== 0;
|
|
895
862
|
}
|
|
896
863
|
get isResolved() {
|
|
897
|
-
const t =
|
|
864
|
+
const t = _.current;
|
|
898
865
|
return t?.addDependency(this), (this.flags & d) !== 0;
|
|
899
866
|
}
|
|
900
867
|
invalidate() {
|
|
901
|
-
this.flags |=
|
|
868
|
+
this.flags |= x, this._markDirty();
|
|
902
869
|
}
|
|
903
870
|
dispose() {
|
|
904
|
-
(this.flags &
|
|
871
|
+
(this.flags & M) === 0 && (this._deps.disposeAll(), this._slots != null && this._slots.clear(), this.flags = M | E | p, this._error = null, this._value = void 0, this._hotIndex = -1);
|
|
905
872
|
}
|
|
906
873
|
[Symbol.dispose]() {
|
|
907
874
|
this.dispose();
|
|
@@ -913,69 +880,62 @@ var { IDLE: p, DIRTY: E, PENDING: g, RESOLVED: d, REJECTED: D, HAS_ERROR: b, REC
|
|
|
913
880
|
const e = this._trackCount++, i = this._deps, r = i.getAt(e);
|
|
914
881
|
if (r != null && r.node === t) r.version = t.version;
|
|
915
882
|
else if (!i.claimExisting(t, e)) {
|
|
916
|
-
const n = new
|
|
883
|
+
const n = new z(t, t.version, t.subscribe(this));
|
|
917
884
|
i.insertNew(e, n);
|
|
918
885
|
}
|
|
919
886
|
(t.flags & O) !== 0 && (i.hasComputeds = !0);
|
|
920
887
|
}
|
|
921
888
|
_recompute() {
|
|
922
889
|
if (this.isRecomputing) return;
|
|
923
|
-
this.flags = (this.flags |
|
|
890
|
+
this.flags = (this.flags | N) & ~x, this._trackEpoch = k(), this._trackCount = 0, this._deps.prepareTracking(), this._hotIndex = -1;
|
|
924
891
|
let t = !1;
|
|
925
892
|
try {
|
|
926
|
-
const s =
|
|
927
|
-
this._deps.truncateFrom(this._trackCount),
|
|
893
|
+
const s = _.run(this, this._fn);
|
|
894
|
+
this._deps.truncateFrom(this._trackCount), t = !0, nt(s) ? this._handleAsyncComputation(s) : this._finalizeResolution(s);
|
|
928
895
|
} catch (s) {
|
|
929
896
|
if (!t) try {
|
|
930
897
|
this._deps.truncateFrom(this._trackCount);
|
|
931
898
|
} catch {
|
|
932
899
|
}
|
|
933
|
-
this._handleError(s,
|
|
900
|
+
this._handleError(s, c.COMPUTED_COMPUTATION_FAILED, !0);
|
|
934
901
|
} finally {
|
|
935
|
-
this._trackEpoch =
|
|
902
|
+
this._trackEpoch = b.UNINITIALIZED, this._trackCount = 0, this.flags &= ~N;
|
|
936
903
|
}
|
|
937
904
|
}
|
|
938
905
|
_handleAsyncComputation(t) {
|
|
939
|
-
this.flags = (this.flags |
|
|
906
|
+
this.flags = (this.flags | S) & ~(p | E | d | D), this._notifySubscribers(void 0, void 0), this._promiseId = (this._promiseId + 1) % ut.MAX_PROMISE_ID;
|
|
940
907
|
const s = this._promiseId;
|
|
941
908
|
t.then((e) => {
|
|
942
909
|
if (s === this._promiseId) {
|
|
943
|
-
if (this._isDirty())
|
|
944
|
-
const i = rt();
|
|
945
|
-
return this._lastDriftEpoch !== i && (this._lastDriftEpoch = i, this._asyncRetryCount = 0), this._asyncRetryCount++ < this._maxAsyncRetries ? this._markDirty() : this._handleError(new S(`Async drift threshold exceeded after ${this._maxAsyncRetries} retries.`), _.COMPUTED_ASYNC_COMPUTATION_FAILED);
|
|
946
|
-
}
|
|
910
|
+
if (this._isDirty()) return this._markDirty();
|
|
947
911
|
this._finalizeResolution(e), this._notifySubscribers(e, void 0);
|
|
948
912
|
}
|
|
949
|
-
}, (e) => s === this._promiseId && this._handleError(e,
|
|
913
|
+
}, (e) => s === this._promiseId && this._handleError(e, c.COMPUTED_ASYNC_COMPUTATION_FAILED));
|
|
950
914
|
}
|
|
951
915
|
_handleError(t, s, e = !1) {
|
|
952
|
-
const i =
|
|
953
|
-
if (!e && !this.isRejected && (this.version =
|
|
916
|
+
const i = g(t, m, s);
|
|
917
|
+
if (!e && !this.isRejected && (this.version = H(this.version)), this._error = i, this.flags = this.flags & ~(p | E | S | d) | D | A, this._onError) try {
|
|
954
918
|
this._onError(i);
|
|
955
919
|
} catch (r) {
|
|
956
|
-
console.error(
|
|
920
|
+
console.error(c.CALLBACK_ERROR_IN_ERROR_HANDLER, r);
|
|
957
921
|
}
|
|
958
922
|
if (e) throw i;
|
|
959
923
|
this._notifySubscribers(void 0, void 0);
|
|
960
924
|
}
|
|
961
925
|
_finalizeResolution(t) {
|
|
962
926
|
const s = this.flags;
|
|
963
|
-
((s & d) === 0 || !this._equal(this._value, t)) && (this.version =
|
|
927
|
+
((s & d) === 0 || !this._equal(this._value, t)) && (this.version = H(this.version)), this._value = t, this._error = null, this.flags = (s | d) & ~(p | E | S | D | A);
|
|
964
928
|
}
|
|
965
929
|
execute() {
|
|
966
930
|
this._markDirty();
|
|
967
931
|
}
|
|
968
932
|
_markDirty() {
|
|
969
933
|
const t = this.flags;
|
|
970
|
-
(t & (
|
|
971
|
-
}
|
|
972
|
-
_isDirty() {
|
|
973
|
-
const t = this._deps;
|
|
974
|
-
return t.hasComputeds ? this._deepDirtyCheck() : t.isDirtyFast();
|
|
934
|
+
(t & (N | E)) === 0 && (this.flags = t | E, this._notifySubscribers(void 0, void 0));
|
|
975
935
|
}
|
|
976
936
|
_deepDirtyCheck() {
|
|
977
|
-
const t = this._deps, s =
|
|
978
|
-
|
|
937
|
+
const t = this._deps, s = _.current;
|
|
938
|
+
_.current = null;
|
|
979
939
|
try {
|
|
980
940
|
const e = t.size;
|
|
981
941
|
for (let i = 0; i < e; i++) {
|
|
@@ -991,19 +951,19 @@ var { IDLE: p, DIRTY: E, PENDING: g, RESOLVED: d, REJECTED: D, HAS_ERROR: b, REC
|
|
|
991
951
|
}
|
|
992
952
|
return this._hotIndex = -1, !1;
|
|
993
953
|
} finally {
|
|
994
|
-
|
|
954
|
+
_.current = s;
|
|
995
955
|
}
|
|
996
956
|
}
|
|
997
957
|
};
|
|
998
|
-
function
|
|
999
|
-
return new
|
|
958
|
+
function Ft(t, s = {}) {
|
|
959
|
+
return new Dt(t, s);
|
|
1000
960
|
}
|
|
1001
|
-
var
|
|
961
|
+
var vt = class extends Q {
|
|
1002
962
|
constructor(t, s = {}) {
|
|
1003
|
-
super(), this[
|
|
963
|
+
super(), this[et] = !0, this._cleanup = null, this._deps = new tt(), this._currentEpoch = b.UNINITIALIZED, this._lastFlushEpoch = b.UNINITIALIZED, this._fn = t, this._onError = s.onError ?? null, this._sync = s.sync ?? !1, this._maxExecutions = s.maxExecutionsPerSecond ?? C.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = s.maxExecutionsPerFlush ?? C.MAX_EXECUTIONS_PER_EFFECT, this._executionsInEpoch = 0, this._executionCount = 0, this._windowStart = 0, this._windowCount = 0, this._execId = 0, this._trackCount = 0, this._sync ? this._notifyCallback = () => this.execute() : this._notifyCallback = () => w.schedule(this), G.attachDebugInfo(this, "effect", this.id);
|
|
1004
964
|
}
|
|
1005
965
|
run() {
|
|
1006
|
-
if (this.isDisposed) throw new v(
|
|
966
|
+
if (this.isDisposed) throw new v(c.EFFECT_DISPOSED);
|
|
1007
967
|
this.execute(!0);
|
|
1008
968
|
}
|
|
1009
969
|
dispose() {
|
|
@@ -1041,14 +1001,14 @@ var yt = class extends Y {
|
|
|
1041
1001
|
let e;
|
|
1042
1002
|
try {
|
|
1043
1003
|
const i = t.subscribe(this._notifyCallback);
|
|
1044
|
-
e = new
|
|
1004
|
+
e = new z(t, t.version, i);
|
|
1045
1005
|
} catch (i) {
|
|
1046
|
-
const r =
|
|
1006
|
+
const r = g(i, v, c.EFFECT_EXECUTION_FAILED);
|
|
1047
1007
|
if (console.error(r), this._onError) try {
|
|
1048
1008
|
this._onError(r);
|
|
1049
1009
|
} catch {
|
|
1050
1010
|
}
|
|
1051
|
-
e = new
|
|
1011
|
+
e = new z(t, t.version, void 0);
|
|
1052
1012
|
}
|
|
1053
1013
|
this._deps.insertNew(s, e);
|
|
1054
1014
|
}
|
|
@@ -1060,8 +1020,8 @@ var yt = class extends Y {
|
|
|
1060
1020
|
this._checkInfiniteLoops(), this.flags = s | I.EXECUTING, this._execCleanup(), this._currentEpoch = k(), this._trackCount = 0, e.prepareTracking(), this._hotIndex = -1;
|
|
1061
1021
|
let i = !1;
|
|
1062
1022
|
try {
|
|
1063
|
-
const r =
|
|
1064
|
-
e.truncateFrom(this._trackCount),
|
|
1023
|
+
const r = _.run(this, this._fn);
|
|
1024
|
+
e.truncateFrom(this._trackCount), i = !0, nt(r) ? this._handleAsyncResult(r) : this._cleanup = typeof r == "function" ? r : null;
|
|
1065
1025
|
} catch (r) {
|
|
1066
1026
|
if (!i) try {
|
|
1067
1027
|
e.truncateFrom(this._trackCount);
|
|
@@ -1072,10 +1032,6 @@ var yt = class extends Y {
|
|
|
1072
1032
|
this.flags &= ~I.EXECUTING;
|
|
1073
1033
|
}
|
|
1074
1034
|
}
|
|
1075
|
-
_isDirty() {
|
|
1076
|
-
const t = this._deps;
|
|
1077
|
-
return t.hasComputeds ? this._deepDirtyCheck() : t.isDirtyFast();
|
|
1078
|
-
}
|
|
1079
1035
|
_handleAsyncResult(t) {
|
|
1080
1036
|
const s = ++this._execId;
|
|
1081
1037
|
t.then((e) => {
|
|
@@ -1083,7 +1039,7 @@ var yt = class extends Y {
|
|
|
1083
1039
|
if (typeof e == "function") try {
|
|
1084
1040
|
e();
|
|
1085
1041
|
} catch (i) {
|
|
1086
|
-
this._handleExecutionError(i,
|
|
1042
|
+
this._handleExecutionError(i, c.EFFECT_CLEANUP_FAILED);
|
|
1087
1043
|
}
|
|
1088
1044
|
return;
|
|
1089
1045
|
}
|
|
@@ -1091,8 +1047,8 @@ var yt = class extends Y {
|
|
|
1091
1047
|
}, (e) => s === this._execId && this._handleExecutionError(e));
|
|
1092
1048
|
}
|
|
1093
1049
|
_deepDirtyCheck() {
|
|
1094
|
-
const t =
|
|
1095
|
-
|
|
1050
|
+
const t = _.current;
|
|
1051
|
+
_.current = null;
|
|
1096
1052
|
const s = this._deps;
|
|
1097
1053
|
try {
|
|
1098
1054
|
const e = s.size;
|
|
@@ -1105,7 +1061,7 @@ var yt = class extends Y {
|
|
|
1105
1061
|
}
|
|
1106
1062
|
return !1;
|
|
1107
1063
|
} finally {
|
|
1108
|
-
|
|
1064
|
+
_.current = t;
|
|
1109
1065
|
}
|
|
1110
1066
|
}
|
|
1111
1067
|
_tryPullComputed(t) {
|
|
@@ -1121,23 +1077,23 @@ var yt = class extends Y {
|
|
|
1121
1077
|
try {
|
|
1122
1078
|
t();
|
|
1123
1079
|
} catch (s) {
|
|
1124
|
-
this._handleExecutionError(s,
|
|
1080
|
+
this._handleExecutionError(s, c.EFFECT_CLEANUP_FAILED);
|
|
1125
1081
|
}
|
|
1126
1082
|
}
|
|
1127
1083
|
}
|
|
1128
1084
|
_checkInfiniteLoops() {
|
|
1129
|
-
const t =
|
|
1130
|
-
this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"),
|
|
1085
|
+
const t = dt();
|
|
1086
|
+
this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), pt() > C.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++;
|
|
1131
1087
|
}
|
|
1132
1088
|
_checkFrequencyLimit() {
|
|
1133
1089
|
if (!Number.isFinite(this._maxExecutions)) return;
|
|
1134
1090
|
const t = Date.now();
|
|
1135
|
-
if (t - this._windowStart >=
|
|
1091
|
+
if (t - this._windowStart >= Z.EFFECT_FREQUENCY_WINDOW) {
|
|
1136
1092
|
this._windowStart = t, this._windowCount = 1;
|
|
1137
1093
|
return;
|
|
1138
1094
|
}
|
|
1139
1095
|
if (++this._windowCount > this._maxExecutions) {
|
|
1140
|
-
const s = new v(
|
|
1096
|
+
const s = new v(c.EFFECT_FREQUENCY_LIMIT_EXCEEDED);
|
|
1141
1097
|
throw this.dispose(), this._handleExecutionError(s), s;
|
|
1142
1098
|
}
|
|
1143
1099
|
}
|
|
@@ -1151,24 +1107,24 @@ var yt = class extends Y {
|
|
|
1151
1107
|
const s = new v(`Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${V}`);
|
|
1152
1108
|
throw this.dispose(), console.error(s), s;
|
|
1153
1109
|
}
|
|
1154
|
-
_handleExecutionError(t, s =
|
|
1155
|
-
const e =
|
|
1110
|
+
_handleExecutionError(t, s = c.EFFECT_EXECUTION_FAILED) {
|
|
1111
|
+
const e = g(t, v, s);
|
|
1156
1112
|
if (console.error(e), this._onError) try {
|
|
1157
1113
|
this._onError(e);
|
|
1158
1114
|
} catch (i) {
|
|
1159
|
-
console.error(
|
|
1115
|
+
console.error(g(i, v, c.CALLBACK_ERROR_IN_ERROR_HANDLER));
|
|
1160
1116
|
}
|
|
1161
1117
|
}
|
|
1162
1118
|
};
|
|
1163
|
-
function
|
|
1164
|
-
if (typeof t != "function") throw new v(
|
|
1165
|
-
const e = new
|
|
1119
|
+
function Rt(t, s = {}) {
|
|
1120
|
+
if (typeof t != "function") throw new v(c.EFFECT_MUST_BE_FUNCTION);
|
|
1121
|
+
const e = new vt(t, s);
|
|
1166
1122
|
return e.execute(), e;
|
|
1167
1123
|
}
|
|
1168
|
-
var
|
|
1169
|
-
function
|
|
1124
|
+
var St = /* @__PURE__ */ Symbol.for("atom-effect/atom"), gt = /* @__PURE__ */ Symbol.for("atom-effect/writable");
|
|
1125
|
+
function rt(t, s, e, i) {
|
|
1170
1126
|
if (e === s.length) return i;
|
|
1171
|
-
const r = s[e], n = t != null && typeof t == "object" ? t : {}, o = n[r], u =
|
|
1127
|
+
const r = s[e], n = t != null && typeof t == "object" ? t : {}, o = n[r], u = rt(o, s, e + 1, i);
|
|
1172
1128
|
if (Object.is(o, u)) return t;
|
|
1173
1129
|
if (Array.isArray(n)) {
|
|
1174
1130
|
const l = n.slice(), h = Number.parseInt(r, 10);
|
|
@@ -1179,7 +1135,7 @@ function ct(t, s, e, i) {
|
|
|
1179
1135
|
[r]: u
|
|
1180
1136
|
};
|
|
1181
1137
|
}
|
|
1182
|
-
function
|
|
1138
|
+
function F(t, s) {
|
|
1183
1139
|
let e = t;
|
|
1184
1140
|
const i = s.length;
|
|
1185
1141
|
for (let r = 0; r < i; r++) {
|
|
@@ -1188,23 +1144,23 @@ function R(t, s) {
|
|
|
1188
1144
|
}
|
|
1189
1145
|
return e;
|
|
1190
1146
|
}
|
|
1191
|
-
function
|
|
1147
|
+
function ot(t, s) {
|
|
1192
1148
|
const e = s.includes(".") ? s.split(".") : [s], i = /* @__PURE__ */ new Set(), r = () => {
|
|
1193
1149
|
i.forEach((n) => n()), i.clear();
|
|
1194
1150
|
};
|
|
1195
1151
|
return {
|
|
1196
1152
|
get value() {
|
|
1197
|
-
return
|
|
1153
|
+
return F(t.value, e);
|
|
1198
1154
|
},
|
|
1199
1155
|
set value(n) {
|
|
1200
|
-
const o = t.peek(), u =
|
|
1156
|
+
const o = t.peek(), u = rt(o, e, 0, n);
|
|
1201
1157
|
u !== o && (t.value = u);
|
|
1202
1158
|
},
|
|
1203
|
-
peek: () =>
|
|
1159
|
+
peek: () => F(t.peek(), e),
|
|
1204
1160
|
subscribe(n) {
|
|
1205
1161
|
const o = t.subscribe((u, l) => {
|
|
1206
|
-
const h =
|
|
1207
|
-
Object.is(h,
|
|
1162
|
+
const h = F(u, e), f = F(l, e);
|
|
1163
|
+
Object.is(h, f) || n(h, f);
|
|
1208
1164
|
});
|
|
1209
1165
|
return i.add(o), () => {
|
|
1210
1166
|
o(), i.delete(o);
|
|
@@ -1213,44 +1169,34 @@ function _t(t, s) {
|
|
|
1213
1169
|
subscriberCount: () => i.size,
|
|
1214
1170
|
dispose: r,
|
|
1215
1171
|
[Symbol.dispose]: r,
|
|
1216
|
-
[
|
|
1217
|
-
[
|
|
1172
|
+
[St]: !0,
|
|
1173
|
+
[gt]: !0
|
|
1218
1174
|
};
|
|
1219
1175
|
}
|
|
1220
|
-
var
|
|
1221
|
-
function Ht(t) {
|
|
1222
|
-
if (typeof t != "function") throw new TypeError(_.BATCH_CALLBACK_MUST_BE_FUNCTION);
|
|
1223
|
-
const s = w;
|
|
1224
|
-
s.startBatch();
|
|
1225
|
-
try {
|
|
1226
|
-
return t();
|
|
1227
|
-
} finally {
|
|
1228
|
-
s.endBatch();
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1176
|
+
var wt = (t, s) => ot(t, s), Ut = (t) => (s) => ot(t, s);
|
|
1231
1177
|
export {
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1178
|
+
y as AsyncState,
|
|
1179
|
+
T as AtomError,
|
|
1180
|
+
m as ComputedError,
|
|
1181
|
+
Z as DEBUG_CONFIG,
|
|
1182
|
+
G as DEBUG_RUNTIME,
|
|
1237
1183
|
v as EffectError,
|
|
1238
1184
|
C as SCHEDULER_CONFIG,
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1185
|
+
U as SchedulerError,
|
|
1186
|
+
bt as atom,
|
|
1187
|
+
ot as atomLens,
|
|
1188
|
+
Nt as batch,
|
|
1189
|
+
wt as composeLens,
|
|
1190
|
+
Ft as computed,
|
|
1191
|
+
Rt as effect,
|
|
1192
|
+
F as getPathValue,
|
|
1193
|
+
yt as isAtom,
|
|
1194
|
+
At as isComputed,
|
|
1195
|
+
Ot as isEffect,
|
|
1196
|
+
Ut as lensFor,
|
|
1251
1197
|
w as scheduler,
|
|
1252
|
-
|
|
1253
|
-
|
|
1198
|
+
rt as setDeepValue,
|
|
1199
|
+
mt as untracked
|
|
1254
1200
|
};
|
|
1255
1201
|
|
|
1256
1202
|
//# sourceMappingURL=index.mjs.map
|