@but212/atom-effect 0.24.0 → 0.25.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,9 +1,9 @@
1
- var R = {
1
+ var b = {
2
2
  IDLE: "idle",
3
3
  PENDING: "pending",
4
4
  RESOLVED: "resolved",
5
5
  REJECTED: "rejected"
6
- }, _ = {
6
+ }, f = {
7
7
  DISPOSED: 1,
8
8
  EXECUTING: 8
9
9
  }, x = {
@@ -17,27 +17,27 @@ var R = {
17
17
  RECOMPUTING: 256,
18
18
  HAS_ERROR: 512,
19
19
  FORCE_COMPUTE: 1024
20
- }, a = {
20
+ }, d = {
21
21
  DISPOSED: 1,
22
22
  SYNC: 8,
23
23
  NOTIFICATION_SCHEDULED: 16
24
- }, C = {
24
+ }, m = {
25
25
  MAX_EXECUTIONS_PER_SECOND: 1e3,
26
26
  MAX_EXECUTIONS_PER_EFFECT: 100,
27
27
  MAX_EXECUTIONS_PER_FLUSH: 1e4,
28
28
  MAX_FLUSH_ITERATIONS: 1e3,
29
29
  MIN_FLUSH_ITERATIONS: 10,
30
30
  BATCH_QUEUE_SHRINK_THRESHOLD: 1e3
31
- }, J = {
31
+ }, st = {
32
32
  WARN_INFINITE_LOOP: !0,
33
33
  EFFECT_FREQUENCY_WINDOW: 1e3
34
- }, $ = {
34
+ }, j = {
35
35
  MAX_ASYNC_RETRIES: 3,
36
36
  MAX_PROMISE_ID: Number.MAX_SAFE_INTEGER - 1
37
- }, S = {
37
+ }, C = {
38
38
  UNINITIALIZED: -1,
39
39
  MIN: 1
40
- }, V = 1073741823, q = { VERSION_BITS: 16 }, Ct = (typeof process < "u" && process.env, !1), ht = Object.freeze([]), H = class {
40
+ }, G = 1073741823, q = { VERSION_BITS: 16 }, Ct = (typeof process < "u" && process.env, !1), W = Object.freeze([]), H = class {
41
41
  constructor(t, s, e = void 0) {
42
42
  this.node = t, this.version = s, this.unsub = e;
43
43
  }
@@ -52,19 +52,19 @@ var R = {
52
52
  constructor(t, s = null, e = !0) {
53
53
  super(t), this.cause = s, this.recoverable = e, this.name = "AtomError";
54
54
  }
55
- }, D = class extends A {
55
+ }, S = class extends A {
56
56
  constructor(t, s = null) {
57
57
  super(t, s, !0), this.name = "ComputedError";
58
58
  }
59
- }, I = class extends A {
59
+ }, D = class extends A {
60
60
  constructor(t, s = null) {
61
61
  super(t, s, !1), this.name = "EffectError";
62
62
  }
63
- }, b = class extends A {
63
+ }, R = class extends A {
64
64
  constructor(t, s = null) {
65
65
  super(t, s, !1), this.name = "SchedulerError";
66
66
  }
67
- }, u = {
67
+ }, l = {
68
68
  COMPUTED_MUST_BE_FUNCTION: "Computed target must be a function",
69
69
  COMPUTED_ASYNC_PENDING_NO_DEFAULT: "Async computation pending with no default value",
70
70
  COMPUTED_COMPUTATION_FAILED: "Computation execution failed",
@@ -83,55 +83,75 @@ var R = {
83
83
  SCHEDULER_CALLBACK_MUST_BE_FUNCTION: "Scheduler callback must be a function",
84
84
  SCHEDULER_END_BATCH_WITHOUT_START: "endBatch() called without matching startBatch(). Ignoring.",
85
85
  BATCH_CALLBACK_MUST_BE_FUNCTION: "Batch callback must be a function"
86
- }, tt = class {
86
+ }, et = class {
87
87
  constructor() {
88
- this._s0 = null, this._s1 = null, this._s2 = null, this._s3 = null, this._count = 0, this._epoch = S.UNINITIALIZED, this._overflow = null;
88
+ this._s0 = null, this._s1 = null, this._s2 = null, this._s3 = null, this._count = 0, this._overflow = null;
89
89
  }
90
90
  get size() {
91
91
  return this._count;
92
92
  }
93
93
  getAt(t) {
94
- if (t === 0) return this._s0;
95
- if (t === 1) return this._s1;
96
- if (t === 2) return this._s2;
97
- if (t === 3) return this._s3;
98
- const s = this._overflow;
99
- if (s !== null && t >= 4) {
100
- const e = t - 4;
101
- if (e < s.length) return s[e] || null;
94
+ switch (t) {
95
+ case 0:
96
+ return this._s0;
97
+ case 1:
98
+ return this._s1;
99
+ case 2:
100
+ return this._s2;
101
+ case 3:
102
+ return this._s3;
103
+ default: {
104
+ const s = this._overflow;
105
+ if (s !== null && t >= 4) {
106
+ const e = t - 4;
107
+ if (e < s.length) return s[e] ?? null;
108
+ }
109
+ return null;
110
+ }
102
111
  }
103
- return null;
104
112
  }
105
113
  setAt(t, s) {
106
- if (t === 0) this._s0 = s;
107
- else if (t === 1) this._s1 = s;
108
- else if (t === 2) this._s2 = s;
109
- else if (t === 3) this._s3 = s;
110
- else {
111
- this._overflow ??= [];
112
- const e = this._overflow;
113
- e[t - 4] = s;
114
+ switch (t) {
115
+ case 0:
116
+ this._s0 = s;
117
+ break;
118
+ case 1:
119
+ this._s1 = s;
120
+ break;
121
+ case 2:
122
+ this._s2 = s;
123
+ break;
124
+ case 3:
125
+ this._s3 = s;
126
+ break;
127
+ default: {
128
+ this._overflow ??= [];
129
+ const e = this._overflow;
130
+ e[t - 4] = s;
131
+ }
114
132
  }
115
133
  t >= this._count && (this._count = t + 1);
116
134
  }
117
135
  truncateFrom(t) {
118
136
  const s = this._count;
119
137
  if (t >= s) return;
120
- if (t <= 0) {
121
- const i = this._s0;
122
- i != null && (this._onItemRemoved(i), this._s0 = null);
123
- }
124
- if (t <= 1) {
125
- const i = this._s1;
126
- i != null && (this._onItemRemoved(i), this._s1 = null);
127
- }
128
- if (t <= 2) {
129
- const i = this._s2;
130
- i != null && (this._onItemRemoved(i), this._s2 = null);
131
- }
132
- if (t <= 3) {
133
- const i = this._s3;
134
- i != null && (this._onItemRemoved(i), this._s3 = null);
138
+ if (t <= 3) switch (t) {
139
+ case 0: {
140
+ const i = this._s0;
141
+ i != null && (this._onItemRemoved(i), this._s0 = null);
142
+ }
143
+ case 1: {
144
+ const i = this._s1;
145
+ i != null && (this._onItemRemoved(i), this._s1 = null);
146
+ }
147
+ case 2: {
148
+ const i = this._s2;
149
+ i != null && (this._onItemRemoved(i), this._s2 = null);
150
+ }
151
+ case 3: {
152
+ const i = this._s3;
153
+ i != null && (this._onItemRemoved(i), this._s3 = null);
154
+ }
135
155
  }
136
156
  const e = this._overflow;
137
157
  if (e !== null && s > 4) {
@@ -221,11 +241,11 @@ var R = {
221
241
  if (r != null && t(r), s <= 4) return;
222
242
  const o = this._overflow;
223
243
  if (o != null) {
224
- let l = 0;
225
- e != null && l++, i != null && l++, n != null && l++, r != null && l++;
226
- for (let h = 0, v = o.length; h < v; h++) {
227
- const m = o[h];
228
- if (m != null && (t(m), ++l === s))
244
+ let h = 0;
245
+ e != null && h++, i != null && h++, n != null && h++, r != null && h++;
246
+ for (let u = 0, a = o.length; u < a; u++) {
247
+ const c = o[u];
248
+ if (c != null && (t(c), ++h === s))
229
249
  return;
230
250
  }
231
251
  }
@@ -242,10 +262,10 @@ var R = {
242
262
  r != null && (t(r), e++);
243
263
  const o = this._s3;
244
264
  if (o != null && (t(o), e++), s <= 4 || e === s) return e;
245
- const l = this._overflow;
246
- if (l != null) for (let h = 0, v = l.length; h < v; h++) {
247
- const m = l[h];
248
- if (m != null && (t(m), ++e === s))
265
+ const h = this._overflow;
266
+ if (h != null) for (let u = 0, a = h.length; u < a; u++) {
267
+ const c = h[u];
268
+ if (c != null && (t(c), ++e === s))
249
269
  break;
250
270
  }
251
271
  return e;
@@ -266,30 +286,30 @@ var R = {
266
286
  dispose() {
267
287
  this.clear();
268
288
  }
269
- }, W = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), lt = /* @__PURE__ */ Symbol("AtomEffect.Id"), j = /* @__PURE__ */ Symbol("AtomEffect.Type"), U = /* @__PURE__ */ Symbol("AtomEffect.NoDefaultValue"), G = {
289
+ }, K = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), lt = /* @__PURE__ */ Symbol("AtomEffect.Id"), Z = /* @__PURE__ */ Symbol("AtomEffect.Type"), U = /* @__PURE__ */ Symbol("AtomEffect.NoDefaultValue"), X = {
270
290
  enabled: !1,
271
- warnInfiniteLoop: J.WARN_INFINITE_LOOP,
291
+ warnInfiniteLoop: st.WARN_INFINITE_LOOP,
272
292
  warn(t, s) {
273
293
  },
274
294
  attachDebugInfo(t, s, e) {
275
295
  },
276
- getDebugName: (t) => t?.[W],
277
- getDebugType: (t) => t?.[j]
278
- }, ct = 1, _t = () => ct++;
296
+ getDebugName: (t) => t?.[K],
297
+ getDebugType: (t) => t?.[Z]
298
+ }, _t = 1, ct = () => _t++;
279
299
  function T(t, s, e) {
280
300
  if (t instanceof A) return t;
281
301
  const i = t instanceof Error, n = i ? t.message : String(t), r = i ? t : void 0;
282
302
  return new s(`${i ? t.constructor.name : "Unexpected error"} (${e}): ${n}`, r);
283
303
  }
284
- var k = class {
304
+ var V = class {
285
305
  constructor() {
286
- this.flags = 0, this.version = 0, this._lastSeenEpoch = S.UNINITIALIZED, this.id = _t() & V, this._slots = null, this._notifying = 0, this._deps = null, this._hotIndex = -1;
306
+ this.flags = 0, this.version = 0, this._lastSeenEpoch = C.UNINITIALIZED, this._notifying = 0, this._hotIndex = -1, this._slots = null, this._deps = null, this.id = ct() & G;
287
307
  }
288
308
  subscribe(t) {
289
309
  const s = typeof t == "function";
290
- if (!s && (!t || typeof t.execute != "function")) throw T(/* @__PURE__ */ new TypeError("Invalid subscriber"), A, u.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
310
+ if (!s && (!t || typeof t.execute != "function")) throw T(/* @__PURE__ */ new TypeError("Invalid subscriber"), A, l.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
291
311
  let e = this._slots;
292
- e || (e = new tt(), this._slots = e);
312
+ e || (e = new et(), this._slots = e);
293
313
  let i = !1;
294
314
  if (e.forEach((r) => {
295
315
  (s ? r.fn === t : r.sub === t) && (i = !0);
@@ -320,7 +340,7 @@ var k = class {
320
340
  try {
321
341
  i.notify(t, s);
322
342
  } catch (n) {
323
- console.error(T(n, A, u.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED));
343
+ console.error(T(n, A, l.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED));
324
344
  }
325
345
  });
326
346
  } finally {
@@ -337,17 +357,17 @@ var k = class {
337
357
  }
338
358
  return !t.hasComputeds && !t.isDirtyFast() ? !1 : this._deepDirtyCheck();
339
359
  }
340
- }, w = 0, X = () => (w = w + 1 & 1073741823 || 1, w), z = (t) => t + 1 & V, Q = 0, F = !1, st = 0, et = () => st;
341
- function K() {
342
- return F ? !1 : (F = !0, st = X(), Q = 0, !0);
360
+ }, w = 0, Q = () => (w = w + 1 & 1073741823 || 1, w), z = (t) => t + 1 & G, Y = 0, F = !1, it = 0, nt = () => it;
361
+ function J() {
362
+ return F ? !1 : (F = !0, it = Q(), Y = 0, !0);
343
363
  }
344
- var Z = () => {
364
+ var tt = () => {
345
365
  F = !1;
346
- }, ft = () => F ? ++Q : 0, L = /* @__PURE__ */ (function(t) {
366
+ }, ft = () => F ? ++Y : 0, L = /* @__PURE__ */ (function(t) {
347
367
  return t[t.IDLE = 0] = "IDLE", t[t.BATCHING = 1] = "BATCHING", t[t.FLUSHING = 2] = "FLUSHING", t;
348
368
  })({}), at = class {
349
369
  constructor() {
350
- this._queueBuffer = [[], []], this._bufferIndex = 0, this._size = 0, this._epoch = 0, this._isProcessing = !1, this._isBatching = !1, this._isFlushingSync = !1, this._batchDepth = 0, this._batchQueue = [], this._batchQueueSize = 0, this._maxFlushIterations = C.MAX_FLUSH_ITERATIONS, this.onOverflow = null, this._boundRunLoop = this._runLoop.bind(this);
370
+ this._queueBuffer = [[], []], this._bufferIndex = 0, this._size = 0, this._epoch = 0, this._isProcessing = !1, this._isBatching = !1, this._isFlushingSync = !1, this._batchDepth = 0, this._batchQueue = [], this._batchQueueSize = 0, this._maxFlushIterations = m.MAX_FLUSH_ITERATIONS, this.onOverflow = null, this._boundRunLoop = this._runLoop.bind(this);
351
371
  }
352
372
  get phase() {
353
373
  return this._isProcessing || this._isFlushingSync ? L.FLUSHING : this._isBatching ? L.BATCHING : L.IDLE;
@@ -373,28 +393,30 @@ var Z = () => {
373
393
  _runLoop() {
374
394
  try {
375
395
  if (this._size === 0) return;
376
- const t = K();
377
- this._drainQueue(), t && Z();
396
+ const t = J();
397
+ this._drainQueue(), t && tt();
378
398
  } finally {
379
399
  this._isProcessing = !1, this._size > 0 && !this._isBatching && this._flush();
380
400
  }
381
401
  }
382
402
  _flushSync() {
383
403
  this._isFlushingSync = !0;
384
- const t = K();
404
+ const t = J();
385
405
  try {
386
406
  this._mergeBatchQueue(), this._drainQueue();
387
407
  } finally {
388
- this._isFlushingSync = !1, t && Z();
408
+ this._isFlushingSync = !1, t && tt();
389
409
  }
390
410
  }
391
411
  _mergeBatchQueue() {
392
412
  if (this._batchQueueSize === 0) return;
393
413
  const t = ++this._epoch, s = this._batchQueue, e = this._queueBuffer[this._bufferIndex];
394
414
  let i = this._size;
395
- s.slice(0, this._batchQueueSize).forEach((n) => {
396
- n._nextEpoch !== t && (n._nextEpoch = t, e[i++] = n);
397
- }), this._size = i, this._batchQueueSize = 0, s.length > C.BATCH_QUEUE_SHRINK_THRESHOLD && (s.length = 0);
415
+ for (let n = 0; n < this._batchQueueSize; n++) {
416
+ const r = s[n];
417
+ r._nextEpoch !== t && (r._nextEpoch = t, e[i++] = r);
418
+ }
419
+ this._size = i, this._batchQueueSize = 0, s.length = 0;
398
420
  }
399
421
  _drainQueue() {
400
422
  let t = 0;
@@ -413,13 +435,13 @@ var Z = () => {
413
435
  const n = s[i];
414
436
  typeof n == "function" ? n() : n.execute();
415
437
  } catch (n) {
416
- console.error(new b("Error occurred during scheduler execution", n));
438
+ console.error(new R("Error occurred during scheduler execution", n));
417
439
  }
418
440
  s.length = 0;
419
441
  }
420
442
  _handleFlushOverflow() {
421
443
  const t = this._size + this._batchQueueSize;
422
- if (console.error(new b(u.SCHEDULER_FLUSH_OVERFLOW(this._maxFlushIterations, t))), this._size = 0, this._queueBuffer[this._bufferIndex].length = 0, this._batchQueueSize = 0, this.onOverflow) try {
444
+ if (console.error(new R(l.SCHEDULER_FLUSH_OVERFLOW(this._maxFlushIterations, t))), this._size = 0, this._queueBuffer[this._bufferIndex].length = 0, this._batchQueueSize = 0, this.onOverflow) try {
423
445
  this.onOverflow(t);
424
446
  } catch {
425
447
  }
@@ -431,10 +453,10 @@ var Z = () => {
431
453
  this._batchDepth !== 0 && --this._batchDepth === 0 && (this._flushSync(), this._isBatching = !1);
432
454
  }
433
455
  setMaxFlushIterations(t) {
434
- if (t < C.MIN_FLUSH_ITERATIONS) throw new b(`Max flush iterations must be at least ${C.MIN_FLUSH_ITERATIONS}`);
456
+ if (t < m.MIN_FLUSH_ITERATIONS) throw new R(`Max flush iterations must be at least ${m.MIN_FLUSH_ITERATIONS}`);
435
457
  this._maxFlushIterations = t;
436
458
  }
437
- }, y = new at(), Y = /* @__PURE__ */ Symbol.for("atom-effect/atom"), it = /* @__PURE__ */ Symbol.for("atom-effect/computed"), nt = /* @__PURE__ */ Symbol.for("atom-effect/effect"), Et = /* @__PURE__ */ Symbol.for("atom-effect/writable"), c = {
459
+ }, y = new at(), $ = /* @__PURE__ */ Symbol.for("atom-effect/atom"), rt = /* @__PURE__ */ Symbol.for("atom-effect/computed"), ot = /* @__PURE__ */ Symbol.for("atom-effect/effect"), Et = /* @__PURE__ */ Symbol.for("atom-effect/writable"), _ = {
438
460
  current: null,
439
461
  run(t, s) {
440
462
  const e = this.current;
@@ -446,22 +468,22 @@ var Z = () => {
446
468
  }
447
469
  }
448
470
  };
449
- function St(t) {
450
- const s = c.current;
471
+ function vt(t) {
472
+ const s = _.current;
451
473
  if (s === null) return t();
452
- c.current = null;
474
+ _.current = null;
453
475
  try {
454
476
  return t();
455
477
  } finally {
456
- c.current = s;
478
+ _.current = s;
457
479
  }
458
480
  }
459
- var dt = class extends k {
481
+ var dt = class extends V {
460
482
  constructor(t, s) {
461
- super(), this._pendingOldValue = void 0, this[Y] = !0, this[Et] = !0, this._value = t, s && (this.flags |= a.SYNC), G.attachDebugInfo(this, "atom", this.id);
483
+ super(), this[$] = !0, this[Et] = !0, this._value = t, this._pendingOldValue = void 0, s && (this.flags |= d.SYNC), X.attachDebugInfo(this, "atom", this.id);
462
484
  }
463
485
  get value() {
464
- const t = c.current;
486
+ const t = _.current;
465
487
  return t?.addDependency(this), this._value;
466
488
  }
467
489
  set value(t) {
@@ -469,10 +491,10 @@ var dt = class extends k {
469
491
  if (Object.is(s, t)) return;
470
492
  this._value = t, this.version = z(this.version);
471
493
  const e = this._slots, i = this.flags;
472
- if (e == null || e.size === 0 || i & a.NOTIFICATION_SCHEDULED) return;
494
+ if (e == null || e.size === 0 || i & d.NOTIFICATION_SCHEDULED) return;
473
495
  this._pendingOldValue = s;
474
- const n = i | a.NOTIFICATION_SCHEDULED;
475
- if (this.flags = n, (n & a.SYNC) !== 0 && !y.isBatching) {
496
+ const n = i | d.NOTIFICATION_SCHEDULED;
497
+ if (this.flags = n, (n & d.SYNC) !== 0 && !y.isBatching) {
476
498
  this._flushNotifications();
477
499
  return;
478
500
  }
@@ -483,15 +505,15 @@ var dt = class extends k {
483
505
  }
484
506
  _flushNotifications() {
485
507
  const t = this.flags;
486
- if (!(t & a.NOTIFICATION_SCHEDULED) || t & a.DISPOSED) return;
508
+ if (!(t & d.NOTIFICATION_SCHEDULED) || t & d.DISPOSED) return;
487
509
  const s = this._pendingOldValue;
488
- this._pendingOldValue = void 0, this.flags &= ~a.NOTIFICATION_SCHEDULED, this._notifySubscribers(this._value, s);
510
+ this._pendingOldValue = void 0, this.flags &= ~d.NOTIFICATION_SCHEDULED, this._notifySubscribers(this._value, s);
489
511
  }
490
512
  peek() {
491
513
  return this._value;
492
514
  }
493
515
  dispose() {
494
- this.flags & a.DISPOSED || (this._slots?.clear(), this.flags |= a.DISPOSED, this._value = void 0, this._pendingOldValue = void 0);
516
+ this.flags & d.DISPOSED || (this._slots?.clear(), this.flags |= d.DISPOSED, this._value = void 0, this._pendingOldValue = void 0);
495
517
  }
496
518
  _deepDirtyCheck() {
497
519
  return !1;
@@ -500,10 +522,10 @@ var dt = class extends k {
500
522
  this.dispose();
501
523
  }
502
524
  };
503
- function vt(t, s = {}) {
525
+ function Dt(t, s = {}) {
504
526
  return new dt(t, s.sync ?? !1);
505
527
  }
506
- var rt = class extends tt {
528
+ var k = class extends et {
507
529
  constructor() {
508
530
  super(), this._map = null, this._SCAN_THRESHOLD = 32, this.hasComputeds = !1, this._depsHash = 0, this._map = null, this.hasComputeds = !1, this._depsHash = 0;
509
531
  }
@@ -519,33 +541,46 @@ var rt = class extends tt {
519
541
  if (s >= e) return !1;
520
542
  const i = e - s;
521
543
  if (this._map !== null || i > this._SCAN_THRESHOLD) return this._claimViaMap(t, s);
522
- if (s < 4) {
523
- if (s <= 0) {
544
+ if (s < 4) switch (s) {
545
+ case 0: {
524
546
  const o = this._s0;
525
547
  if (o && o.node === t && o.unsub)
526
548
  return o.version = t.version, !0;
527
549
  }
528
- if (s <= 1 && e > 1) {
529
- const o = this._s1;
530
- if (o && o.node === t && o.unsub)
531
- return o.version = t.version, s !== 1 && (this._s1 = this._s0, this._s0 = o), !0;
532
- }
533
- if (s <= 2 && e > 2) {
534
- const o = this._s2;
535
- if (o && o.node === t && o.unsub)
536
- return o.version = t.version, s !== 2 && this._swapInline(2, s, o), !0;
537
- }
538
- if (s <= 3 && e > 3) {
539
- const o = this._s3;
540
- if (o && o.node === t && o.unsub)
541
- return o.version = t.version, s !== 3 && this._swapInline(3, s, o), !0;
542
- }
550
+ case 1:
551
+ if (e > 1) {
552
+ const o = this._s1;
553
+ if (o && o.node === t && o.unsub)
554
+ return o.version = t.version, s !== 1 && (this._s1 = this._s0, this._s0 = o), !0;
555
+ }
556
+ case 2:
557
+ if (e > 2) {
558
+ const o = this._s2;
559
+ if (o && o.node === t && o.unsub) {
560
+ if (o.version = t.version, s !== 2) {
561
+ const h = s === 0 ? this._s0 : this._s1;
562
+ s === 0 ? this._s0 = o : this._s1 = o, this._s2 = h;
563
+ }
564
+ return !0;
565
+ }
566
+ }
567
+ case 3:
568
+ if (e > 3) {
569
+ const o = this._s3;
570
+ if (o && o.node === t && o.unsub) {
571
+ if (o.version = t.version, s !== 3) {
572
+ let h;
573
+ s === 0 ? (h = this._s0, this._s0 = o) : s === 1 ? (h = this._s1, this._s1 = o) : (h = this._s2, this._s2 = o), this._s3 = h;
574
+ }
575
+ return !0;
576
+ }
577
+ }
543
578
  }
544
579
  const n = s > 4 ? s : 4, r = this._overflow;
545
- if (r) for (let o = n - 4, l = r.length; o < l; o++) {
546
- const h = r[o];
547
- if (h && h.node === t && h.unsub)
548
- return h.version = t.version, this._swapGeneral(o + 4, s, h), !0;
580
+ if (r) for (let o = n - 4, h = r.length; o < h; o++) {
581
+ const u = r[o];
582
+ if (u && u.node === t && u.unsub)
583
+ return u.version = t.version, this._swapGeneral(o + 4, s, u), !0;
549
584
  }
550
585
  return !1;
551
586
  }
@@ -553,9 +588,14 @@ var rt = class extends tt {
553
588
  if (this._map === null) {
554
589
  this._map = /* @__PURE__ */ new Map();
555
590
  const n = this._count;
556
- for (let r = s; r < n; r++) {
557
- const o = this.getAt(r);
558
- o?.unsub && this._map.set(o.node, r);
591
+ s < 4 && (s <= 0 && this._s0?.unsub && this._map.set(this._s0.node, 0), s <= 1 && this._s1?.unsub && this._map.set(this._s1.node, 1), s <= 2 && this._s2?.unsub && this._map.set(this._s2.node, 2), s <= 3 && this._s3?.unsub && this._map.set(this._s3.node, 3));
592
+ const r = this._overflow;
593
+ if (r && n > 4) {
594
+ const o = s > 4 ? s : 4;
595
+ for (let h = o - 4, u = r.length; h < u; h++) {
596
+ const a = r[h];
597
+ a?.unsub && this._map.set(a.node, h + 4);
598
+ }
559
599
  }
560
600
  }
561
601
  const e = this._map.get(t);
@@ -575,7 +615,14 @@ var rt = class extends tt {
575
615
  _swapGeneral(t, s, e) {
576
616
  if (t === s) return;
577
617
  const i = this.getAt(s);
578
- this.setAt(s, e), this.setAt(t, i);
618
+ if (this.setAt(s, e), t === 0) this._s0 = i;
619
+ else if (t === 1) this._s1 = i;
620
+ else if (t === 2) this._s2 = i;
621
+ else if (t === 3) this._s3 = i;
622
+ else {
623
+ const n = this._overflow;
624
+ n[t - 4] = i;
625
+ }
579
626
  }
580
627
  insertNew(t, s) {
581
628
  const e = this._count;
@@ -583,101 +630,87 @@ var rt = class extends tt {
583
630
  const i = this.getAt(t);
584
631
  i != null && (this.add(i), this._map !== null && i.unsub && this._map.set(i.node, this._count - 1));
585
632
  }
586
- t === 0 ? this._s0 = s : t === 1 ? this._s1 = s : t === 2 ? this._s2 = s : t === 3 ? this._s3 = s : this.setAt(t, s), t >= e && (this._count = t + 1);
633
+ if (t === 0) this._s0 = s;
634
+ else if (t === 1) this._s1 = s;
635
+ else if (t === 2) this._s2 = s;
636
+ else if (t === 3) this._s3 = s;
637
+ else {
638
+ let i = this._overflow;
639
+ i || (i = [], this._overflow = i), i[t - 4] = s;
640
+ }
641
+ t >= e && (this._count = t + 1);
587
642
  }
588
643
  truncateFrom(t) {
589
644
  t >= this._count || (super.truncateFrom(t), this._map !== null && (this._map.clear(), this._map = null));
590
645
  }
591
646
  seal() {
592
- const t = this._count;
593
- if (t <= 0) {
594
- this._depsHash = 0;
595
- return;
596
- }
597
- let s = 0;
598
- const e = q.VERSION_BITS, i = this._s0;
599
- if (i && (s = s + (i.version << e) + i.node.id | 0), t > 1) {
600
- const n = this._s1;
601
- n && (s = s + (n.version << e) + n.node.id | 0);
602
- }
603
- if (t > 2) {
604
- const n = this._s2;
605
- n && (s = s + (n.version << e) + n.node.id | 0);
606
- }
607
- if (t > 3) {
608
- const n = this._s3;
609
- n && (s = s + (n.version << e) + n.node.id | 0);
610
- const r = this._overflow;
611
- if (r) for (let o = 0, l = r.length; o < l; o++) {
612
- const h = r[o];
613
- h && (s = s + (h.version << e) + h.node.id | 0);
647
+ const t = this._count, s = q.VERSION_BITS;
648
+ let e = 0;
649
+ switch (t) {
650
+ case 0:
651
+ this._depsHash = 0;
652
+ return;
653
+ case 1: {
654
+ const i = this._s0;
655
+ e = e + (i.version << s) + i.node.id | 0;
656
+ break;
657
+ }
658
+ case 2: {
659
+ const i = this._s0, n = this._s1;
660
+ e = e + (i.version << s) + i.node.id | 0, e = e + (n.version << s) + n.node.id | 0;
661
+ break;
662
+ }
663
+ case 3: {
664
+ const i = this._s0, n = this._s1, r = this._s2;
665
+ e = e + (i.version << s) + i.node.id | 0, e = e + (n.version << s) + n.node.id | 0, e = e + (r.version << s) + r.node.id | 0;
666
+ break;
667
+ }
668
+ default: {
669
+ const i = this._s0, n = this._s1, r = this._s2, o = this._s3;
670
+ if (e = e + (i.version << s) + i.node.id | 0, e = e + (n.version << s) + n.node.id | 0, e = e + (r.version << s) + r.node.id | 0, e = e + (o.version << s) + o.node.id | 0, t > 4) {
671
+ const h = this._overflow;
672
+ for (let u = 0, a = h.length; u < a; u++) {
673
+ const c = h[u];
674
+ e = e + (c.version << s) + c.node.id | 0;
675
+ }
676
+ }
614
677
  }
615
678
  }
616
- this._depsHash = s;
679
+ this._depsHash = e;
617
680
  }
618
681
  isDirtyFast() {
619
- const t = this._count;
620
- if (t <= 0) return !1;
621
- let s = 0;
622
- const e = q.VERSION_BITS, i = this._s0;
623
- if (i) {
624
- const n = i.node;
625
- s = s + (n.version << e) + n.id | 0;
626
- }
627
- if (t > 1) {
628
- const n = this._s1;
629
- if (n) {
630
- const r = n.node;
631
- s = s + (r.version << e) + r.id | 0;
682
+ const t = this._count, s = q.VERSION_BITS;
683
+ let e = 0;
684
+ switch (t) {
685
+ case 0:
686
+ return !1;
687
+ case 1: {
688
+ const i = this._s0.node;
689
+ e = e + (i.version << s) + i.id | 0;
690
+ break;
632
691
  }
633
- }
634
- if (t > 2) {
635
- const n = this._s2;
636
- if (n) {
637
- const r = n.node;
638
- s = s + (r.version << e) + r.id | 0;
692
+ case 2: {
693
+ const i = this._s0.node, n = this._s1.node;
694
+ e = e + (i.version << s) + i.id | 0, e = e + (n.version << s) + n.id | 0;
695
+ break;
639
696
  }
640
- }
641
- if (t > 3) {
642
- const n = this._s3;
643
- if (n) {
644
- const o = n.node;
645
- s = s + (o.version << e) + o.id | 0;
697
+ case 3: {
698
+ const i = this._s0.node, n = this._s1.node, r = this._s2.node;
699
+ e = e + (i.version << s) + i.id | 0, e = e + (n.version << s) + n.id | 0, e = e + (r.version << s) + r.id | 0;
700
+ break;
646
701
  }
647
- const r = this._overflow;
648
- if (r) for (let o = 0, l = r.length; o < l; o++) {
649
- const h = r[o];
650
- if (h) {
651
- const v = h.node;
652
- s = s + (v.version << e) + v.id | 0;
702
+ default: {
703
+ const i = this._s0.node, n = this._s1.node, r = this._s2.node, o = this._s3.node;
704
+ if (e = e + (i.version << s) + i.id | 0, e = e + (n.version << s) + n.id | 0, e = e + (r.version << s) + r.id | 0, e = e + (o.version << s) + o.id | 0, t > 4) {
705
+ const h = this._overflow;
706
+ for (let u = 0, a = h.length; u < a; u++) {
707
+ const c = h[u].node;
708
+ e = e + (c.version << s) + c.id | 0;
709
+ }
653
710
  }
654
711
  }
655
712
  }
656
- return s !== this._depsHash;
657
- }
658
- captureVersionSnapshot() {
659
- const t = this._count;
660
- if (t <= 0) return 0;
661
- let s = 0;
662
- const e = this._s0;
663
- if (e && (s = (s << 5) - s + e.node.version | 0), t > 1) {
664
- const i = this._s1;
665
- i && (s = (s << 5) - s + i.node.version | 0);
666
- }
667
- if (t > 2) {
668
- const i = this._s2;
669
- i && (s = (s << 5) - s + i.node.version | 0);
670
- }
671
- if (t > 3) {
672
- const i = this._s3;
673
- i && (s = (s << 5) - s + i.node.version | 0);
674
- const n = this._overflow;
675
- if (n) for (let r = 0, o = n.length; r < o; r++) {
676
- const l = n[r];
677
- l && (s = (s << 5) - s + l.node.version | 0);
678
- }
679
- }
680
- return s;
713
+ return e !== this._depsHash;
681
714
  }
682
715
  disposeAll() {
683
716
  this._count > 0 && this.truncateFrom(0), this.hasComputeds = !1, this._map !== null && (this._map.clear(), this._map = null);
@@ -688,46 +721,46 @@ var rt = class extends tt {
688
721
  compact() {
689
722
  }
690
723
  };
691
- function Dt(t) {
692
- return t !== null && typeof t == "object" && Y in t;
724
+ function St(t) {
725
+ return t !== null && typeof t == "object" && $ in t;
693
726
  }
694
727
  function gt(t) {
695
- return t !== null && typeof t == "object" && it in t;
728
+ return t !== null && typeof t == "object" && rt in t;
696
729
  }
697
- function Tt(t) {
698
- return t !== null && typeof t == "object" && nt in t;
730
+ function mt(t) {
731
+ return t !== null && typeof t == "object" && ot in t;
699
732
  }
700
- function ot(t) {
733
+ function ht(t) {
701
734
  return t !== null && typeof t == "object" && typeof t.then == "function";
702
735
  }
703
- var { IDLE: d, DIRTY: f, PENDING: g, RESOLVED: E, REJECTED: p, HAS_ERROR: N, RECOMPUTING: O, DISPOSED: M, IS_COMPUTED: P, FORCE_COMPUTE: B } = x, pt = class extends k {
736
+ var { IDLE: I, DIRTY: E, PENDING: g, RESOLVED: p, REJECTED: v, HAS_ERROR: N, RECOMPUTING: O, DISPOSED: M, IS_COMPUTED: P, FORCE_COMPUTE: B } = x, pt = class extends V {
704
737
  constructor(t, s = {}) {
705
- if (typeof t != "function") throw new D(u.COMPUTED_MUST_BE_FUNCTION);
706
- if (super(), this[Y] = !0, this[it] = !0, this._error = null, this._promiseId = 0, this._deps = new rt(), this._asyncStartAggregateVersion = 0, this._asyncRetryCount = 0, this._lastDriftEpoch = S.UNINITIALIZED, this._trackEpoch = S.UNINITIALIZED, this._trackCount = 0, this._value = void 0, this.flags = P | f | d, this._equal = s.equal ?? Object.is, this._fn = t, this._defaultValue = "defaultValue" in s ? s.defaultValue : U, this._onError = s.onError ?? null, this._maxAsyncRetries = (s.maxAsyncRetries ?? $.MAX_ASYNC_RETRIES) & V, G.attachDebugInfo(this, "computed", this.id), s.lazy === !1) try {
738
+ if (typeof t != "function") throw new S(l.COMPUTED_MUST_BE_FUNCTION);
739
+ if (super(), this[$] = !0, this[rt] = !0, this._error = null, this._promiseId = 0, this._deps = new k(), this._asyncRetryCount = 0, this._lastDriftEpoch = C.UNINITIALIZED, this._trackEpoch = C.UNINITIALIZED, this._trackCount = 0, this._value = void 0, this.flags = P | E | I, this._equal = s.equal ?? Object.is, this._fn = t, this._defaultValue = "defaultValue" in s ? s.defaultValue : U, this._onError = s.onError ?? null, this._maxAsyncRetries = (s.maxAsyncRetries ?? j.MAX_ASYNC_RETRIES) & G, X.attachDebugInfo(this, "computed", this.id), s.lazy === !1) try {
707
740
  this._recompute();
708
741
  } catch {
709
742
  }
710
743
  }
711
744
  _track() {
712
- c.current?.addDependency(this);
745
+ _.current?.addDependency(this);
713
746
  }
714
747
  get value() {
715
748
  this._track();
716
749
  const t = this.flags;
717
- if ((t & (E | f | d)) === E) return this._value;
718
- if (t & M) throw new D(u.COMPUTED_DISPOSED);
750
+ if ((t & (p | E | I)) === p) return this._value;
751
+ if (t & M) throw new S(l.COMPUTED_DISPOSED);
719
752
  if (t & O) {
720
753
  if (this._defaultValue !== U) return this._defaultValue;
721
- throw new D(u.COMPUTED_CIRCULAR_DEPENDENCY);
754
+ throw new S(l.COMPUTED_CIRCULAR_DEPENDENCY);
722
755
  }
723
- if (t & (f | d) && ((t & d) === 0 && (t & B) === 0 && this._deps.size > 0 && !this._isDirty() ? this.flags &= ~f : this._recompute(), this.flags & E))
756
+ if (t & (E | I) && ((t & I) === 0 && (t & B) === 0 && this._deps.size > 0 && !this._isDirty() ? this.flags &= ~E : this._recompute(), this.flags & p))
724
757
  return this._value;
725
758
  const s = this._defaultValue, e = s !== U;
726
759
  if (this.flags & g) {
727
760
  if (e) return s;
728
- throw new D(u.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
761
+ throw new S(l.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
729
762
  }
730
- if (this.flags & p) {
763
+ if (this.flags & v) {
731
764
  if (e) return s;
732
765
  throw this._error;
733
766
  }
@@ -739,11 +772,13 @@ var { IDLE: d, DIRTY: f, PENDING: g, RESOLVED: E, REJECTED: p, HAS_ERROR: N, REC
739
772
  get state() {
740
773
  this._track();
741
774
  const t = this.flags;
742
- return t & E ? R.RESOLVED : t & g ? R.PENDING : t & p ? R.REJECTED : R.IDLE;
775
+ return t & p ? b.RESOLVED : t & g ? b.PENDING : t & v ? b.REJECTED : b.IDLE;
743
776
  }
744
777
  get hasError() {
745
- if (this._track(), this.flags & (p | N)) return !0;
746
- const t = this._deps, s = t.size;
778
+ if (this._track(), this.flags & (v | N)) return !0;
779
+ const t = this._deps;
780
+ if (!t.hasComputeds) return !1;
781
+ const s = t.size;
747
782
  for (let e = 0; e < s; e++) {
748
783
  const i = t.getAt(e);
749
784
  if (i != null && i.node.flags & N) return !0;
@@ -757,14 +792,16 @@ var { IDLE: d, DIRTY: f, PENDING: g, RESOLVED: E, REJECTED: p, HAS_ERROR: N, REC
757
792
  this._track();
758
793
  const t = [];
759
794
  this._error && t.push(this._error);
760
- const s = this._deps, e = s.size;
795
+ const s = this._deps;
796
+ if (!s.hasComputeds) return t.length === 0 ? W : Object.freeze(t);
797
+ const e = s.size;
761
798
  for (let i = 0; i < e; i++) {
762
799
  const n = s.getAt(i);
763
800
  if (n == null) continue;
764
801
  const r = n.node;
765
802
  r.flags & N && this._collectErrorsFromDep(r, t);
766
803
  }
767
- return t.length === 0 ? ht : Object.freeze(t);
804
+ return t.length === 0 ? W : Object.freeze(t);
768
805
  }
769
806
  _collectErrorsFromDep(t, s) {
770
807
  const e = t.errors, i = e.length;
@@ -780,13 +817,13 @@ var { IDLE: d, DIRTY: f, PENDING: g, RESOLVED: E, REJECTED: p, HAS_ERROR: N, REC
780
817
  return this._track(), (this.flags & g) !== 0;
781
818
  }
782
819
  get isResolved() {
783
- return this._track(), (this.flags & E) !== 0;
820
+ return this._track(), (this.flags & p) !== 0;
784
821
  }
785
822
  invalidate() {
786
823
  this.flags |= B, this._markDirty();
787
824
  }
788
825
  dispose() {
789
- this.flags & M || (this._deps.disposeAll(), this._slots?.clear(), this.flags = M | f | d, this._error = null, this._value = void 0, this._hotIndex = -1);
826
+ this.flags & M || (this._deps.disposeAll(), this._slots?.clear(), this.flags = M | E | I, this._error = null, this._value = void 0, this._hotIndex = -1);
790
827
  }
791
828
  [Symbol.dispose]() {
792
829
  this.dispose();
@@ -804,59 +841,60 @@ var { IDLE: d, DIRTY: f, PENDING: g, RESOLVED: E, REJECTED: p, HAS_ERROR: N, REC
804
841
  }
805
842
  _recompute() {
806
843
  if (this.flags & O) return;
807
- this.flags = (this.flags | O) & ~B, this._trackEpoch = X(), this._trackCount = 0, this._deps.prepareTracking(), this._hotIndex = -1;
844
+ this.flags = (this.flags | O) & ~B, this._trackEpoch = Q(), this._trackCount = 0, this._deps.prepareTracking(), this._hotIndex = -1;
808
845
  let t = !1;
809
846
  try {
810
- const s = c.run(this, this._fn);
811
- this._deps.truncateFrom(this._trackCount), this._deps.seal(), t = !0, ot(s) ? this._handleAsyncComputation(s) : this._finalizeResolution(s);
847
+ const s = _.run(this, this._fn);
848
+ this._deps.truncateFrom(this._trackCount), this._deps.seal(), t = !0, ht(s) ? this._handleAsyncComputation(s) : this._finalizeResolution(s);
812
849
  } catch (s) {
813
850
  if (!t) try {
814
851
  this._deps.truncateFrom(this._trackCount);
815
852
  } catch {
816
853
  }
817
- this._handleError(s, u.COMPUTED_COMPUTATION_FAILED, !0);
854
+ this._handleError(s, l.COMPUTED_COMPUTATION_FAILED, !0);
818
855
  } finally {
819
- this._trackEpoch = S.UNINITIALIZED, this._trackCount = 0, this.flags &= ~O;
856
+ this._trackEpoch = C.UNINITIALIZED, this._trackCount = 0, this.flags &= ~O;
820
857
  }
821
858
  }
822
859
  _handleAsyncComputation(t) {
823
- this.flags = (this.flags | g) & ~(d | f | E | p), this._notifySubscribers(void 0, void 0), this._asyncStartAggregateVersion = this._captureVersionSnapshot(), this._asyncRetryCount = 0, this._promiseId = (this._promiseId + 1) % $.MAX_PROMISE_ID;
860
+ this.flags = (this.flags | g) & ~(I | E | p | v), this._notifySubscribers(void 0, void 0), this._asyncRetryCount = 0, this._promiseId = (this._promiseId + 1) % j.MAX_PROMISE_ID;
824
861
  const s = this._promiseId;
825
862
  t.then((e) => {
826
863
  if (s === this._promiseId) {
827
- if (this._captureVersionSnapshot() !== this._asyncStartAggregateVersion) {
828
- const i = et();
829
- return this._lastDriftEpoch !== i && (this._lastDriftEpoch = i, this._asyncRetryCount = 0), this._asyncRetryCount++ < this._maxAsyncRetries ? this._markDirty() : this._handleError(new D(`Async drift threshold exceeded after ${this._maxAsyncRetries} retries.`), u.COMPUTED_ASYNC_COMPUTATION_FAILED);
864
+ if (this._isDirty()) {
865
+ const i = nt();
866
+ 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.`), l.COMPUTED_ASYNC_COMPUTATION_FAILED);
830
867
  }
831
868
  this._finalizeResolution(e), this._notifySubscribers(e, void 0);
832
869
  }
833
- }, (e) => s === this._promiseId && this._handleError(e, u.COMPUTED_ASYNC_COMPUTATION_FAILED));
834
- }
835
- _captureVersionSnapshot() {
836
- return this._deps.captureVersionSnapshot();
870
+ }, (e) => s === this._promiseId && this._handleError(e, l.COMPUTED_ASYNC_COMPUTATION_FAILED));
837
871
  }
838
872
  _handleError(t, s, e = !1) {
839
- const i = T(t, D, s);
840
- if (!e && !(this.flags & p) && (this.version = z(this.version)), this._error = i, this.flags = this.flags & ~(d | f | g | E) | p | N, this._onError) try {
873
+ const i = T(t, S, s);
874
+ if (!e && !(this.flags & v) && (this.version = z(this.version)), this._error = i, this.flags = this.flags & ~(I | E | g | p) | v | N, this._onError) try {
841
875
  this._onError(i);
842
876
  } catch (n) {
843
- console.error(u.CALLBACK_ERROR_IN_ERROR_HANDLER, n);
877
+ console.error(l.CALLBACK_ERROR_IN_ERROR_HANDLER, n);
844
878
  }
845
879
  if (e) throw i;
846
880
  this._notifySubscribers(void 0, void 0);
847
881
  }
848
882
  _finalizeResolution(t) {
849
- (!(this.flags & E) || !this._equal(this._value, t)) && (this.version = z(this.version)), this._value = t, this._error = null, this.flags = (this.flags | E) & ~(d | f | g | p | N);
883
+ (!(this.flags & p) || !this._equal(this._value, t)) && (this.version = z(this.version)), this._value = t, this._error = null, this.flags = (this.flags | p) & ~(I | E | g | v | N);
850
884
  }
851
885
  execute() {
852
886
  this._markDirty();
853
887
  }
854
888
  _markDirty() {
855
- this.flags & (O | f) || (this.flags |= f, this._notifySubscribers(void 0, void 0));
889
+ this.flags & (O | E) || (this.flags |= E, this._notifySubscribers(void 0, void 0));
890
+ }
891
+ _isDirty() {
892
+ const t = this._deps;
893
+ return t.hasComputeds ? this._deepDirtyCheck() : t.isDirtyFast();
856
894
  }
857
895
  _deepDirtyCheck() {
858
- const t = this._deps, s = c.current;
859
- c.current = null;
896
+ const t = this._deps, s = _.current;
897
+ _.current = null;
860
898
  try {
861
899
  const e = t.size;
862
900
  for (let i = 0; i < e; i++) {
@@ -872,34 +910,35 @@ var { IDLE: d, DIRTY: f, PENDING: g, RESOLVED: E, REJECTED: p, HAS_ERROR: N, REC
872
910
  }
873
911
  return this._hotIndex = -1, !1;
874
912
  } finally {
875
- c.current = s;
913
+ _.current = s;
876
914
  }
877
915
  }
878
916
  };
879
- function At(t, s = {}) {
917
+ function Tt(t, s = {}) {
880
918
  return new pt(t, s);
881
919
  }
882
- var It = class extends k {
920
+ var It = class extends V {
883
921
  constructor(t, s = {}) {
884
- super(), this[nt] = !0, this._cleanup = null, this._deps = new rt(), this._currentEpoch = S.UNINITIALIZED, this._lastFlushEpoch = S.UNINITIALIZED, this._executionsInEpoch = 0, this._executionCount = 0, this._windowStart = 0, this._windowCount = 0, this._execId = 0, this._trackCount = 0, 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._sync ? this._notifyCallback = () => this.execute() : this._notifyCallback = () => y.schedule(this), G.attachDebugInfo(this, "effect", this.id);
922
+ super(), this[ot] = !0, this._cleanup = null, this._deps = new k(), this._currentEpoch = C.UNINITIALIZED, this._lastFlushEpoch = C.UNINITIALIZED, this._fn = t, this._onError = s.onError ?? null, this._sync = s.sync ?? !1, this._maxExecutions = s.maxExecutionsPerSecond ?? m.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = s.maxExecutionsPerFlush ?? m.MAX_EXECUTIONS_PER_EFFECT, this._cleanup = null, this._deps = new k(), this._currentEpoch = C.UNINITIALIZED, this._lastFlushEpoch = C.UNINITIALIZED, 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 = () => y.schedule(this), X.attachDebugInfo(this, "effect", this.id);
885
923
  }
886
924
  run() {
887
- if (this.flags & _.DISPOSED) throw new I(u.EFFECT_DISPOSED);
925
+ if (this.flags & f.DISPOSED) throw new D(l.EFFECT_DISPOSED);
888
926
  this.execute(!0);
889
927
  }
890
928
  dispose() {
891
- this.flags & _.DISPOSED || (this.flags |= _.DISPOSED, this._execCleanup(), this._deps?.disposeAll());
929
+ this.flags & f.DISPOSED || (this.flags |= f.DISPOSED, this._execCleanup(), this._deps?.disposeAll());
892
930
  }
893
931
  [Symbol.dispose]() {
894
932
  this.dispose();
895
933
  }
896
934
  addDependency(t) {
897
- if (!(this.flags & _.EXECUTING)) return;
935
+ if (!(this.flags & f.EXECUTING)) return;
898
936
  const s = this._currentEpoch;
899
937
  if (t._lastSeenEpoch === s) return;
900
938
  t._lastSeenEpoch = s;
901
- const e = this._trackCount, i = this._deps, n = i.getAt(e);
902
- n != null && n.node === t ? n.version = t.version : i.claimExisting(t, e) || this._insertNewDependency(t, e), t.flags & x.IS_COMPUTED && (i.hasComputeds = !0), this._trackCount = e + 1;
939
+ const e = this._trackCount, i = this._deps;
940
+ let n;
941
+ e === 0 ? n = i._s0 : e === 1 ? n = i._s1 : e === 2 ? n = i._s2 : e === 3 ? n = i._s3 : n = i.getAt(e), n != null && n.node === t ? n.version = t.version : i.claimExisting(t, e) || this._insertNewDependency(t, e), t.flags & x.IS_COMPUTED && (i.hasComputeds = !0), this._trackCount = e + 1;
903
942
  }
904
943
  _insertNewDependency(t, s) {
905
944
  let e;
@@ -907,7 +946,7 @@ var It = class extends k {
907
946
  const i = t.subscribe(this._notifyCallback);
908
947
  e = new H(t, t.version, i);
909
948
  } catch (i) {
910
- const n = T(i, I, u.EFFECT_EXECUTION_FAILED);
949
+ const n = T(i, D, l.EFFECT_EXECUTION_FAILED);
911
950
  if (console.error(n), this._onError) try {
912
951
  this._onError(n);
913
952
  } catch {
@@ -917,14 +956,14 @@ var It = class extends k {
917
956
  this._deps.insertNew(s, e);
918
957
  }
919
958
  execute(t = !1) {
920
- if (this.flags & (_.DISPOSED | _.EXECUTING)) return;
959
+ if (this.flags & (f.DISPOSED | f.EXECUTING)) return;
921
960
  const s = this._deps;
922
961
  if (!t && s.size > 0 && !this._isDirty()) return;
923
- this._checkInfiniteLoops(), this.flags |= _.EXECUTING, this._execCleanup(), this._currentEpoch = X(), this._trackCount = 0, s.prepareTracking(), this._hotIndex = -1;
962
+ this._checkInfiniteLoops(), this.flags |= f.EXECUTING, this._execCleanup(), this._currentEpoch = Q(), this._trackCount = 0, s.prepareTracking(), this._hotIndex = -1;
924
963
  let e = !1;
925
964
  try {
926
- const i = c.run(this, this._fn);
927
- s.truncateFrom(this._trackCount), s.seal(), e = !0, ot(i) ? this._handleAsyncResult(i) : this._cleanup = typeof i == "function" ? i : null;
965
+ const i = _.run(this, this._fn);
966
+ s.truncateFrom(this._trackCount), s.seal(), e = !0, ht(i) ? this._handleAsyncResult(i) : this._cleanup = typeof i == "function" ? i : null;
928
967
  } catch (i) {
929
968
  if (!e) try {
930
969
  s.truncateFrom(this._trackCount);
@@ -932,17 +971,21 @@ var It = class extends k {
932
971
  }
933
972
  this._handleExecutionError(i), this._cleanup = null;
934
973
  } finally {
935
- this.flags &= ~_.EXECUTING;
974
+ this.flags &= ~f.EXECUTING;
936
975
  }
937
976
  }
977
+ _isDirty() {
978
+ const t = this._deps;
979
+ return t.hasComputeds ? this._deepDirtyCheck() : t.isDirtyFast();
980
+ }
938
981
  _handleAsyncResult(t) {
939
982
  const s = ++this._execId;
940
983
  t.then((e) => {
941
- if (s !== this._execId || this.flags & _.DISPOSED) {
984
+ if (s !== this._execId || this.flags & f.DISPOSED) {
942
985
  if (typeof e == "function") try {
943
986
  e();
944
987
  } catch (i) {
945
- this._handleExecutionError(i, u.EFFECT_CLEANUP_FAILED);
988
+ this._handleExecutionError(i, l.EFFECT_CLEANUP_FAILED);
946
989
  }
947
990
  return;
948
991
  }
@@ -950,8 +993,8 @@ var It = class extends k {
950
993
  }, (e) => s === this._execId && this._handleExecutionError(e));
951
994
  }
952
995
  _deepDirtyCheck() {
953
- const t = c.current;
954
- c.current = null;
996
+ const t = _.current;
997
+ _.current = null;
955
998
  const s = this._deps;
956
999
  try {
957
1000
  const e = s.size;
@@ -964,7 +1007,7 @@ var It = class extends k {
964
1007
  }
965
1008
  return !1;
966
1009
  } finally {
967
- c.current = t;
1010
+ _.current = t;
968
1011
  }
969
1012
  }
970
1013
  _tryPullComputed(t) {
@@ -978,56 +1021,56 @@ var It = class extends k {
978
1021
  try {
979
1022
  this._cleanup();
980
1023
  } catch (t) {
981
- this._handleExecutionError(t, u.EFFECT_CLEANUP_FAILED);
1024
+ this._handleExecutionError(t, l.EFFECT_CLEANUP_FAILED);
982
1025
  }
983
1026
  this._cleanup = null;
984
1027
  }
985
1028
  }
986
1029
  _checkInfiniteLoops() {
987
- const t = et();
988
- this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), ft() > C.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++;
1030
+ const t = nt();
1031
+ this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), ft() > m.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++;
989
1032
  }
990
1033
  _checkFrequencyLimit() {
991
1034
  if (!Number.isFinite(this._maxExecutions)) return;
992
1035
  const t = Date.now();
993
- if (t - this._windowStart >= J.EFFECT_FREQUENCY_WINDOW) {
1036
+ if (t - this._windowStart >= st.EFFECT_FREQUENCY_WINDOW) {
994
1037
  this._windowStart = t, this._windowCount = 1;
995
1038
  return;
996
1039
  }
997
1040
  if (++this._windowCount > this._maxExecutions) {
998
- const s = new I(u.EFFECT_FREQUENCY_LIMIT_EXCEEDED);
1041
+ const s = new D(l.EFFECT_FREQUENCY_LIMIT_EXCEEDED);
999
1042
  throw this.dispose(), this._handleExecutionError(s), s;
1000
1043
  }
1001
1044
  }
1002
1045
  get isDisposed() {
1003
- return (this.flags & _.DISPOSED) !== 0;
1046
+ return (this.flags & f.DISPOSED) !== 0;
1004
1047
  }
1005
1048
  get executionCount() {
1006
1049
  return this._executionCount;
1007
1050
  }
1008
1051
  get isExecuting() {
1009
- return (this.flags & _.EXECUTING) !== 0;
1052
+ return (this.flags & f.EXECUTING) !== 0;
1010
1053
  }
1011
1054
  _throwInfiniteLoopError(t) {
1012
- const s = new I(`Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${Q}`);
1055
+ const s = new D(`Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${Y}`);
1013
1056
  throw this.dispose(), console.error(s), s;
1014
1057
  }
1015
- _handleExecutionError(t, s = u.EFFECT_EXECUTION_FAILED) {
1016
- const e = T(t, I, s);
1058
+ _handleExecutionError(t, s = l.EFFECT_EXECUTION_FAILED) {
1059
+ const e = T(t, D, s);
1017
1060
  if (console.error(e), this._onError) try {
1018
1061
  this._onError(e);
1019
1062
  } catch (i) {
1020
- console.error(T(i, I, u.CALLBACK_ERROR_IN_ERROR_HANDLER));
1063
+ console.error(T(i, D, l.CALLBACK_ERROR_IN_ERROR_HANDLER));
1021
1064
  }
1022
1065
  }
1023
1066
  };
1024
- function mt(t, s = {}) {
1025
- if (typeof t != "function") throw new I(u.EFFECT_MUST_BE_FUNCTION);
1067
+ function At(t, s = {}) {
1068
+ if (typeof t != "function") throw new D(l.EFFECT_MUST_BE_FUNCTION);
1026
1069
  const e = new It(t, s);
1027
1070
  return e.execute(), e;
1028
1071
  }
1029
1072
  function Nt(t) {
1030
- if (typeof t != "function") throw new TypeError(u.BATCH_CALLBACK_MUST_BE_FUNCTION);
1073
+ if (typeof t != "function") throw new TypeError(l.BATCH_CALLBACK_MUST_BE_FUNCTION);
1031
1074
  y.startBatch();
1032
1075
  try {
1033
1076
  return t();
@@ -1036,23 +1079,23 @@ function Nt(t) {
1036
1079
  }
1037
1080
  }
1038
1081
  export {
1039
- R as AsyncState,
1082
+ b as AsyncState,
1040
1083
  A as AtomError,
1041
- D as ComputedError,
1042
- J as DEBUG_CONFIG,
1043
- G as DEBUG_RUNTIME,
1044
- I as EffectError,
1045
- C as SCHEDULER_CONFIG,
1046
- b as SchedulerError,
1047
- vt as atom,
1084
+ S as ComputedError,
1085
+ st as DEBUG_CONFIG,
1086
+ X as DEBUG_RUNTIME,
1087
+ D as EffectError,
1088
+ m as SCHEDULER_CONFIG,
1089
+ R as SchedulerError,
1090
+ Dt as atom,
1048
1091
  Nt as batch,
1049
- At as computed,
1050
- mt as effect,
1051
- Dt as isAtom,
1092
+ Tt as computed,
1093
+ At as effect,
1094
+ St as isAtom,
1052
1095
  gt as isComputed,
1053
- Tt as isEffect,
1096
+ mt as isEffect,
1054
1097
  y as scheduler,
1055
- St as untracked
1098
+ vt as untracked
1056
1099
  };
1057
1100
 
1058
1101
  //# sourceMappingURL=index.mjs.map