@but212/atom-effect 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,14 +1,14 @@
1
- const R = {
1
+ const T = {
2
2
  IDLE: "idle",
3
3
  PENDING: "pending",
4
4
  RESOLVED: "resolved",
5
5
  REJECTED: "rejected"
6
- }, m = {
6
+ }, F = {
7
7
  DISPOSED: 1,
8
8
  // 0001 - Effect has been disposed
9
9
  EXECUTING: 2
10
10
  // 0010 - Effect is currently executing
11
- }, c = {
11
+ }, h = {
12
12
  DIRTY: 1,
13
13
  // 0001 - Needs recomputation
14
14
  IDLE: 2,
@@ -23,12 +23,12 @@ const R = {
23
23
  // 100000 - Currently recomputing
24
24
  HAS_ERROR: 64
25
25
  // 1000000 - Has error state
26
- }, W = {
26
+ }, ie = {
27
27
  /** Maximum number of pooled objects to prevent memory bloat */
28
28
  MAX_SIZE: 1e3,
29
29
  /** Number of objects to pre-allocate for performance-critical paths */
30
30
  WARMUP_SIZE: 100
31
- }, N = {
31
+ }, U = {
32
32
  /** Maximum effect executions per second to detect infinite loops (Legacy/Fallback) */
33
33
  MAX_EXECUTIONS_PER_SECOND: 100,
34
34
  /** Threshold for cleaning up old execution timestamps */
@@ -43,13 +43,13 @@ const R = {
43
43
  * Increased from 1000 to 5000 based on evaluation report
44
44
  */
45
45
  MAX_EXECUTIONS_PER_FLUSH: 5e3
46
- }, M = {
46
+ }, k = {
47
47
  /** Maximum dependencies before warning about large dependency graphs */
48
48
  MAX_DEPENDENCIES: 1e3,
49
49
  /** Enable infinite loop detection warnings */
50
50
  WARN_INFINITE_LOOP: !0
51
- }, I = 1073741823, U = typeof process < "u" && process.env && process.env.NODE_ENV !== "production";
52
- class _ extends Error {
51
+ }, N = 1073741823, w = typeof process < "u" && process.env && process.env.NODE_ENV !== "production";
52
+ class d extends Error {
53
53
  /**
54
54
  * Creates a new AtomError
55
55
  * @param message - Error message describing what went wrong
@@ -60,7 +60,7 @@ class _ extends Error {
60
60
  super(e), this.name = "AtomError", this.cause = t, this.recoverable = s, this.timestamp = /* @__PURE__ */ new Date();
61
61
  }
62
62
  }
63
- class b extends _ {
63
+ class D extends d {
64
64
  /**
65
65
  * Creates a new ComputedError
66
66
  * @param message - Error message
@@ -70,7 +70,7 @@ class b extends _ {
70
70
  super(e, t, !0), this.name = "ComputedError";
71
71
  }
72
72
  }
73
- class E extends _ {
73
+ class S extends d {
74
74
  /**
75
75
  * Creates a new EffectError
76
76
  * @param message - Error message
@@ -80,7 +80,7 @@ class E extends _ {
80
80
  super(e, t, !1), this.name = "EffectError";
81
81
  }
82
82
  }
83
- class y extends _ {
83
+ class C extends d {
84
84
  /**
85
85
  * Creates a new SchedulerError
86
86
  * @param message - Error message
@@ -90,20 +90,20 @@ class y extends _ {
90
90
  super(e, t, !1), this.name = "SchedulerError";
91
91
  }
92
92
  }
93
- function D(i, e, t) {
93
+ function R(i, e, t) {
94
94
  if (i instanceof TypeError)
95
95
  return new e(`Type error (${t}): ${i.message}`, i);
96
96
  if (i instanceof ReferenceError)
97
97
  return new e(`Reference error (${t}): ${i.message}`, i);
98
- if (i instanceof _)
98
+ if (i instanceof d)
99
99
  return i;
100
100
  const s = i instanceof Error ? i.message : String(i), n = i instanceof Error ? i : null;
101
101
  return new e(`Unexpected error (${t}): ${s}`, n);
102
102
  }
103
- function k(i) {
103
+ function X(i) {
104
104
  return i != null && typeof i.then == "function";
105
105
  }
106
- const h = {
106
+ const a = {
107
107
  // ─────────────────────────────────────────────────────────────────
108
108
  // Computed errors
109
109
  // ─────────────────────────────────────────────────────────────────
@@ -112,9 +112,9 @@ const h = {
112
112
  */
113
113
  COMPUTED_MUST_BE_FUNCTION: "Computed function must be a function",
114
114
  /**
115
- * Error thrown when subscribe() receives a non-function listener.
115
+ * Error thrown when subscribe() receives an invalid listener.
116
116
  */
117
- COMPUTED_SUBSCRIBER_MUST_BE_FUNCTION: "Subscriber listener must be a function",
117
+ COMPUTED_SUBSCRIBER_MUST_BE_FUNCTION: "Subscriber listener must be a function or Subscriber object",
118
118
  /**
119
119
  * Error thrown when accessing a pending async computed without a default value.
120
120
  */
@@ -135,9 +135,9 @@ const h = {
135
135
  // Atom errors
136
136
  // ─────────────────────────────────────────────────────────────────
137
137
  /**
138
- * Error thrown when atom.subscribe() receives a non-function listener.
138
+ * Error thrown when atom.subscribe() receives an invalid listener.
139
139
  */
140
- ATOM_SUBSCRIBER_MUST_BE_FUNCTION: "Subscription listener must be a function",
140
+ ATOM_SUBSCRIBER_MUST_BE_FUNCTION: "Subscription listener must be a function or Subscriber object",
141
141
  /**
142
142
  * Error thrown when the atom subscriber notification process fails.
143
143
  */
@@ -188,23 +188,23 @@ const h = {
188
188
  */
189
189
  CALLBACK_ERROR_IN_ERROR_HANDLER: "Error occurred during onError callback execution"
190
190
  };
191
- let A = 0;
192
- function q() {
193
- return A = (A + 1 | 0) & I, A;
191
+ let P = 0;
192
+ function G() {
193
+ return P = (P + 1 | 0) & N, P;
194
194
  }
195
- let C = 0, P = 0, T = !1;
196
- function w() {
197
- return T ? (U && console.warn(
195
+ let A = 0, v = 0, O = !1;
196
+ function q() {
197
+ return O ? (w && console.warn(
198
198
  "Warning: startFlush() called during flush - ignored to prevent infinite loop detection bypass"
199
- ), !1) : (T = !0, C = C + 1 & I, P = 0, !0);
199
+ ), !1) : (O = !0, A = A + 1 & N, v = 0, !0);
200
200
  }
201
- function v() {
202
- T = !1;
201
+ function z() {
202
+ O = !1;
203
203
  }
204
- function V() {
205
- return T ? ++P : 0;
204
+ function H() {
205
+ return O ? ++v : 0;
206
206
  }
207
- class X {
207
+ class J {
208
208
  constructor() {
209
209
  this.queueA = [], this.queueB = [], this.queue = this.queueA, this.queueSize = 0, this._epoch = 0, this.isProcessing = !1, this.isBatching = !1, this.batchDepth = 0, this.batchQueue = [], this.batchQueueSize = 0, this.isFlushingSync = !1, this.maxFlushIterations = 1e3;
210
210
  }
@@ -234,7 +234,7 @@ class X {
234
234
  */
235
235
  schedule(e) {
236
236
  if (typeof e != "function")
237
- throw new y("Scheduler callback must be a function");
237
+ throw new C("Scheduler callback must be a function");
238
238
  e._nextEpoch !== this._epoch && (e._nextEpoch = this._epoch, this.isBatching || this.isFlushingSync ? this.batchQueue[this.batchQueueSize++] = e : (this.queue[this.queueSize++] = e, this.isProcessing || this.flush()));
239
239
  }
240
240
  /**
@@ -254,16 +254,16 @@ class X {
254
254
  this.isProcessing = !0;
255
255
  const e = this.queue, t = this.queueSize;
256
256
  this.queue = this.queue === this.queueA ? this.queueB : this.queueA, this.queueSize = 0, this._epoch++, queueMicrotask(() => {
257
- const s = w();
257
+ const s = q();
258
258
  for (let n = 0; n < t; n++)
259
259
  try {
260
260
  e[n]?.();
261
261
  } catch (r) {
262
262
  console.error(
263
- new y("Error occurred during scheduler execution", r)
263
+ new C("Error occurred during scheduler execution", r)
264
264
  );
265
265
  }
266
- e.length = 0, this.isProcessing = !1, s && v(), this.queueSize > 0 && !this.isBatching && this.flush();
266
+ e.length = 0, this.isProcessing = !1, s && z(), this.queueSize > 0 && !this.isBatching && this.flush();
267
267
  });
268
268
  }
269
269
  /**
@@ -281,7 +281,7 @@ class X {
281
281
  */
282
282
  flushSync() {
283
283
  this.isFlushingSync = !0;
284
- const e = w();
284
+ const e = q();
285
285
  try {
286
286
  if (this._epoch++, this.batchQueueSize > 0) {
287
287
  for (let s = 0; s < this.batchQueueSize; s++) {
@@ -294,7 +294,7 @@ class X {
294
294
  for (; this.queueSize > 0; ) {
295
295
  if (++t > this.maxFlushIterations) {
296
296
  console.error(
297
- new y(
297
+ new C(
298
298
  `Maximum flush iterations (${this.maxFlushIterations}) exceeded. Possible infinite loop in reactive dependencies. Consider increasing the limit with scheduler.setMaxFlushIterations()`
299
299
  )
300
300
  ), this.queueSize = 0, this.queue.length = 0, this.batchQueueSize = 0;
@@ -305,9 +305,9 @@ class X {
305
305
  for (let r = 0; r < n; r++)
306
306
  try {
307
307
  s[r]?.();
308
- } catch (u) {
308
+ } catch (c) {
309
309
  console.error(
310
- new y("Error occurred during batch execution", u)
310
+ new C("Error occurred during batch execution", c)
311
311
  );
312
312
  }
313
313
  if (s.length = 0, this.batchQueueSize > 0) {
@@ -317,7 +317,7 @@ class X {
317
317
  }
318
318
  }
319
319
  } finally {
320
- this.isFlushingSync = !1, e && v();
320
+ this.isFlushingSync = !1, e && z();
321
321
  }
322
322
  }
323
323
  /**
@@ -381,24 +381,24 @@ class X {
381
381
  */
382
382
  setMaxFlushIterations(e) {
383
383
  if (e < 10)
384
- throw new y("Max flush iterations must be at least 10");
384
+ throw new C("Max flush iterations must be at least 10");
385
385
  this.maxFlushIterations = e;
386
386
  }
387
387
  }
388
- const g = new X();
389
- function K(i) {
388
+ const m = new J();
389
+ function ne(i) {
390
390
  if (typeof i != "function")
391
- throw new _("Batch callback must be a function");
392
- g.startBatch();
391
+ throw new d("Batch callback must be a function");
392
+ m.startBatch();
393
393
  try {
394
394
  return i();
395
395
  } catch (e) {
396
- throw new _("Error occurred during batch execution", e);
396
+ throw new d("Error occurred during batch execution", e);
397
397
  } finally {
398
- g.endBatch();
398
+ m.endBatch();
399
399
  }
400
400
  }
401
- const S = {
401
+ const y = {
402
402
  /** @inheritdoc */
403
403
  current: null,
404
404
  /**
@@ -419,24 +419,37 @@ const S = {
419
419
  return this.current;
420
420
  }
421
421
  };
422
- function Z(i) {
422
+ function re(i) {
423
423
  if (typeof i != "function")
424
- throw new _("Untracked callback must be a function");
425
- const e = S.current;
426
- S.current = null;
424
+ throw new d("Untracked callback must be a function");
425
+ const e = y.current;
426
+ y.current = null;
427
427
  try {
428
428
  return i();
429
429
  } catch (t) {
430
- throw new _("Error occurred during untracked execution", t);
430
+ throw new d("Error occurred during untracked execution", t);
431
431
  } finally {
432
- S.current = e;
432
+ y.current = e;
433
433
  }
434
434
  }
435
- const O = /* @__PURE__ */ Symbol("debugName"), j = /* @__PURE__ */ Symbol("id"), x = /* @__PURE__ */ Symbol("type"), B = /* @__PURE__ */ Symbol("noDefaultValue");
436
- function G(i) {
437
- return i !== null && typeof i == "object" && "dependencies" in i && i.dependencies instanceof Set;
435
+ const L = /* @__PURE__ */ Symbol("debugName"), W = /* @__PURE__ */ Symbol("id"), M = /* @__PURE__ */ Symbol("type"), j = /* @__PURE__ */ Symbol("noDefaultValue");
436
+ function K(i) {
437
+ return i !== null && typeof i == "object" && "dependencies" in i && Array.isArray(i.dependencies);
438
+ }
439
+ let V = 0;
440
+ function Y(i, e, t) {
441
+ const s = i;
442
+ if (s._visitedEpoch !== t) {
443
+ if (s._visitedEpoch = t, i === e)
444
+ throw new D("Indirect circular dependency detected");
445
+ if (K(i)) {
446
+ const n = i.dependencies;
447
+ for (let r = 0; r < n.length; r++)
448
+ Y(n[r], e, t);
449
+ }
450
+ }
438
451
  }
439
- const f = {
452
+ const b = {
440
453
  /**
441
454
  * Whether debug mode is enabled.
442
455
  *
@@ -450,13 +463,13 @@ const f = {
450
463
  *
451
464
  * @see {@link DEBUG_CONFIG.MAX_DEPENDENCIES}
452
465
  */
453
- maxDependencies: M.MAX_DEPENDENCIES,
466
+ maxDependencies: k.MAX_DEPENDENCIES,
454
467
  /**
455
468
  * Whether to warn about potential infinite loops.
456
469
  *
457
470
  * @see {@link DEBUG_CONFIG.WARN_INFINITE_LOOP}
458
471
  */
459
- warnInfiniteLoop: M.WARN_INFINITE_LOOP,
472
+ warnInfiniteLoop: k.WARN_INFINITE_LOOP,
460
473
  /**
461
474
  * Logs a warning message when condition is true and debug is enabled.
462
475
  *
@@ -499,16 +512,10 @@ const f = {
499
512
  * debug.checkCircular(computedC, computedA);
500
513
  * ```
501
514
  */
502
- checkCircular(i, e, t = /* @__PURE__ */ new Set()) {
515
+ checkCircular(i, e, t) {
503
516
  if (i === e)
504
- throw new b("Direct circular dependency detected");
505
- if (this.enabled) {
506
- if (t.has(i))
507
- throw new b("Indirect circular dependency detected");
508
- if (t.add(i), G(i))
509
- for (const s of i.dependencies)
510
- this.checkCircular(s, e, t);
511
- }
517
+ throw new D("Direct circular dependency detected");
518
+ this.enabled && (V++, Y(i, e, V));
512
519
  },
513
520
  /**
514
521
  * Attaches debug metadata to a reactive object.
@@ -534,7 +541,7 @@ const f = {
534
541
  if (!this.enabled)
535
542
  return;
536
543
  const s = i;
537
- s[O] = `${e}_${t}`, s[j] = t, s[x] = e;
544
+ s[L] = `${e}_${t}`, s[W] = t, s[M] = e;
538
545
  },
539
546
  /**
540
547
  * Retrieves the debug display name from a reactive object.
@@ -549,8 +556,8 @@ const f = {
549
556
  * ```
550
557
  */
551
558
  getDebugName(i) {
552
- if (i !== null && typeof i == "object" && O in i)
553
- return i[O];
559
+ if (i !== null && typeof i == "object" && L in i)
560
+ return i[L];
554
561
  },
555
562
  /**
556
563
  * Retrieves the debug type from a reactive object.
@@ -567,13 +574,13 @@ const f = {
567
574
  * ```
568
575
  */
569
576
  getDebugType(i) {
570
- if (i !== null && typeof i == "object" && x in i)
571
- return i[x];
577
+ if (i !== null && typeof i == "object" && M in i)
578
+ return i[M];
572
579
  }
573
580
  };
574
- let $ = 1;
575
- const L = () => $++;
576
- class F {
581
+ let Z = 1;
582
+ const B = () => Z++;
583
+ class x {
577
584
  constructor() {
578
585
  this.subscribers = null;
579
586
  }
@@ -706,7 +713,7 @@ class F {
706
713
  return this.subscribers ? [...this.subscribers] : [];
707
714
  }
708
715
  }
709
- class Y {
716
+ class ee {
710
717
  /**
711
718
  * Creates a new AtomImpl instance.
712
719
  *
@@ -714,7 +721,7 @@ class Y {
714
721
  * @param sync - Whether to notify subscribers synchronously
715
722
  */
716
723
  constructor(e, t) {
717
- this._isNotificationScheduled = !1, this.id = L() & I, this.version = 0, this.flags = 0, this._lastSeenEpoch = -1, this._value = e, this._functionSubscribers = new F(), this._objectSubscribers = new F(), this._sync = t, this._notifyTask = this._flushNotifications.bind(this), f.attachDebugInfo(this, "atom", this.id);
724
+ this._isNotificationScheduled = !1, this.id = B() & N, this.version = 0, this.flags = 0, this._lastSeenEpoch = -1, this._value = e, this._functionSubscribers = new x(), this._objectSubscribers = new x(), this._sync = t, this._notifyTask = this._flushNotifications.bind(this), b.attachDebugInfo(this, "atom", this.id);
718
725
  }
719
726
  /**
720
727
  * Gets the current value and registers the atom as a dependency
@@ -727,7 +734,7 @@ class Y {
727
734
  * a computed or effect context.
728
735
  */
729
736
  get value() {
730
- const e = S.getCurrent();
737
+ const e = y.getCurrent();
731
738
  return e != null && this._track(e), this._value;
732
739
  }
733
740
  /**
@@ -743,7 +750,7 @@ class Y {
743
750
  set value(e) {
744
751
  if (Object.is(this._value, e)) return;
745
752
  const t = this._value;
746
- this.version = this.version + 1 & I;
753
+ this.version = this.version + 1 & N;
747
754
  const s = this.version;
748
755
  this._value = e, !(!this._functionSubscribers.hasSubscribers && !this._objectSubscribers.hasSubscribers) && this._notify(e, t, s);
749
756
  }
@@ -783,7 +790,7 @@ class Y {
783
790
  * but don't schedule a new task. The pending task will see the latest value.
784
791
  */
785
792
  _notify(e, t, s) {
786
- this._isNotificationScheduled || (this._pendingOldValue = t, this._isNotificationScheduled = !0), this._sync && !g.isBatching ? this._flushNotifications() : g.schedule(this._notifyTask);
793
+ this._isNotificationScheduled || (this._pendingOldValue = t, this._isNotificationScheduled = !0), this._sync && !m.isBatching ? this._flushNotifications() : m.schedule(this._notifyTask);
787
794
  }
788
795
  /**
789
796
  * Executes the pending notifications.
@@ -794,18 +801,18 @@ class Y {
794
801
  const e = this._pendingOldValue, t = this._value;
795
802
  this._pendingOldValue = void 0, this._isNotificationScheduled = !1, this._functionSubscribers.forEachSafe(
796
803
  (s) => s(t, e),
797
- (s) => console.error(new _(h.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED, s))
804
+ (s) => console.error(new d(a.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED, s))
798
805
  ), this._objectSubscribers.forEachSafe(
799
806
  (s) => s.execute(),
800
- (s) => console.error(new _(h.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED, s))
807
+ (s) => console.error(new d(a.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED, s))
801
808
  );
802
809
  }
803
810
  /**
804
- * Subscribes a listener function to value changes.
811
+ * Subscribes a listener function or Subscriber object to value changes.
805
812
  *
806
- * @param listener - Function to call when the value changes
813
+ * @param listener - Function or Subscriber object to call when the value changes
807
814
  * @returns An unsubscribe function
808
- * @throws {AtomError} If listener is not a function
815
+ * @throws {AtomError} If listener is not a function or Subscriber
809
816
  *
810
817
  * @example
811
818
  * ```ts
@@ -816,8 +823,10 @@ class Y {
816
823
  * ```
817
824
  */
818
825
  subscribe(e) {
826
+ if (typeof e == "object" && e !== null && "execute" in e)
827
+ return this._objectSubscribers.add(e);
819
828
  if (typeof e != "function")
820
- throw new _(h.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
829
+ throw new d(a.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
821
830
  return this._functionSubscribers.add(e);
822
831
  }
823
832
  /**
@@ -851,40 +860,40 @@ class Y {
851
860
  return this._functionSubscribers.size + this._objectSubscribers.size;
852
861
  }
853
862
  }
854
- function ee(i, e = {}) {
855
- return new Y(i, e.sync ?? !1);
863
+ function ce(i, e = {}) {
864
+ return new ee(i, e.sync ?? !1);
856
865
  }
857
- const d = process.env.NODE_ENV !== "production", l = Object.freeze([]);
858
- class Q {
866
+ const p = process.env.NODE_ENV !== "production", f = Object.freeze([]), E = Object.freeze([]);
867
+ class $ {
859
868
  constructor() {
860
- this.pool = [], this.maxPoolSize = 50, this.maxReusableCapacity = 256, this.stats = d ? {
869
+ this.pool = [], this.maxPoolSize = 50, this.maxReusableCapacity = 256, this.stats = p ? {
861
870
  acquired: 0,
862
871
  released: 0,
863
872
  rejected: { frozen: 0, tooLarge: 0, poolFull: 0 }
864
873
  } : null;
865
874
  }
866
875
  acquire() {
867
- return d && this.stats && this.stats.acquired++, this.pool.pop() ?? [];
876
+ return p && this.stats && this.stats.acquired++, this.pool.pop() ?? [];
868
877
  }
869
878
  release(e, t) {
870
879
  if (!(t && e === t)) {
871
880
  if (Object.isFrozen(e)) {
872
- d && this.stats && this.stats.rejected.frozen++;
881
+ p && this.stats && this.stats.rejected.frozen++;
873
882
  return;
874
883
  }
875
884
  if (e.length > this.maxReusableCapacity) {
876
- d && this.stats && this.stats.rejected.tooLarge++;
885
+ p && this.stats && this.stats.rejected.tooLarge++;
877
886
  return;
878
887
  }
879
888
  if (this.pool.length >= this.maxPoolSize) {
880
- d && this.stats && this.stats.rejected.poolFull++;
889
+ p && this.stats && this.stats.rejected.poolFull++;
881
890
  return;
882
891
  }
883
- e.length = 0, this.pool.push(e), d && this.stats && this.stats.released++;
892
+ e.length = 0, this.pool.push(e), p && this.stats && this.stats.released++;
884
893
  }
885
894
  }
886
895
  getStats() {
887
- if (!d || !this.stats) return null;
896
+ if (!p || !this.stats) return null;
888
897
  const { acquired: e, released: t, rejected: s } = this.stats, n = s.frozen + s.tooLarge + s.poolFull;
889
898
  return {
890
899
  acquired: e,
@@ -895,15 +904,15 @@ class Q {
895
904
  };
896
905
  }
897
906
  reset() {
898
- this.pool.length = 0, d && this.stats && (this.stats.acquired = 0, this.stats.released = 0, this.stats.rejected = { frozen: 0, tooLarge: 0, poolFull: 0 });
907
+ this.pool.length = 0, p && this.stats && (this.stats.acquired = 0, this.stats.released = 0, this.stats.rejected = { frozen: 0, tooLarge: 0, poolFull: 0 });
899
908
  }
900
909
  }
901
- const p = new Q();
902
- class z {
910
+ const g = new $(), I = new $();
911
+ class Q {
903
912
  constructor(e, t = {}) {
904
913
  if (typeof e != "function")
905
- throw new b(h.COMPUTED_MUST_BE_FUNCTION);
906
- if (this.id = L() & I, this.version = 0, this.flags = 0, this._lastSeenEpoch = -1, this._value = void 0, this._stateFlags = c.DIRTY | c.IDLE, this._error = null, this._promiseId = 0, this._equal = t.equal ?? Object.is, this._fn = e, this._defaultValue = "defaultValue" in t ? t.defaultValue : B, this._hasDefaultValue = this._defaultValue !== B, this._onError = t.onError ?? null, this.MAX_PROMISE_ID = Number.MAX_SAFE_INTEGER - 1, this._functionSubscribers = new F(), this._objectSubscribers = new F(), this._dependencies = l, this._subscriptions = /* @__PURE__ */ new Map(), this._recomputeJob = () => {
914
+ throw new D(a.COMPUTED_MUST_BE_FUNCTION);
915
+ if (this.id = B() & N, this.version = 0, this.flags = 0, this._lastSeenEpoch = -1, this._value = void 0, this._stateFlags = h.DIRTY | h.IDLE, this._error = null, this._promiseId = 0, this._equal = t.equal ?? Object.is, this._fn = e, this._defaultValue = "defaultValue" in t ? t.defaultValue : j, this._hasDefaultValue = this._defaultValue !== j, this._onError = t.onError ?? null, this.MAX_PROMISE_ID = Number.MAX_SAFE_INTEGER - 1, this._functionSubscribers = new x(), this._objectSubscribers = new x(), this._dependencies = f, this._unsubscribes = E, this._recomputeJob = () => {
907
916
  if (this._isDirty())
908
917
  try {
909
918
  this._recompute();
@@ -920,7 +929,7 @@ class z {
920
929
  }, this._trackable = Object.assign(() => this._markDirty(), {
921
930
  addDependency: (s) => {
922
931
  }
923
- }), f.attachDebugInfo(this, "computed", this.id), f.enabled) {
932
+ }), b.attachDebugInfo(this, "computed", this.id), b.enabled) {
924
933
  const s = this;
925
934
  s.subscriberCount = () => this._functionSubscribers.size + this._objectSubscribers.size, s.isDirty = () => this._isDirty(), s.dependencies = this._dependencies, s.stateFlags = this._getFlagsAsString();
926
935
  }
@@ -932,14 +941,16 @@ class z {
932
941
  }
933
942
  // === PUBLIC API ===
934
943
  get value() {
935
- if ((this._stateFlags & (c.RESOLVED | c.DIRTY)) === c.RESOLVED)
944
+ if ((this._stateFlags & (h.RESOLVED | h.DIRTY)) === h.RESOLVED)
936
945
  return this._registerTracking(), this._value;
937
946
  const t = this._computeValue();
938
947
  return this._registerTracking(), t;
939
948
  }
940
949
  subscribe(e) {
950
+ if (typeof e == "object" && e !== null && "execute" in e)
951
+ return this._objectSubscribers.add(e);
941
952
  if (typeof e != "function")
942
- throw new b(h.COMPUTED_SUBSCRIBER_MUST_BE_FUNCTION);
953
+ throw new D(a.COMPUTED_SUBSCRIBER_MUST_BE_FUNCTION);
943
954
  return this._functionSubscribers.add(e);
944
955
  }
945
956
  peek() {
@@ -964,58 +975,58 @@ class z {
964
975
  this._markDirty();
965
976
  }
966
977
  dispose() {
967
- if (this._dependencies !== l) {
968
- for (const e of this._dependencies) {
969
- const t = this._subscriptions.get(e.id);
970
- t && t(), this._subscriptions.delete(e.id);
978
+ if (this._unsubscribes !== E) {
979
+ for (let e = 0; e < this._unsubscribes.length; e++) {
980
+ const t = this._unsubscribes[e];
981
+ t && t();
971
982
  }
972
- p.release(this._dependencies);
983
+ I.release(this._unsubscribes), this._unsubscribes = E;
973
984
  }
974
- this._dependencies = l, this._functionSubscribers.clear(), this._objectSubscribers.clear(), this._stateFlags = c.DIRTY | c.IDLE, this._error = null, this._value = void 0, this._promiseId = (this._promiseId + 1) % this.MAX_PROMISE_ID;
985
+ this._dependencies !== f && (g.release(this._dependencies), this._dependencies = f), this._functionSubscribers.clear(), this._objectSubscribers.clear(), this._stateFlags = h.DIRTY | h.IDLE, this._error = null, this._value = void 0, this._promiseId = (this._promiseId + 1) % this.MAX_PROMISE_ID;
975
986
  }
976
987
  // === PRIVATE: State Flag Operations (inlined for performance) ===
977
988
  _isDirty() {
978
- return (this._stateFlags & c.DIRTY) !== 0;
989
+ return (this._stateFlags & h.DIRTY) !== 0;
979
990
  }
980
991
  _setDirty() {
981
- this._stateFlags |= c.DIRTY;
992
+ this._stateFlags |= h.DIRTY;
982
993
  }
983
994
  _clearDirty() {
984
995
  this._stateFlags &= -2;
985
996
  }
986
997
  _isIdle() {
987
- return (this._stateFlags & c.IDLE) !== 0;
998
+ return (this._stateFlags & h.IDLE) !== 0;
988
999
  }
989
1000
  _setIdle() {
990
- this._stateFlags |= c.IDLE, this._stateFlags &= -29;
1001
+ this._stateFlags |= h.IDLE, this._stateFlags &= -29;
991
1002
  }
992
1003
  _isPending() {
993
- return (this._stateFlags & c.PENDING) !== 0;
1004
+ return (this._stateFlags & h.PENDING) !== 0;
994
1005
  }
995
1006
  _setPending() {
996
- this._stateFlags |= c.PENDING, this._stateFlags &= -27;
1007
+ this._stateFlags |= h.PENDING, this._stateFlags &= -27;
997
1008
  }
998
1009
  _isResolved() {
999
- return (this._stateFlags & c.RESOLVED) !== 0;
1010
+ return (this._stateFlags & h.RESOLVED) !== 0;
1000
1011
  }
1001
1012
  _setResolved() {
1002
- this._stateFlags |= c.RESOLVED, this._stateFlags &= -87;
1013
+ this._stateFlags |= h.RESOLVED, this._stateFlags &= -87;
1003
1014
  }
1004
1015
  _isRejected() {
1005
- return (this._stateFlags & c.REJECTED) !== 0;
1016
+ return (this._stateFlags & h.REJECTED) !== 0;
1006
1017
  }
1007
1018
  _setRejected() {
1008
- this._stateFlags |= c.REJECTED | c.HAS_ERROR, this._stateFlags &= -15;
1019
+ this._stateFlags |= h.REJECTED | h.HAS_ERROR, this._stateFlags &= -15;
1009
1020
  }
1010
1021
  _isRecomputing() {
1011
- return (this._stateFlags & c.RECOMPUTING) !== 0;
1022
+ return (this._stateFlags & h.RECOMPUTING) !== 0;
1012
1023
  }
1013
1024
  _setRecomputing(e) {
1014
- const t = c.RECOMPUTING;
1025
+ const t = h.RECOMPUTING;
1015
1026
  this._stateFlags = this._stateFlags & ~t | -Number(e) & t;
1016
1027
  }
1017
1028
  _getAsyncState() {
1018
- return this._isPending() ? R.PENDING : this._isResolved() ? R.RESOLVED : this._isRejected() ? R.REJECTED : R.IDLE;
1029
+ return this._isPending() ? T.PENDING : this._isResolved() ? T.RESOLVED : this._isRejected() ? T.REJECTED : T.IDLE;
1019
1030
  }
1020
1031
  _getFlagsAsString() {
1021
1032
  const e = [];
@@ -1029,47 +1040,52 @@ class z {
1029
1040
  if (!this._isDirty() && this._isResolved())
1030
1041
  return;
1031
1042
  this._setRecomputing(!0);
1032
- const e = this._dependencies, t = p.acquire(), s = q();
1043
+ const e = this._dependencies, t = g.acquire(), s = G();
1033
1044
  let n = 0;
1034
- const r = (o) => {
1035
- o._lastSeenEpoch !== s && (o._lastSeenEpoch = s, n < t.length ? t[n] = o : t.push(o), n++);
1036
- }, u = this._trackable.addDependency;
1045
+ const r = (_) => {
1046
+ _._lastSeenEpoch !== s && (_._lastSeenEpoch = s, n < t.length ? t[n] = _ : t.push(_), n++);
1047
+ }, c = this._trackable.addDependency;
1037
1048
  this._trackable.addDependency = r;
1038
- let a = !1;
1049
+ let o = !1;
1039
1050
  try {
1040
- const o = S.run(this._trackable, this._fn);
1041
- if (t.length = n, k(o)) {
1042
- this._syncDependencies(e, t, s), this._dependencies = t, a = !0, this._handleAsyncComputation(o), this._setRecomputing(!1);
1051
+ const _ = y.run(this._trackable, this._fn);
1052
+ if (t.length = n, X(_)) {
1053
+ this._syncDependencies(e, t, this._unsubscribes, s), this._dependencies = t, o = !0, this._handleAsyncComputation(_), this._setRecomputing(!1);
1043
1054
  return;
1044
1055
  }
1045
- this._syncDependencies(e, t, s), this._dependencies = t, a = !0, this._handleSyncResult(o);
1046
- } catch (o) {
1047
- t.length = n, this._syncDependencies(e, t, s), this._dependencies = t, a = !0, this._handleComputationError(o);
1056
+ this._syncDependencies(e, t, this._unsubscribes, s), this._dependencies = t, o = !0, this._handleSyncResult(_);
1057
+ } catch (_) {
1058
+ t.length = n, this._syncDependencies(e, t, this._unsubscribes, s), this._dependencies = t, this._handleComputationError(_);
1048
1059
  } finally {
1049
- this._trackable.addDependency = u, a ? e !== l && p.release(e) : p.release(t);
1060
+ this._trackable.addDependency = c, o ? e !== f && g.release(e) : g.release(t);
1050
1061
  }
1051
1062
  }
1052
1063
  /**
1053
1064
  * Synchronizes subscriptions based on dependency changes.
1054
1065
  * O(N) Diff using Epoch.
1055
1066
  */
1056
- _syncDependencies(e, t, s) {
1057
- if (e !== l)
1058
- for (let n = 0; n < e.length; n++) {
1059
- const r = e[n];
1060
- if (r && r._lastSeenEpoch !== s) {
1061
- const u = this._subscriptions.get(r.id);
1062
- u && (u(), this._subscriptions.delete(r.id));
1063
- }
1064
- }
1065
- for (let n = 0; n < t.length; n++) {
1066
- const r = t[n];
1067
- if (r && !this._subscriptions.has(r.id)) {
1068
- f.checkCircular(r, this);
1069
- const u = r.subscribe(() => this._markDirty());
1070
- this._subscriptions.set(r.id, u);
1067
+ /**
1068
+ * Synchronizes subscriptions based on dependency changes using O(N) strategy.
1069
+ * Maps unsubs 1:1 with dependencies array.
1070
+ */
1071
+ _syncDependencies(e, t, s, n) {
1072
+ if (e !== f && s !== E)
1073
+ for (let c = 0; c < e.length; c++) {
1074
+ const o = e[c];
1075
+ o && (o._tempUnsub = s[c]);
1071
1076
  }
1077
+ const r = I.acquire();
1078
+ r.length = t.length;
1079
+ for (let c = 0; c < t.length; c++) {
1080
+ const o = t[c];
1081
+ o && (o._tempUnsub ? (r[c] = o._tempUnsub, o._tempUnsub = void 0) : (b.checkCircular(o, this), r[c] = o.subscribe(this)));
1072
1082
  }
1083
+ if (e !== f)
1084
+ for (let c = 0; c < e.length; c++) {
1085
+ const o = e[c];
1086
+ o?._tempUnsub && (o._tempUnsub(), o._tempUnsub = void 0);
1087
+ }
1088
+ s !== E && I.release(s), this._unsubscribes = r;
1073
1089
  }
1074
1090
  _handleSyncResult(e) {
1075
1091
  const t = !this._isResolved() || !this._equal(this._value, e);
@@ -1089,29 +1105,29 @@ class z {
1089
1105
  this._value = e, this._clearDirty(), this._setResolved(), this._error = null, this._setRecomputing(!1), t && this._notifySubscribers();
1090
1106
  }
1091
1107
  _handleAsyncRejection(e) {
1092
- const t = D(e, b, h.COMPUTED_ASYNC_COMPUTATION_FAILED);
1108
+ const t = R(e, D, a.COMPUTED_ASYNC_COMPUTATION_FAILED);
1093
1109
  if (this._error = t, this._setRejected(), this._clearDirty(), this._setRecomputing(!1), this._onError && typeof this._onError == "function")
1094
1110
  try {
1095
1111
  this._onError(t);
1096
1112
  } catch (s) {
1097
- console.error(h.CALLBACK_ERROR_IN_ERROR_HANDLER, s);
1113
+ console.error(a.CALLBACK_ERROR_IN_ERROR_HANDLER, s);
1098
1114
  }
1099
1115
  this._notifySubscribers();
1100
1116
  }
1101
1117
  _handleComputationError(e) {
1102
- const t = D(e, b, h.COMPUTED_COMPUTATION_FAILED);
1118
+ const t = R(e, D, a.COMPUTED_COMPUTATION_FAILED);
1103
1119
  if (this._error = t, this._setRejected(), this._clearDirty(), this._setRecomputing(!1), this._onError && typeof this._onError == "function")
1104
1120
  try {
1105
1121
  this._onError(t);
1106
1122
  } catch (s) {
1107
- console.error(h.CALLBACK_ERROR_IN_ERROR_HANDLER, s);
1123
+ console.error(a.CALLBACK_ERROR_IN_ERROR_HANDLER, s);
1108
1124
  }
1109
1125
  throw t;
1110
1126
  }
1111
1127
  _handlePending() {
1112
1128
  if (this._hasDefaultValue)
1113
1129
  return this._defaultValue;
1114
- throw new b(h.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
1130
+ throw new D(a.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
1115
1131
  }
1116
1132
  _handleRejected() {
1117
1133
  if (this._error?.recoverable && this._hasDefaultValue)
@@ -1121,14 +1137,21 @@ class z {
1121
1137
  // === PRIVATE: Dependency Management ===
1122
1138
  // (Replaced by _syncDependencies and inline pool logic)
1123
1139
  // === PRIVATE: Subscriber Management ===
1140
+ /**
1141
+ * Subscriber interface implementation (Zero-Allocation pattern)
1142
+ * Called by dependencies when they change - delegates to _markDirty
1143
+ */
1144
+ execute() {
1145
+ this._markDirty();
1146
+ }
1124
1147
  _markDirty() {
1125
- this._isRecomputing() || this._isDirty() || (this._setDirty(), this._setIdle(), (this._functionSubscribers.hasSubscribers || this._objectSubscribers.hasSubscribers) && g.schedule(this._recomputeJob));
1148
+ this._isRecomputing() || this._isDirty() || (this._setDirty(), this._setIdle(), (this._functionSubscribers.hasSubscribers || this._objectSubscribers.hasSubscribers) && m.schedule(this._recomputeJob));
1126
1149
  }
1127
1150
  _notifySubscribers() {
1128
- !this._functionSubscribers.hasSubscribers && !this._objectSubscribers.hasSubscribers || g.schedule(this._notifyJob);
1151
+ !this._functionSubscribers.hasSubscribers && !this._objectSubscribers.hasSubscribers || m.schedule(this._notifyJob);
1129
1152
  }
1130
1153
  _registerTracking() {
1131
- const e = S.getCurrent();
1154
+ const e = y.getCurrent();
1132
1155
  if (e)
1133
1156
  if (typeof e == "object" && e !== null && e.addDependency)
1134
1157
  e.addDependency(this);
@@ -1138,49 +1161,75 @@ class z {
1138
1161
  } else e.execute && this._objectSubscribers.add(e);
1139
1162
  }
1140
1163
  }
1141
- Object.freeze(z.prototype);
1142
- function te(i, e = {}) {
1143
- return new z(i, e);
1164
+ Object.freeze(Q.prototype);
1165
+ function ue(i, e = {}) {
1166
+ return new Q(i, e);
1144
1167
  }
1145
- class H {
1168
+ class te {
1146
1169
  constructor(e, t = {}) {
1147
1170
  this.run = () => {
1148
1171
  if (this.isDisposed)
1149
- throw new E(h.EFFECT_MUST_BE_FUNCTION);
1172
+ throw new S(a.EFFECT_MUST_BE_FUNCTION);
1150
1173
  this.execute();
1151
1174
  }, this.dispose = () => {
1152
- if (!this.isDisposed && (this._setDisposed(), this._safeCleanup(), this._dependencies !== l)) {
1153
- for (const s of this._dependencies) {
1154
- const n = this._subscriptions.get(s.id);
1155
- n && n(), this._subscriptions.delete(s.id);
1175
+ if (!this.isDisposed) {
1176
+ if (this._setDisposed(), this._safeCleanup(), this._unsubscribes !== E) {
1177
+ for (let s = 0; s < this._unsubscribes.length; s++) {
1178
+ const n = this._unsubscribes[s];
1179
+ n && n();
1180
+ }
1181
+ I.release(this._unsubscribes), this._unsubscribes = E;
1156
1182
  }
1157
- p.release(this._dependencies), this._dependencies = l;
1183
+ this._dependencies !== f && (g.release(this._dependencies), this._dependencies = f);
1158
1184
  }
1159
1185
  }, this.addDependency = (s) => {
1160
- if (this.isExecuting && this._nextDeps) {
1186
+ if (this.isExecuting && this._nextDeps && this._nextUnsubs) {
1161
1187
  const n = s, r = this._currentEpoch;
1162
1188
  if (n._lastSeenEpoch === r) return;
1163
- n._lastSeenEpoch = r, this._nextDeps.push(n), this._subscriptions.has(n.id) || this._subscribeTo(n);
1189
+ n._lastSeenEpoch = r, this._nextDeps.push(n), n._tempUnsub ? (this._nextUnsubs.push(n._tempUnsub), n._tempUnsub = void 0) : this._subscribeTo(n);
1164
1190
  }
1165
1191
  }, this.execute = () => {
1166
1192
  if (this.isDisposed || this.isExecuting) return;
1167
- this._checkInfiniteLoop(), this._setExecuting(!0), this._safeCleanup(), this._modifiedDeps.clear();
1168
- const s = this._dependencies, n = p.acquire(), r = q();
1169
- this._nextDeps = n, this._currentEpoch = r;
1170
- let u = !1;
1193
+ this._checkInfiniteLoop(), this._setExecuting(!0), this._safeCleanup();
1194
+ const s = this._dependencies, n = this._unsubscribes, r = g.acquire(), c = I.acquire(), o = G();
1195
+ if (s !== f && n !== E)
1196
+ for (let u = 0; u < s.length; u++) {
1197
+ const l = s[u];
1198
+ l && (l._tempUnsub = n[u]);
1199
+ }
1200
+ this._nextDeps = r, this._nextUnsubs = c, this._currentEpoch = o;
1201
+ let _ = !1;
1171
1202
  try {
1172
- const a = S.run(this, this._fn);
1173
- this._syncDependencies(s, r), this._dependencies = n, u = !0, this._checkLoopWarnings(), k(a) ? a.then((o) => {
1174
- !this.isDisposed && typeof o == "function" && (this._cleanup = o);
1175
- }).catch((o) => {
1176
- console.error(D(o, E, h.EFFECT_EXECUTION_FAILED));
1177
- }) : this._cleanup = typeof a == "function" ? a : null;
1178
- } catch (a) {
1179
- this._syncDependencies(s, r), this._dependencies = n, u = !0, console.error(D(a, E, h.EFFECT_EXECUTION_FAILED)), this._cleanup = null;
1203
+ const u = y.run(this, this._fn);
1204
+ this._dependencies = r, this._unsubscribes = c, _ = !0, this._checkLoopWarnings(), X(u) ? u.then((l) => {
1205
+ !this.isDisposed && typeof l == "function" && (this._cleanup = l);
1206
+ }).catch((l) => {
1207
+ console.error(R(l, S, a.EFFECT_EXECUTION_FAILED));
1208
+ }) : this._cleanup = typeof u == "function" ? u : null;
1209
+ } catch (u) {
1210
+ _ = !0, console.error(R(u, S, a.EFFECT_EXECUTION_FAILED)), this._cleanup = null;
1180
1211
  } finally {
1181
- this._setExecuting(!1), this._nextDeps = null, u ? s !== l && p.release(s) : p.release(n);
1212
+ if (this._setExecuting(!1), this._nextDeps = null, this._nextUnsubs = null, _) {
1213
+ if (s !== f) {
1214
+ for (let u = 0; u < s.length; u++) {
1215
+ const l = s[u];
1216
+ l?._tempUnsub && (l._tempUnsub(), l._tempUnsub = void 0);
1217
+ }
1218
+ g.release(s);
1219
+ }
1220
+ n !== E && I.release(n);
1221
+ } else {
1222
+ g.release(r);
1223
+ for (let u = 0; u < c.length; u++)
1224
+ c[u]?.();
1225
+ if (I.release(c), s !== f)
1226
+ for (let u = 0; u < s.length; u++) {
1227
+ const l = s[u];
1228
+ l && (l._tempUnsub = void 0);
1229
+ }
1230
+ }
1182
1231
  }
1183
- }, this._id = L() & I, this._flags = 0, this._currentEpoch = -1, this._fn = e, this._sync = t.sync ?? !1, this._maxExecutions = t.maxExecutionsPerSecond ?? N.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = t.maxExecutionsPerFlush ?? N.MAX_EXECUTIONS_PER_EFFECT, this._trackModifications = t.trackModifications ?? !1, this._cleanup = null, this._dependencies = l, this._subscriptions = /* @__PURE__ */ new Map(), this._nextDeps = null, this._modifiedDeps = /* @__PURE__ */ new Set(), this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._history = U ? [] : null, this._executionCount = 0, f.attachDebugInfo(this, "effect", this._id);
1232
+ }, this._id = B() & N, this._flags = 0, this._currentEpoch = -1, this._fn = e, this._sync = t.sync ?? !1, this._maxExecutions = t.maxExecutionsPerSecond ?? U.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = t.maxExecutionsPerFlush ?? U.MAX_EXECUTIONS_PER_EFFECT, this._trackModifications = t.trackModifications ?? !1, this._cleanup = null, this._dependencies = f, this._unsubscribes = E, this._nextDeps = null, this._nextUnsubs = null, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._history = w ? [] : null, this._executionCount = 0, b.attachDebugInfo(this, "effect", this._id);
1184
1233
  }
1185
1234
  /**
1186
1235
  * Synchronizes subscriptions by unsubscribing from removed dependencies.
@@ -1189,24 +1238,16 @@ class H {
1189
1238
  * @param prevDeps - Previous dependency array
1190
1239
  * @param epoch - Current execution epoch for staleness detection
1191
1240
  */
1192
- _syncDependencies(e, t) {
1193
- if (e !== l)
1194
- for (let s = 0; s < e.length; s++) {
1195
- const n = e[s];
1196
- if (n && n._lastSeenEpoch !== t) {
1197
- const r = this._subscriptions.get(n.id);
1198
- r && (r(), this._subscriptions.delete(n.id));
1199
- }
1200
- }
1201
- }
1241
+ // _syncDependencies removed (inline logic in execute)
1202
1242
  _subscribeTo(e) {
1203
1243
  try {
1204
1244
  const t = e.subscribe(() => {
1205
- this._trackModifications && this.isExecuting && this._modifiedDeps.add(e), this._sync ? this.execute() : g.schedule(this.execute);
1245
+ this._trackModifications && this.isExecuting && (e._modifiedAtEpoch = this._currentEpoch), this._sync ? this.execute() : m.schedule(this.execute);
1206
1246
  });
1207
- this._subscriptions.set(e.id, t);
1247
+ this._nextUnsubs && this._nextUnsubs.push(t);
1208
1248
  } catch (t) {
1209
- console.error(D(t, E, h.EFFECT_EXECUTION_FAILED));
1249
+ console.error(R(t, S, a.EFFECT_EXECUTION_FAILED)), this._nextUnsubs && this._nextUnsubs.push(() => {
1250
+ });
1210
1251
  }
1211
1252
  }
1212
1253
  /**
@@ -1228,7 +1269,7 @@ class H {
1228
1269
  * ```
1229
1270
  */
1230
1271
  get isDisposed() {
1231
- return (this._flags & m.DISPOSED) !== 0;
1272
+ return (this._flags & F.DISPOSED) !== 0;
1232
1273
  }
1233
1274
  /**
1234
1275
  * Returns the total number of times this effect has been executed.
@@ -1270,7 +1311,7 @@ class H {
1270
1311
  * ```
1271
1312
  */
1272
1313
  get isExecuting() {
1273
- return (this._flags & m.EXECUTING) !== 0;
1314
+ return (this._flags & F.EXECUTING) !== 0;
1274
1315
  }
1275
1316
  /**
1276
1317
  * Sets the disposed flag on this effect.
@@ -1282,7 +1323,7 @@ class H {
1282
1323
  * @internal
1283
1324
  */
1284
1325
  _setDisposed() {
1285
- this._flags |= m.DISPOSED;
1326
+ this._flags |= F.DISPOSED;
1286
1327
  }
1287
1328
  /**
1288
1329
  * Sets or clears the executing flag on this effect.
@@ -1296,7 +1337,7 @@ class H {
1296
1337
  * @internal
1297
1338
  */
1298
1339
  _setExecuting(e) {
1299
- const t = m.EXECUTING;
1340
+ const t = F.EXECUTING;
1300
1341
  this._flags = this._flags & ~t | -Number(e) & t;
1301
1342
  }
1302
1343
  /**
@@ -1317,7 +1358,7 @@ class H {
1317
1358
  try {
1318
1359
  this._cleanup();
1319
1360
  } catch (e) {
1320
- console.error(D(e, E, h.EFFECT_CLEANUP_FAILED));
1361
+ console.error(R(e, S, a.EFFECT_CLEANUP_FAILED));
1321
1362
  }
1322
1363
  this._cleanup = null;
1323
1364
  }
@@ -1330,9 +1371,9 @@ class H {
1330
1371
  * @internal
1331
1372
  */
1332
1373
  _checkInfiniteLoop() {
1333
- if (this._lastFlushEpoch !== C && (this._lastFlushEpoch = C, this._executionsInEpoch = 0), this._executionsInEpoch++, this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), V() > N.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++, this._history) {
1374
+ if (this._lastFlushEpoch !== A && (this._lastFlushEpoch = A, this._executionsInEpoch = 0), this._executionsInEpoch++, this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), H() > U.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++, this._history) {
1334
1375
  const e = Date.now();
1335
- this._history.push(e), this._history.length > N.MAX_EXECUTIONS_PER_SECOND + 10 && this._history.shift(), this._checkTimestampLoop(e);
1376
+ this._history.push(e), this._history.length > U.MAX_EXECUTIONS_PER_SECOND + 10 && this._history.shift(), this._checkTimestampLoop(e);
1336
1377
  }
1337
1378
  }
1338
1379
  _checkTimestampLoop(e) {
@@ -1343,16 +1384,16 @@ class H {
1343
1384
  for (let r = t.length - 1; r >= 0 && !(t[r] < s); r--)
1344
1385
  n++;
1345
1386
  if (n > this._maxExecutions) {
1346
- const r = new E(
1387
+ const r = new S(
1347
1388
  `Effect executed ${n} times within 1 second. Infinite loop suspected`
1348
1389
  );
1349
- if (this.dispose(), console.error(r), U)
1390
+ if (this.dispose(), console.error(r), w)
1350
1391
  throw r;
1351
1392
  }
1352
1393
  }
1353
1394
  _throwInfiniteLoopError(e) {
1354
- const t = new E(
1355
- `Infinite loop detected (${e}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${P}`
1395
+ const t = new S(
1396
+ `Infinite loop detected (${e}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${v}`
1356
1397
  );
1357
1398
  throw this.dispose(), console.error(t), t;
1358
1399
  }
@@ -1370,56 +1411,56 @@ class H {
1370
1411
  * @internal
1371
1412
  */
1372
1413
  _checkLoopWarnings() {
1373
- if (this._trackModifications && f.enabled) {
1414
+ if (this._trackModifications && b.enabled) {
1374
1415
  const e = this._dependencies;
1375
1416
  for (let t = 0; t < e.length; t++) {
1376
1417
  const s = e[t];
1377
- s && this._modifiedDeps.has(s) && f.warn(
1418
+ s && s._modifiedAtEpoch === this._currentEpoch && b.warn(
1378
1419
  !0,
1379
- `Effect is reading a dependency (${f.getDebugName(s) || "unknown"}) that it just modified. Infinite loop may occur`
1420
+ `Effect is reading a dependency (${b.getDebugName(s) || "unknown"}) that it just modified. Infinite loop may occur`
1380
1421
  );
1381
1422
  }
1382
1423
  }
1383
1424
  }
1384
1425
  }
1385
- function se(i, e = {}) {
1426
+ function he(i, e = {}) {
1386
1427
  if (typeof i != "function")
1387
- throw new E(h.EFFECT_MUST_BE_FUNCTION);
1388
- const t = new H(i, e);
1428
+ throw new S(a.EFFECT_MUST_BE_FUNCTION);
1429
+ const t = new te(i, e);
1389
1430
  return t.execute(), t;
1390
1431
  }
1391
- function J(i) {
1432
+ function se(i) {
1392
1433
  return i !== null && typeof i == "object" && "value" in i && "subscribe" in i && typeof i.subscribe == "function";
1393
1434
  }
1394
- function ie(i) {
1395
- if (f.enabled) {
1396
- const e = f.getDebugType(i);
1435
+ function oe(i) {
1436
+ if (b.enabled) {
1437
+ const e = b.getDebugType(i);
1397
1438
  if (e)
1398
1439
  return e === "computed";
1399
1440
  }
1400
- return J(i) && "invalidate" in i && typeof i.invalidate == "function";
1441
+ return se(i) && "invalidate" in i && typeof i.invalidate == "function";
1401
1442
  }
1402
- function ne(i) {
1443
+ function ae(i) {
1403
1444
  return i !== null && typeof i == "object" && "dispose" in i && "run" in i && typeof i.dispose == "function" && typeof i.run == "function";
1404
1445
  }
1405
1446
  export {
1406
- R as AsyncState,
1407
- _ as AtomError,
1408
- b as ComputedError,
1409
- M as DEBUG_CONFIG,
1410
- f as DEBUG_RUNTIME,
1411
- E as EffectError,
1412
- W as POOL_CONFIG,
1413
- N as SCHEDULER_CONFIG,
1414
- y as SchedulerError,
1415
- ee as atom,
1416
- K as batch,
1417
- te as computed,
1418
- se as effect,
1419
- J as isAtom,
1420
- ie as isComputed,
1421
- ne as isEffect,
1422
- g as scheduler,
1423
- Z as untracked
1447
+ T as AsyncState,
1448
+ d as AtomError,
1449
+ D as ComputedError,
1450
+ k as DEBUG_CONFIG,
1451
+ b as DEBUG_RUNTIME,
1452
+ S as EffectError,
1453
+ ie as POOL_CONFIG,
1454
+ U as SCHEDULER_CONFIG,
1455
+ C as SchedulerError,
1456
+ ce as atom,
1457
+ ne as batch,
1458
+ ue as computed,
1459
+ he as effect,
1460
+ se as isAtom,
1461
+ oe as isComputed,
1462
+ ae as isEffect,
1463
+ m as scheduler,
1464
+ re as untracked
1424
1465
  };
1425
1466
  //# sourceMappingURL=index.mjs.map