@but212/atom-effect 0.27.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/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var A = {
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
- }, H = {
9
+ }, B = {
10
10
  DISPOSED: 1,
11
11
  IS_COMPUTED: 2,
12
12
  DIRTY: 8,
@@ -28,45 +28,25 @@ var A = {
28
28
  MAX_FLUSH_ITERATIONS: 1e3,
29
29
  MIN_FLUSH_ITERATIONS: 10,
30
30
  BATCH_QUEUE_SHRINK_THRESHOLD: 1e3
31
- }, st = {
31
+ }, Z = {
32
32
  WARN_INFINITE_LOOP: !0,
33
33
  EFFECT_FREQUENCY_WINDOW: 1e3
34
- }, j = {
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
- }, w = 1073741823, _t = { VERSION_BITS: 16 }, mt = (typeof process < "u" && process.env, !1), W = Object.freeze([]), z = class {
41
- constructor(t, s, e = void 0) {
42
- this.node = t, this.version = s, this.unsub = e;
43
- }
44
- }, ft = 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
- }, S = class extends N {
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 N {
45
+ }, v = class extends T {
66
46
  constructor(t, s = null) {
67
47
  super(t, s, !1), this.name = "EffectError";
68
48
  }
69
- }, L = class extends N {
49
+ }, U = class extends T {
70
50
  constructor(t, s = null) {
71
51
  super(t, s, !1), this.name = "SchedulerError";
72
52
  }
@@ -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
- }, et = class {
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
  }
@@ -239,8 +239,8 @@ var A = {
239
239
  if (o != null && (t(o), ++e === s))
240
240
  return;
241
241
  const u = this._overflow;
242
- if (u != null) for (let h = 0, l = u.length; h < l; h++) {
243
- const f = u[h];
242
+ if (u != null) for (let l = 0, h = u.length; l < h; l++) {
243
+ const f = u[l];
244
244
  if (f != null && (t(f), ++e === s))
245
245
  return;
246
246
  }
@@ -262,8 +262,8 @@ var A = {
262
262
  if (o != null && (t(o), ++e === s))
263
263
  return e;
264
264
  const u = this._overflow;
265
- if (u != null) for (let h = 0, l = u.length; h < l; h++) {
266
- const f = u[h];
265
+ if (u != null) for (let l = 0, h = u.length; l < h; l++) {
266
+ const f = u[l];
267
267
  if (f != null && (t(f), ++e === s))
268
268
  return e;
269
269
  }
@@ -288,44 +288,201 @@ var A = {
288
288
  dispose() {
289
289
  this.clear();
290
290
  }
291
- }, K = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), at = /* @__PURE__ */ Symbol("AtomEffect.Id"), Z = /* @__PURE__ */ Symbol("AtomEffect.Type"), P = /* @__PURE__ */ Symbol("AtomEffect.NoDefaultValue"), Et = class {
292
- constructor() {
293
- this.enabled = !1, this.warnInfiniteLoop = st.WARN_INFINITE_LOOP;
291
+ }, tt = class extends J {
292
+ constructor(...t) {
293
+ super(...t), this._map = null, this._SCAN_THRESHOLD = 32, this.hasComputeds = !1;
294
294
  }
295
- warn(t, s) {
295
+ prepareTracking() {
296
+ this.hasComputeds = !1;
296
297
  }
297
- attachDebugInfo(t, s, e) {
298
+ _onItemRemoved(t) {
299
+ const s = t.unsub;
300
+ s && s();
298
301
  }
299
- getDebugName(t) {
300
- if (t != null)
301
- return t[K];
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
- getDebugType(t) {
304
- if (t != null)
305
- return t[Z];
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
- }, G = new Et(), dt = 1, pt = () => dt++ | 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
468
  var Q = class {
312
469
  constructor() {
313
- this.flags = 0, this.version = 0, this._lastSeenEpoch = T.UNINITIALIZED, this._notifying = 0, this._hotIndex = -1, this._slots = null, this._deps = null, this.id = pt() & w;
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 & H.DISPOSED) !== 0;
473
+ return (this.flags & B.DISPOSED) !== 0;
317
474
  }
318
475
  get isComputed() {
319
- return (this.flags & H.IS_COMPUTED) !== 0;
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 m(/* @__PURE__ */ new TypeError("Invalid subscriber"), N, c.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
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 et(), this._slots = e);
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;
@@ -334,8 +491,8 @@ var Q = class {
334
491
  else {
335
492
  const n = e._overflow;
336
493
  if (n != null) for (let o = 0, u = n.length; o < u; o++) {
337
- const h = n[o];
338
- if (h != null && (s ? h.fn === t : h.sub === t)) {
494
+ const l = n[o];
495
+ if (l != null && (s ? l.fn === t : l.sub === t)) {
339
496
  i = !0;
340
497
  break;
341
498
  }
@@ -386,8 +543,8 @@ var Q = class {
386
543
  const u = r[n];
387
544
  if (u != null) try {
388
545
  u.notify(t, s);
389
- } catch (h) {
390
- this._logNotifyError(h);
546
+ } catch (l) {
547
+ this._logNotifyError(l);
391
548
  }
392
549
  }
393
550
  } finally {
@@ -396,7 +553,7 @@ var Q = class {
396
553
  }
397
554
  }
398
555
  _logNotifyError(t) {
399
- console.error(m(t, N, c.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED));
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 Q = class {
406
563
  const e = t.getAt(s);
407
564
  if (e != null && e.node.version !== e.version) return !0;
408
565
  }
409
- return !t.hasComputeds && !t.isDirtyFast() ? !1 : this._deepDirtyCheck();
566
+ return this._deepDirtyCheck();
410
567
  }
411
- }, M = 0;
412
- function Y() {
413
- const t = M + 1 & w;
414
- return M = t === 0 ? 1 : t, M;
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;
569
+ function k() {
570
+ const t = P + 1 & X;
571
+ return P = t === 0 ? 1 : t, P;
415
572
  }
416
- function X(t) {
417
- const s = t + 1 & w;
573
+ function H(t) {
574
+ const s = t + 1 & X;
418
575
  return s === 0 ? 1 : s;
419
576
  }
420
- var k = 0, R = !1, it = 0;
421
- function nt() {
577
+ var V = 0, R = !1, it = 0;
578
+ function dt() {
422
579
  return it;
423
580
  }
424
- function J() {
425
- return R ? !1 : (R = !0, it = Y(), k = 0, !0);
581
+ function W() {
582
+ return R ? !1 : (R = !0, it = k(), V = 0, !0);
426
583
  }
427
- function tt() {
584
+ function K() {
428
585
  R = !1;
429
586
  }
430
- function Ct() {
587
+ function pt() {
431
588
  if (!R) return 0;
432
- const t = ++k;
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 It = class {
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 It = class {
459
616
  _runLoop() {
460
617
  try {
461
618
  if (this._size === 0) return;
462
- const t = J();
463
- this._drainQueue(), t && tt();
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 = J();
627
+ const t = W();
471
628
  try {
472
629
  this._mergeBatchQueue(), this._drainQueue();
473
630
  } finally {
474
- this._isFlushingSync = !1, t && tt();
631
+ this._isFlushingSync = !1, t && K();
475
632
  }
476
633
  }
477
634
  _mergeBatchQueue() {
@@ -503,14 +660,14 @@ var It = class {
503
660
  try {
504
661
  typeof r == "function" ? r() : r.execute();
505
662
  } catch (n) {
506
- console.error(new L("Error occurred during scheduler execution", n));
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 L(c.SCHEDULER_FLUSH_OVERFLOW(s, t))), this._size = 0;
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,36 +683,23 @@ var It = 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 L(`Max flush iterations must be at least ${C.MIN_FLUSH_ITERATIONS}`);
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
- }, F = new It(), V = /* @__PURE__ */ Symbol.for("atom-effect/atom"), rt = /* @__PURE__ */ Symbol.for("atom-effect/computed"), ot = /* @__PURE__ */ Symbol.for("atom-effect/effect"), Dt = /* @__PURE__ */ Symbol.for("atom-effect/writable"), vt = class {
533
- constructor() {
534
- this.current = null;
535
- }
536
- run(t, s) {
537
- const e = this.current;
538
- this.current = t;
539
- try {
540
- return s();
541
- } finally {
542
- this.current = e;
543
- }
544
- }
545
- }, _ = new vt();
689
+ }, w = new Ct();
546
690
  function Nt(t) {
547
- const s = _, e = s.current;
548
- if (e === null) return t();
549
- s.current = null;
691
+ if (typeof t != "function") throw new TypeError(c.BATCH_CALLBACK_MUST_BE_FUNCTION);
692
+ const s = w;
693
+ s.startBatch();
550
694
  try {
551
695
  return t();
552
696
  } finally {
553
- s.current = e;
697
+ s.endBatch();
554
698
  }
555
699
  }
556
- var St = class extends Q {
700
+ var It = class extends Q {
557
701
  constructor(t, s) {
558
- super(), this[V] = !0, this[Dt] = !0, this._value = t, s && (this.flags |= a.SYNC), G.attachDebugInfo(this, "atom", this.id);
702
+ super(), this[$] = !0, this[Et] = !0, this._value = t, s && (this.flags |= a.SYNC), G.attachDebugInfo(this, "atom", this.id);
559
703
  }
560
704
  get isNotificationScheduled() {
561
705
  return (this.flags & a.NOTIFICATION_SCHEDULED) !== 0;
@@ -570,11 +714,11 @@ var St = class extends Q {
570
714
  set value(t) {
571
715
  const s = this._value;
572
716
  if (Object.is(s, t)) return;
573
- this._value = t, this.version = X(this.version);
717
+ this._value = t, this.version = H(this.version);
574
718
  const e = this.flags;
575
719
  if ((e & a.NOTIFICATION_SCHEDULED) !== 0) return;
576
720
  const i = this._slots;
577
- i == null || i.size === 0 || (this._pendingOldValue = s, this.flags = e | a.NOTIFICATION_SCHEDULED, (e & a.SYNC) !== 0 && !F.isBatching ? this._flushNotifications() : F.schedule(this));
721
+ i == null || i.size === 0 || (this._pendingOldValue = s, this.flags = e | a.NOTIFICATION_SCHEDULED, (e & a.SYNC) !== 0 && !w.isBatching ? this._flushNotifications() : w.schedule(this));
578
722
  }
579
723
  execute() {
580
724
  this._flushNotifications();
@@ -599,201 +743,25 @@ var St = class extends Q {
599
743
  this.dispose();
600
744
  }
601
745
  };
602
- function yt(t, s = {}) {
603
- return new St(t, s.sync ?? !1);
746
+ function bt(t, s = {}) {
747
+ return new It(t, s.sync ?? !1);
748
+ }
749
+ function yt(t) {
750
+ return typeof t == "object" && t !== null && $ in t;
604
751
  }
605
- var ut = class extends et {
606
- constructor(...t) {
607
- super(...t), this._map = null, this._SCAN_THRESHOLD = 32, this.hasComputeds = !1, this._depsHash = 0;
608
- }
609
- prepareTracking() {
610
- this.hasComputeds = !1;
611
- }
612
- _onItemRemoved(t) {
613
- const s = t.unsub;
614
- s && s();
615
- }
616
- claimExisting(t, s) {
617
- const e = this._count;
618
- if (s >= e) return !1;
619
- const i = e - s;
620
- if (this._map !== null || i > this._SCAN_THRESHOLD) return this._claimViaMap(t, s);
621
- if (s < 4) switch (s) {
622
- case 0: {
623
- const n = this._s0;
624
- if (n && n.node === t && n.unsub)
625
- return n.version = t.version, !0;
626
- }
627
- case 1:
628
- if (e > 1) {
629
- const n = this._s1;
630
- if (n && n.node === t && n.unsub)
631
- return n.version = t.version, s !== 1 && (this._s1 = this._s0, this._s0 = n), !0;
632
- }
633
- case 2:
634
- if (e > 2) {
635
- const n = this._s2;
636
- if (n && n.node === t && n.unsub) {
637
- if (n.version = t.version, s !== 2) {
638
- const o = s === 0 ? this._s0 : this._s1;
639
- s === 0 ? this._s0 = n : this._s1 = n, this._s2 = o;
640
- }
641
- return !0;
642
- }
643
- }
644
- case 3:
645
- if (e > 3) {
646
- const n = this._s3;
647
- if (n && n.node === t && n.unsub) {
648
- if (n.version = t.version, s !== 3) {
649
- let o;
650
- 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;
651
- }
652
- return !0;
653
- }
654
- }
655
- }
656
- const r = this._overflow;
657
- if (r) {
658
- const n = t.version, o = s > 4 ? s : 4, u = r.length;
659
- for (let h = o - 4; h < u; h++) {
660
- const l = r[h];
661
- if (l && l.node === t && l.unsub)
662
- return l.version = n, this._swapGeneral(h + 4, s, l), !0;
663
- }
664
- }
665
- return !1;
666
- }
667
- _claimViaMap(t, s) {
668
- let e = this._map;
669
- if (e === null) {
670
- e = this._map = /* @__PURE__ */ new Map();
671
- const n = this._count;
672
- if (s < 4) {
673
- const u = this._s0;
674
- s <= 0 && u?.unsub && e.set(u.node, 0);
675
- const h = this._s1;
676
- s <= 1 && h?.unsub && e.set(h.node, 1);
677
- const l = this._s2;
678
- s <= 2 && l?.unsub && e.set(l.node, 2);
679
- const f = this._s3;
680
- s <= 3 && f?.unsub && e.set(f.node, 3);
681
- }
682
- const o = this._overflow;
683
- if (o && n > 4) {
684
- const u = s > 4 ? s : 4, h = o.length;
685
- for (let l = u - 4; l < h; l++) {
686
- const f = o[l];
687
- f?.unsub && e.set(f.node, l + 4);
688
- }
689
- }
690
- }
691
- const i = e.get(t);
692
- if (i === void 0 || i < s) return !1;
693
- const r = this.getAt(i);
694
- if (r == null || !r.unsub) return !1;
695
- if (r.version = t.version, i !== s) {
696
- let n;
697
- 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);
698
- }
699
- return !0;
700
- }
701
- _swapGeneral(t, s, e) {
702
- if (t === s) return;
703
- let i;
704
- 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;
705
- else if (t === 1) this._s1 = i;
706
- else if (t === 2) this._s2 = i;
707
- else if (t === 3) this._s3 = i;
708
- else {
709
- const r = this._overflow;
710
- r[t - 4] = i;
711
- }
712
- }
713
- insertNew(t, s) {
714
- const e = this._count;
715
- if (t < e) {
716
- let i;
717
- 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));
718
- }
719
- if (t === 0) this._s0 = s;
720
- else if (t === 1) this._s1 = s;
721
- else if (t === 2) this._s2 = s;
722
- else if (t === 3) this._s3 = s;
723
- else {
724
- let i = this._overflow;
725
- i || (i = [], this._overflow = i), i[t - 4] = s;
726
- }
727
- t >= e && (this._count = t + 1);
728
- }
729
- truncateFrom(t) {
730
- t >= this._count || (super.truncateFrom(t), this._map !== null && (this._map.clear(), this._map = null));
731
- }
732
- seal() {
733
- this._depsHash = this._calculateHash(!1);
734
- }
735
- isDirtyFast() {
736
- return this._calculateHash(!0) !== this._depsHash;
737
- }
738
- _calculateHash(t) {
739
- const s = this._count;
740
- if (s === 0) return 0;
741
- const e = _t.VERSION_BITS;
742
- let i = 0;
743
- const r = this._s0;
744
- if (r != null) {
745
- const n = r.node, o = t ? n.version : r.version;
746
- i = i + (o << e) + n.id | 0;
747
- const u = this._s1;
748
- if (s > 1 && u != null) {
749
- const h = u.node, l = t ? h.version : u.version;
750
- i = i + (l << e) + h.id | 0;
751
- const f = this._s2;
752
- if (s > 2 && f != null) {
753
- const $ = f.node, lt = t ? $.version : f.version;
754
- i = i + (lt << e) + $.id | 0;
755
- const U = this._s3;
756
- if (s > 3 && U != null) {
757
- const q = U.node, ct = t ? q.version : U.version;
758
- i = i + (ct << e) + q.id | 0;
759
- }
760
- }
761
- }
762
- }
763
- if (s > 4) {
764
- const n = this._overflow;
765
- for (let o = 0, u = n.length; o < u; o++) {
766
- const h = n[o], l = h.node, f = t ? l.version : h.version;
767
- i = i + (f << e) + l.id | 0;
768
- }
769
- }
770
- return i;
771
- }
772
- disposeAll() {
773
- this._count > 0 && this.truncateFrom(0), this.hasComputeds = !1;
774
- }
775
- remove(t) {
776
- throw new Error("remove() is strictly prohibited in DepSlotBuffer to preserve sequential cache paths.");
777
- }
778
- compact() {
779
- }
780
- };
781
752
  function At(t) {
782
- return typeof t == "object" && t !== null && V in t;
753
+ return typeof t == "object" && t !== null && st in t;
783
754
  }
784
755
  function Ot(t) {
785
- return typeof t == "object" && t !== null && rt in t;
756
+ return typeof t == "object" && t !== null && et in t;
786
757
  }
787
- function bt(t) {
788
- return typeof t == "object" && t !== null && ot in t;
789
- }
790
- function ht(t) {
758
+ function nt(t) {
791
759
  return typeof t == "object" && t !== null && typeof t.then == "function";
792
760
  }
793
- var { IDLE: p, DIRTY: E, PENDING: g, RESOLVED: d, REJECTED: D, HAS_ERROR: O, RECOMPUTING: y, DISPOSED: x, IS_COMPUTED: b, FORCE_COMPUTE: B } = H, gt = class extends Q {
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 {
794
762
  constructor(t, s = {}) {
795
- if (typeof t != "function") throw new S(c.COMPUTED_MUST_BE_FUNCTION);
796
- if (super(), this[V] = !0, this[rt] = !0, this._error = null, this._promiseId = 0, this._deps = new ut(), this._asyncRetryCount = 0, this._lastDriftEpoch = T.UNINITIALIZED, this._trackEpoch = T.UNINITIALIZED, this._trackCount = 0, this._value = void 0, this.flags = b | E | p, this._equal = s.equal ?? Object.is, this._fn = t, this._defaultValue = "defaultValue" in s ? s.defaultValue : P, this._onError = s.onError ?? null, this._maxAsyncRetries = (s.maxAsyncRetries ?? j.MAX_ASYNC_RETRIES) & w, G.attachDebugInfo(this, "computed", this.id), s.lazy === !1) try {
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 {
797
765
  this._recompute();
798
766
  } catch {
799
767
  }
@@ -805,10 +773,10 @@ var { IDLE: p, DIRTY: E, PENDING: g, RESOLVED: d, REJECTED: D, HAS_ERROR: O, REC
805
773
  return (this.flags & D) !== 0;
806
774
  }
807
775
  get isRecomputing() {
808
- return (this.flags & y) !== 0;
776
+ return (this.flags & N) !== 0;
809
777
  }
810
778
  get _hasErrorInternal() {
811
- return (this.flags & O) !== 0;
779
+ return (this.flags & A) !== 0;
812
780
  }
813
781
  _track() {
814
782
  _.current?.addDependency(this);
@@ -818,20 +786,20 @@ var { IDLE: p, DIRTY: E, PENDING: g, RESOLVED: d, REJECTED: D, HAS_ERROR: O, REC
818
786
  t?.addDependency(this);
819
787
  let s = this.flags;
820
788
  if ((s & (d | E | p)) === d) return this._value;
821
- if ((s & x) !== 0) throw new S(c.COMPUTED_DISPOSED);
822
- if ((s & y) !== 0) {
789
+ if ((s & M) !== 0) throw new m(c.COMPUTED_DISPOSED);
790
+ if ((s & N) !== 0) {
823
791
  const r = this._defaultValue;
824
- if (r !== P) return r;
825
- throw new S(c.COMPUTED_CIRCULAR_DEPENDENCY);
792
+ if (r !== L) return r;
793
+ throw new m(c.COMPUTED_CIRCULAR_DEPENDENCY);
826
794
  }
827
795
  if ((s & (E | p)) !== 0) {
828
796
  const r = this._deps;
829
- if ((s & p) === 0 && (s & B) === 0 && r.size > 0 && !this._isDirty() ? s = this.flags &= ~E : (this._recompute(), s = this.flags), (s & d) !== 0) return this._value;
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;
830
798
  }
831
- const e = this._defaultValue, i = e !== P;
832
- if ((s & g) !== 0) {
799
+ const e = this._defaultValue, i = e !== L;
800
+ if ((s & S) !== 0) {
833
801
  if (i) return e;
834
- throw new S(c.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
802
+ throw new m(c.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
835
803
  }
836
804
  if ((s & D) !== 0) {
837
805
  if (i) return e;
@@ -846,11 +814,11 @@ var { IDLE: p, DIRTY: E, PENDING: g, RESOLVED: d, REJECTED: D, HAS_ERROR: O, REC
846
814
  const t = _.current;
847
815
  t?.addDependency(this);
848
816
  const s = this.flags;
849
- return (s & d) !== 0 ? A.RESOLVED : (s & g) !== 0 ? A.PENDING : (s & D) !== 0 ? A.REJECTED : A.IDLE;
817
+ return (s & d) !== 0 ? y.RESOLVED : (s & S) !== 0 ? y.PENDING : (s & D) !== 0 ? y.REJECTED : y.IDLE;
850
818
  }
851
819
  get hasError() {
852
820
  const t = _.current;
853
- if (t?.addDependency(this), (this.flags & (D | O)) !== 0) return !0;
821
+ if (t?.addDependency(this), (this.flags & (D | A)) !== 0) return !0;
854
822
  const s = this._deps;
855
823
  if (!s.hasComputeds) return !1;
856
824
  const e = s.size;
@@ -865,7 +833,7 @@ var { IDLE: p, DIRTY: E, PENDING: g, RESOLVED: d, REJECTED: D, HAS_ERROR: O, REC
865
833
  t?.addDependency(this);
866
834
  const s = this._error, e = this._deps;
867
835
  if (!e.hasComputeds)
868
- return s == null ? W : Object.freeze([s]);
836
+ return s == null ? Y : Object.freeze([s]);
869
837
  const i = [];
870
838
  s != null && i.push(s);
871
839
  const r = e.size;
@@ -873,9 +841,9 @@ var { IDLE: p, DIRTY: E, PENDING: g, RESOLVED: d, REJECTED: D, HAS_ERROR: O, REC
873
841
  const o = e.getAt(n);
874
842
  if (o == null) continue;
875
843
  const u = o.node;
876
- (u.flags & b) !== 0 && u.hasError && this._collectErrorsFromDep(u, i);
844
+ (u.flags & O) !== 0 && u.hasError && this._collectErrorsFromDep(u, i);
877
845
  }
878
- return i.length === 0 ? W : Object.freeze(i);
846
+ return i.length === 0 ? Y : Object.freeze(i);
879
847
  }
880
848
  _collectErrorsFromDep(t, s) {
881
849
  const e = t.errors, i = e.length;
@@ -890,17 +858,17 @@ var { IDLE: p, DIRTY: E, PENDING: g, RESOLVED: d, REJECTED: D, HAS_ERROR: O, REC
890
858
  }
891
859
  get isPending() {
892
860
  const t = _.current;
893
- return t?.addDependency(this), (this.flags & g) !== 0;
861
+ return t?.addDependency(this), (this.flags & S) !== 0;
894
862
  }
895
863
  get isResolved() {
896
864
  const t = _.current;
897
865
  return t?.addDependency(this), (this.flags & d) !== 0;
898
866
  }
899
867
  invalidate() {
900
- this.flags |= B, this._markDirty();
868
+ this.flags |= x, this._markDirty();
901
869
  }
902
870
  dispose() {
903
- (this.flags & x) === 0 && (this._deps.disposeAll(), this._slots != null && this._slots.clear(), this.flags = x | E | p, this._error = null, this._value = void 0, this._hotIndex = -1);
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);
904
872
  }
905
873
  [Symbol.dispose]() {
906
874
  this.dispose();
@@ -915,15 +883,15 @@ var { IDLE: p, DIRTY: E, PENDING: g, RESOLVED: d, REJECTED: D, HAS_ERROR: O, REC
915
883
  const n = new z(t, t.version, t.subscribe(this));
916
884
  i.insertNew(e, n);
917
885
  }
918
- (t.flags & b) !== 0 && (i.hasComputeds = !0);
886
+ (t.flags & O) !== 0 && (i.hasComputeds = !0);
919
887
  }
920
888
  _recompute() {
921
889
  if (this.isRecomputing) return;
922
- this.flags = (this.flags | y) & ~B, this._trackEpoch = Y(), this._trackCount = 0, this._deps.prepareTracking(), this._hotIndex = -1;
890
+ this.flags = (this.flags | N) & ~x, this._trackEpoch = k(), this._trackCount = 0, this._deps.prepareTracking(), this._hotIndex = -1;
923
891
  let t = !1;
924
892
  try {
925
893
  const s = _.run(this, this._fn);
926
- this._deps.truncateFrom(this._trackCount), this._deps.seal(), t = !0, ht(s) ? this._handleAsyncComputation(s) : this._finalizeResolution(s);
894
+ this._deps.truncateFrom(this._trackCount), t = !0, nt(s) ? this._handleAsyncComputation(s) : this._finalizeResolution(s);
927
895
  } catch (s) {
928
896
  if (!t) try {
929
897
  this._deps.truncateFrom(this._trackCount);
@@ -931,25 +899,22 @@ var { IDLE: p, DIRTY: E, PENDING: g, RESOLVED: d, REJECTED: D, HAS_ERROR: O, REC
931
899
  }
932
900
  this._handleError(s, c.COMPUTED_COMPUTATION_FAILED, !0);
933
901
  } finally {
934
- this._trackEpoch = T.UNINITIALIZED, this._trackCount = 0, this.flags &= ~y;
902
+ this._trackEpoch = b.UNINITIALIZED, this._trackCount = 0, this.flags &= ~N;
935
903
  }
936
904
  }
937
905
  _handleAsyncComputation(t) {
938
- this.flags = (this.flags | g) & ~(p | E | d | D), this._notifySubscribers(void 0, void 0), this._asyncRetryCount = 0, this._promiseId = (this._promiseId + 1) % j.MAX_PROMISE_ID;
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;
939
907
  const s = this._promiseId;
940
908
  t.then((e) => {
941
909
  if (s === this._promiseId) {
942
- if (this._isDirty()) {
943
- const i = nt();
944
- 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.`), c.COMPUTED_ASYNC_COMPUTATION_FAILED);
945
- }
910
+ if (this._isDirty()) return this._markDirty();
946
911
  this._finalizeResolution(e), this._notifySubscribers(e, void 0);
947
912
  }
948
913
  }, (e) => s === this._promiseId && this._handleError(e, c.COMPUTED_ASYNC_COMPUTATION_FAILED));
949
914
  }
950
915
  _handleError(t, s, e = !1) {
951
- const i = m(t, S, s);
952
- if (!e && !this.isRejected && (this.version = X(this.version)), this._error = i, this.flags = this.flags & ~(p | E | g | d) | D | O, this._onError) try {
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 {
953
918
  this._onError(i);
954
919
  } catch (r) {
955
920
  console.error(c.CALLBACK_ERROR_IN_ERROR_HANDLER, r);
@@ -959,18 +924,14 @@ var { IDLE: p, DIRTY: E, PENDING: g, RESOLVED: d, REJECTED: D, HAS_ERROR: O, REC
959
924
  }
960
925
  _finalizeResolution(t) {
961
926
  const s = this.flags;
962
- ((s & d) === 0 || !this._equal(this._value, t)) && (this.version = X(this.version)), this._value = t, this._error = null, this.flags = (s | d) & ~(p | E | g | D | O);
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);
963
928
  }
964
929
  execute() {
965
930
  this._markDirty();
966
931
  }
967
932
  _markDirty() {
968
933
  const t = this.flags;
969
- (t & (y | E)) === 0 && (this.flags = t | E, this._notifySubscribers(void 0, void 0));
970
- }
971
- _isDirty() {
972
- const t = this._deps;
973
- return t.hasComputeds ? this._deepDirtyCheck() : t.isDirtyFast();
934
+ (t & (N | E)) === 0 && (this.flags = t | E, this._notifySubscribers(void 0, void 0));
974
935
  }
975
936
  _deepDirtyCheck() {
976
937
  const t = this._deps, s = _.current;
@@ -981,7 +942,7 @@ var { IDLE: p, DIRTY: E, PENDING: g, RESOLVED: d, REJECTED: D, HAS_ERROR: O, REC
981
942
  const r = t.getAt(i);
982
943
  if (r == null) continue;
983
944
  const n = r.node;
984
- if ((n.flags & b) !== 0) try {
945
+ if ((n.flags & O) !== 0) try {
985
946
  n.value;
986
947
  } catch {
987
948
  }
@@ -994,12 +955,12 @@ var { IDLE: p, DIRTY: E, PENDING: g, RESOLVED: d, REJECTED: D, HAS_ERROR: O, REC
994
955
  }
995
956
  }
996
957
  };
997
- function Rt(t, s = {}) {
998
- return new gt(t, s);
958
+ function Ft(t, s = {}) {
959
+ return new Dt(t, s);
999
960
  }
1000
- var Tt = class extends Q {
961
+ var vt = class extends Q {
1001
962
  constructor(t, s = {}) {
1002
- super(), this[ot] = !0, this._cleanup = null, this._deps = new ut(), this._currentEpoch = T.UNINITIALIZED, this._lastFlushEpoch = T.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 = () => F.schedule(this), G.attachDebugInfo(this, "effect", this.id);
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);
1003
964
  }
1004
965
  run() {
1005
966
  if (this.isDisposed) throw new v(c.EFFECT_DISPOSED);
@@ -1042,7 +1003,7 @@ var Tt = class extends Q {
1042
1003
  const i = t.subscribe(this._notifyCallback);
1043
1004
  e = new z(t, t.version, i);
1044
1005
  } catch (i) {
1045
- const r = m(i, v, c.EFFECT_EXECUTION_FAILED);
1006
+ const r = g(i, v, c.EFFECT_EXECUTION_FAILED);
1046
1007
  if (console.error(r), this._onError) try {
1047
1008
  this._onError(r);
1048
1009
  } catch {
@@ -1056,11 +1017,11 @@ var Tt = class extends Q {
1056
1017
  if ((s & (I.DISPOSED | I.EXECUTING)) !== 0) return;
1057
1018
  const e = this._deps;
1058
1019
  if (!t && e.size > 0 && !this._isDirty()) return;
1059
- this._checkInfiniteLoops(), this.flags = s | I.EXECUTING, this._execCleanup(), this._currentEpoch = Y(), this._trackCount = 0, e.prepareTracking(), this._hotIndex = -1;
1020
+ this._checkInfiniteLoops(), this.flags = s | I.EXECUTING, this._execCleanup(), this._currentEpoch = k(), this._trackCount = 0, e.prepareTracking(), this._hotIndex = -1;
1060
1021
  let i = !1;
1061
1022
  try {
1062
1023
  const r = _.run(this, this._fn);
1063
- e.truncateFrom(this._trackCount), e.seal(), i = !0, ht(r) ? this._handleAsyncResult(r) : this._cleanup = typeof r == "function" ? r : null;
1024
+ e.truncateFrom(this._trackCount), i = !0, nt(r) ? this._handleAsyncResult(r) : this._cleanup = typeof r == "function" ? r : null;
1064
1025
  } catch (r) {
1065
1026
  if (!i) try {
1066
1027
  e.truncateFrom(this._trackCount);
@@ -1071,10 +1032,6 @@ var Tt = class extends Q {
1071
1032
  this.flags &= ~I.EXECUTING;
1072
1033
  }
1073
1034
  }
1074
- _isDirty() {
1075
- const t = this._deps;
1076
- return t.hasComputeds ? this._deepDirtyCheck() : t.isDirtyFast();
1077
- }
1078
1035
  _handleAsyncResult(t) {
1079
1036
  const s = ++this._execId;
1080
1037
  t.then((e) => {
@@ -1125,13 +1082,13 @@ var Tt = class extends Q {
1125
1082
  }
1126
1083
  }
1127
1084
  _checkInfiniteLoops() {
1128
- const t = nt();
1129
- this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), Ct() > C.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++;
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++;
1130
1087
  }
1131
1088
  _checkFrequencyLimit() {
1132
1089
  if (!Number.isFinite(this._maxExecutions)) return;
1133
1090
  const t = Date.now();
1134
- if (t - this._windowStart >= st.EFFECT_FREQUENCY_WINDOW) {
1091
+ if (t - this._windowStart >= Z.EFFECT_FREQUENCY_WINDOW) {
1135
1092
  this._windowStart = t, this._windowCount = 1;
1136
1093
  return;
1137
1094
  }
@@ -1147,51 +1104,99 @@ var Tt = class extends Q {
1147
1104
  return (this.flags & I.EXECUTING) !== 0;
1148
1105
  }
1149
1106
  _throwInfiniteLoopError(t) {
1150
- const s = new v(`Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${k}`);
1107
+ const s = new v(`Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${V}`);
1151
1108
  throw this.dispose(), console.error(s), s;
1152
1109
  }
1153
1110
  _handleExecutionError(t, s = c.EFFECT_EXECUTION_FAILED) {
1154
- const e = m(t, v, s);
1111
+ const e = g(t, v, s);
1155
1112
  if (console.error(e), this._onError) try {
1156
1113
  this._onError(e);
1157
1114
  } catch (i) {
1158
- console.error(m(i, v, c.CALLBACK_ERROR_IN_ERROR_HANDLER));
1115
+ console.error(g(i, v, c.CALLBACK_ERROR_IN_ERROR_HANDLER));
1159
1116
  }
1160
1117
  }
1161
1118
  };
1162
- function Ft(t, s = {}) {
1119
+ function Rt(t, s = {}) {
1163
1120
  if (typeof t != "function") throw new v(c.EFFECT_MUST_BE_FUNCTION);
1164
- const e = new Tt(t, s);
1121
+ const e = new vt(t, s);
1165
1122
  return e.execute(), e;
1166
1123
  }
1167
- function wt(t) {
1168
- if (typeof t != "function") throw new TypeError(c.BATCH_CALLBACK_MUST_BE_FUNCTION);
1169
- const s = F;
1170
- s.startBatch();
1171
- try {
1172
- return t();
1173
- } finally {
1174
- s.endBatch();
1175
- }
1124
+ var St = /* @__PURE__ */ Symbol.for("atom-effect/atom"), gt = /* @__PURE__ */ Symbol.for("atom-effect/writable");
1125
+ function rt(t, s, e, i) {
1126
+ if (e === s.length) return i;
1127
+ const r = s[e], n = t != null && typeof t == "object" ? t : {}, o = n[r], u = rt(o, s, e + 1, i);
1128
+ if (Object.is(o, u)) return t;
1129
+ if (Array.isArray(n)) {
1130
+ const l = n.slice(), h = Number.parseInt(r, 10);
1131
+ return Number.isNaN(h) ? l[r] = u : l[h] = u, l;
1132
+ }
1133
+ return {
1134
+ ...n,
1135
+ [r]: u
1136
+ };
1137
+ }
1138
+ function F(t, s) {
1139
+ let e = t;
1140
+ const i = s.length;
1141
+ for (let r = 0; r < i; r++) {
1142
+ if (e == null) return;
1143
+ e = e[s[r]];
1144
+ }
1145
+ return e;
1146
+ }
1147
+ function ot(t, s) {
1148
+ const e = s.includes(".") ? s.split(".") : [s], i = /* @__PURE__ */ new Set(), r = () => {
1149
+ i.forEach((n) => n()), i.clear();
1150
+ };
1151
+ return {
1152
+ get value() {
1153
+ return F(t.value, e);
1154
+ },
1155
+ set value(n) {
1156
+ const o = t.peek(), u = rt(o, e, 0, n);
1157
+ u !== o && (t.value = u);
1158
+ },
1159
+ peek: () => F(t.peek(), e),
1160
+ subscribe(n) {
1161
+ const o = t.subscribe((u, l) => {
1162
+ const h = F(u, e), f = F(l, e);
1163
+ Object.is(h, f) || n(h, f);
1164
+ });
1165
+ return i.add(o), () => {
1166
+ o(), i.delete(o);
1167
+ };
1168
+ },
1169
+ subscriberCount: () => i.size,
1170
+ dispose: r,
1171
+ [Symbol.dispose]: r,
1172
+ [St]: !0,
1173
+ [gt]: !0
1174
+ };
1176
1175
  }
1176
+ var wt = (t, s) => ot(t, s), Ut = (t) => (s) => ot(t, s);
1177
1177
  export {
1178
- A as AsyncState,
1179
- N as AtomError,
1180
- S as ComputedError,
1181
- st as DEBUG_CONFIG,
1178
+ y as AsyncState,
1179
+ T as AtomError,
1180
+ m as ComputedError,
1181
+ Z as DEBUG_CONFIG,
1182
1182
  G as DEBUG_RUNTIME,
1183
1183
  v as EffectError,
1184
1184
  C as SCHEDULER_CONFIG,
1185
- L as SchedulerError,
1186
- yt as atom,
1187
- wt as batch,
1188
- Rt as computed,
1189
- Ft as effect,
1190
- At as isAtom,
1191
- Ot as isComputed,
1192
- bt as isEffect,
1193
- F as scheduler,
1194
- Nt as untracked
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,
1197
+ w as scheduler,
1198
+ rt as setDeepValue,
1199
+ mt as untracked
1195
1200
  };
1196
1201
 
1197
1202
  //# sourceMappingURL=index.mjs.map