@but212/atom-effect 0.8.4 → 0.9.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,7 +1,7 @@
1
1
  const Z = {
2
2
  /** One second in milliseconds */
3
3
  ONE_SECOND_MS: 1e3
4
- }, v = {
4
+ }, P = {
5
5
  IDLE: "idle",
6
6
  PENDING: "pending",
7
7
  RESOLVED: "resolved",
@@ -31,7 +31,7 @@ const Z = {
31
31
  MAX_SIZE: 1e3,
32
32
  /** Number of objects to pre-allocate for performance-critical paths */
33
33
  WARMUP_SIZE: 100
34
- }, g = {
34
+ }, D = {
35
35
  /** Maximum effect executions per second to detect infinite loops (Legacy/Fallback) */
36
36
  MAX_EXECUTIONS_PER_SECOND: 1e3,
37
37
  /** Threshold for cleaning up old execution timestamps */
@@ -50,24 +50,24 @@ const Z = {
50
50
  MAX_FLUSH_ITERATIONS: 1e3,
51
51
  /** Minimum allowed value for max flush iterations */
52
52
  MIN_FLUSH_ITERATIONS: 10
53
- }, k = {
53
+ }, B = {
54
54
  /** Maximum dependencies before warning about large dependency graphs */
55
55
  MAX_DEPENDENCIES: 1e3,
56
56
  /** Enable infinite loop detection warnings */
57
57
  WARN_INFINITE_LOOP: !0
58
- }, I = 1073741823, a = typeof process < "u" && process.env && process.env.NODE_ENV !== "production", ee = Object.freeze([]);
59
- class p extends Error {
58
+ }, I = 1073741823, l = typeof process < "u" && process.env && process.env.NODE_ENV !== "production", ee = Object.freeze([]);
59
+ class b extends Error {
60
60
  /**
61
61
  * Creates a new AtomError
62
62
  * @param message - Error message describing what went wrong
63
63
  * @param cause - Original error that caused this error
64
64
  * @param recoverable - Whether the operation can be retried
65
65
  */
66
- constructor(e, t = null, s = !0) {
67
- super(e), this.name = "AtomError", this.cause = t, this.recoverable = s, this.timestamp = /* @__PURE__ */ new Date();
66
+ constructor(e, t = null, i = !0) {
67
+ super(e), this.name = "AtomError", this.cause = t, this.recoverable = i, this.timestamp = /* @__PURE__ */ new Date();
68
68
  }
69
69
  }
70
- class N extends p {
70
+ class N extends b {
71
71
  /**
72
72
  * Creates a new ComputedError
73
73
  * @param message - Error message
@@ -77,7 +77,7 @@ class N extends p {
77
77
  super(e, t, !0), this.name = "ComputedError";
78
78
  }
79
79
  }
80
- class b extends p {
80
+ class g extends b {
81
81
  /**
82
82
  * Creates a new EffectError
83
83
  * @param message - Error message
@@ -87,7 +87,7 @@ class b extends p {
87
87
  super(e, t, !1), this.name = "EffectError";
88
88
  }
89
89
  }
90
- class O extends p {
90
+ class O extends b {
91
91
  /**
92
92
  * Creates a new SchedulerError
93
93
  * @param message - Error message
@@ -105,10 +105,6 @@ const h = {
105
105
  * Error thrown when computed() receives a non-function argument.
106
106
  */
107
107
  COMPUTED_MUST_BE_FUNCTION: "Computed function must be a function",
108
- /**
109
- * Error thrown when subscribe() receives an invalid listener.
110
- */
111
- COMPUTED_SUBSCRIBER_MUST_BE_FUNCTION: "Subscriber listener must be a function or Subscriber object",
112
108
  /**
113
109
  * Error thrown when accessing a pending async computed without a default value.
114
110
  */
@@ -121,10 +117,6 @@ const h = {
121
117
  * Error thrown when an asynchronous computed computation fails.
122
118
  */
123
119
  COMPUTED_ASYNC_COMPUTATION_FAILED: "Async computed computation failed",
124
- /**
125
- * Error thrown when subscribing to a dependency fails.
126
- */
127
- COMPUTED_DEPENDENCY_SUBSCRIPTION_FAILED: "Failed to subscribe to dependency",
128
120
  // ─────────────────────────────────────────────────────────────────
129
121
  // Atom errors
130
122
  // ─────────────────────────────────────────────────────────────────
@@ -132,10 +124,6 @@ const h = {
132
124
  * Error thrown when atom.subscribe() receives an invalid listener.
133
125
  */
134
126
  ATOM_SUBSCRIBER_MUST_BE_FUNCTION: "Subscription listener must be a function or Subscriber object",
135
- /**
136
- * Error thrown when the atom subscriber notification process fails.
137
- */
138
- ATOM_SUBSCRIBER_EXECUTION_FAILED: "Error occurred while executing atom subscribers",
139
127
  /**
140
128
  * Error logged when an individual subscriber throws during notification.
141
129
  * @remarks This error is caught and logged to prevent cascading failures.
@@ -156,79 +144,59 @@ const h = {
156
144
  * Error thrown when an effect's cleanup function fails.
157
145
  */
158
146
  EFFECT_CLEANUP_FAILED: "Effect cleanup function execution failed",
159
- // ─────────────────────────────────────────────────────────────────
160
- // Debug warnings
161
- // ─────────────────────────────────────────────────────────────────
162
- /**
163
- * Warning message for large dependency graphs.
164
- *
165
- * @param count - The number of dependencies detected
166
- * @returns Formatted warning message with dependency count
167
- *
168
- * @example
169
- * ```ts
170
- * console.warn(ERROR_MESSAGES.LARGE_DEPENDENCY_GRAPH(150));
171
- * // Output: "Large dependency graph detected: 150 dependencies"
172
- * ```
173
- */
174
- LARGE_DEPENDENCY_GRAPH: (i) => `Large dependency graph detected: ${i} dependencies`,
175
- /**
176
- * Warning logged when attempting to unsubscribe a non-existent listener.
177
- */
178
- UNSUBSCRIBE_NON_EXISTENT: "Attempted to unsubscribe a non-existent listener",
179
147
  /**
180
148
  * Error logged when the onError callback itself throws an error.
181
149
  * @remarks This prevents cascading failures from masking the original error.
182
150
  */
183
151
  CALLBACK_ERROR_IN_ERROR_HANDLER: "Error occurred during onError callback execution"
184
- }, L = /* @__PURE__ */ Symbol("debugName"), te = /* @__PURE__ */ Symbol("id"), V = /* @__PURE__ */ Symbol("type"), q = /* @__PURE__ */ Symbol("noDefaultValue");
185
- function se(i) {
186
- return "dependencies" in i && Array.isArray(i.dependencies);
152
+ }, L = /* @__PURE__ */ Symbol("debugName"), te = /* @__PURE__ */ Symbol("id"), V = /* @__PURE__ */ Symbol("type"), j = /* @__PURE__ */ Symbol("noDefaultValue");
153
+ function se(s) {
154
+ return "dependencies" in s && Array.isArray(s.dependencies);
187
155
  }
188
- let j = 0;
189
- function G(i, e, t) {
190
- if (i._visitedEpoch !== t) {
191
- if (i._visitedEpoch = t, i === e)
156
+ let q = 0;
157
+ function G(s, e, t) {
158
+ if (s._visitedEpoch !== t) {
159
+ if (s._visitedEpoch = t, s === e)
192
160
  throw new N("Indirect circular dependency detected");
193
- if (se(i)) {
194
- const s = i.dependencies;
195
- for (let n = 0; n < s.length; n++) {
196
- const r = s[n];
161
+ if (se(s)) {
162
+ const i = s.dependencies;
163
+ for (let n = 0; n < i.length; n++) {
164
+ const r = i[n];
197
165
  r && G(r, e, t);
198
166
  }
199
167
  }
200
168
  }
201
169
  }
202
- const d = {
170
+ const E = {
203
171
  enabled: typeof process < "u" && process.env?.NODE_ENV === "development",
204
- maxDependencies: k.MAX_DEPENDENCIES,
205
- warnInfiniteLoop: k.WARN_INFINITE_LOOP,
206
- warn(i, e) {
207
- this.enabled && i && console.warn(`[Atom Effect] ${e}`);
172
+ maxDependencies: B.MAX_DEPENDENCIES,
173
+ warnInfiniteLoop: B.WARN_INFINITE_LOOP,
174
+ warn(s, e) {
175
+ this.enabled && s && console.warn(`[Atom Effect] ${e}`);
208
176
  },
209
177
  /**
210
178
  * Checks for circular dependencies.
211
179
  * Direct check runs always; indirect check only in dev mode.
212
180
  * @throws {ComputedError} When circular dependency detected
213
181
  */
214
- checkCircular(i, e) {
215
- if (i === e)
182
+ checkCircular(s, e) {
183
+ if (s === e)
216
184
  throw new N("Direct circular dependency detected");
217
- this.enabled && (j++, G(i, e, j));
185
+ this.enabled && (q++, G(s, e, q));
218
186
  },
219
- attachDebugInfo(i, e, t) {
187
+ attachDebugInfo(s, e, t) {
220
188
  if (!this.enabled)
221
189
  return;
222
- const s = i;
223
- s[L] = `${e}_${t}`, s[te] = t, s[V] = e;
190
+ const i = s;
191
+ i[L] = `${e}_${t}`, i[te] = t, i[V] = e;
224
192
  },
225
- getDebugName(i) {
226
- if (i != null && L in i)
227
- return i[L];
193
+ getDebugName(s) {
194
+ if (s != null && L in s)
195
+ return s[L];
228
196
  },
229
- getDebugType(i) {
230
- if (i != null && V in i)
231
- return i[V];
197
+ getDebugType(s) {
198
+ if (s != null && V in s)
199
+ return s[V];
232
200
  }
233
201
  };
234
202
  let ie = 1;
@@ -238,7 +206,7 @@ class Y {
238
206
  this.id = ne() & I, this.flags = 0;
239
207
  }
240
208
  }
241
- class $ extends Y {
209
+ class Q extends Y {
242
210
  constructor() {
243
211
  super(), this.version = 0, this._lastSeenEpoch = -1;
244
212
  }
@@ -253,7 +221,7 @@ class $ extends Y {
253
221
  if (typeof e == "object" && e !== null && "execute" in e)
254
222
  return this._objectSubscribers.add(e);
255
223
  if (typeof e != "function")
256
- throw new p(h.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
224
+ throw new b(h.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
257
225
  return this._functionSubscribers.add(e);
258
226
  }
259
227
  /**
@@ -270,26 +238,26 @@ class $ extends Y {
270
238
  */
271
239
  _notifySubscribers(e, t) {
272
240
  this._functionSubscribers.forEachSafe(
273
- (s) => s(e, t),
274
- (s) => console.error(new p(h.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED, s))
241
+ (i) => i(e, t),
242
+ (i) => console.error(new b(h.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED, i))
275
243
  ), this._objectSubscribers.forEachSafe(
276
- (s) => s.execute(),
277
- (s) => console.error(new p(h.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED, s))
244
+ (i) => i.execute(),
245
+ (i) => console.error(new b(h.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED, i))
278
246
  );
279
247
  }
280
248
  }
281
- let U = 0;
282
- function H() {
283
- return U = (U + 1 | 0) & I, U;
249
+ let x = 0;
250
+ function $() {
251
+ return x = x + 1 & I || 1, x;
284
252
  }
285
253
  function re() {
286
- return U;
254
+ return x;
287
255
  }
288
- let x = 0, w = 0, F = !1;
256
+ let U = 0, w = 0, F = !1;
289
257
  function z() {
290
- return F ? (a && console.warn(
258
+ return F ? (l && console.warn(
291
259
  "Warning: startFlush() called during flush - ignored to prevent infinite loop detection bypass"
292
- ), !1) : (F = !0, x = x + 1 & I, w = 0, !0);
260
+ ), !1) : (F = !0, U = U + 1 & I, w = 0, !0);
293
261
  }
294
262
  function X() {
295
263
  F = !1;
@@ -299,7 +267,7 @@ function oe() {
299
267
  }
300
268
  class ce {
301
269
  constructor() {
302
- 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 = g.MAX_FLUSH_ITERATIONS;
270
+ 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 = D.MAX_FLUSH_ITERATIONS;
303
271
  }
304
272
  get phase() {
305
273
  return this.isProcessing || this.isFlushingSync ? 2 : this.isBatching ? 1 : 0;
@@ -316,13 +284,15 @@ class ce {
316
284
  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()));
317
285
  }
318
286
  flush() {
319
- if (this.isProcessing || this.queueSize === 0) return;
320
- this.isProcessing = !0;
321
- const e = this.queue, t = this.queueSize;
322
- this.queue = this.queue === this.queueA ? this.queueB : this.queueA, this.queueSize = 0, this._epoch++, queueMicrotask(() => {
323
- const s = z();
324
- this._processJobs(e, t), this.isProcessing = !1, s && X(), this.queueSize > 0 && !this.isBatching && this.flush();
325
- });
287
+ this.isProcessing || this.queueSize === 0 || (this.isProcessing = !0, queueMicrotask(() => {
288
+ try {
289
+ if (this.queueSize === 0) return;
290
+ const e = z();
291
+ this._drainQueue(), e && X();
292
+ } finally {
293
+ this.isProcessing = !1, this.queueSize > 0 && !this.isBatching && this.flush();
294
+ }
295
+ }));
326
296
  }
327
297
  flushSync() {
328
298
  this.isFlushingSync = !0;
@@ -364,9 +334,9 @@ class ce {
364
334
  ), this.queueSize = 0, this.queue.length = 0, this.batchQueueSize = 0;
365
335
  }
366
336
  _processJobs(e, t) {
367
- for (let s = 0; s < t; s++)
337
+ for (let i = 0; i < t; i++)
368
338
  try {
369
- e[s]?.();
339
+ e[i]?.();
370
340
  } catch (n) {
371
341
  console.error(
372
342
  new O("Error occurred during scheduler execution", n)
@@ -390,29 +360,29 @@ class ce {
390
360
  * @param max - Maximum iterations count.
391
361
  */
392
362
  setMaxFlushIterations(e) {
393
- if (e < g.MIN_FLUSH_ITERATIONS)
363
+ if (e < D.MIN_FLUSH_ITERATIONS)
394
364
  throw new O(
395
- `Max flush iterations must be at least ${g.MIN_FLUSH_ITERATIONS}`
365
+ `Max flush iterations must be at least ${D.MIN_FLUSH_ITERATIONS}`
396
366
  );
397
367
  this.maxFlushIterations = e;
398
368
  }
399
369
  }
400
370
  const T = new ce();
401
- function Se(i) {
402
- if (typeof i != "function")
403
- throw new p("Batch callback must be a function");
371
+ function Se(s) {
372
+ if (typeof s != "function")
373
+ throw new b("Batch callback must be a function");
404
374
  T.startBatch();
405
375
  try {
406
- return i();
376
+ return s();
407
377
  } finally {
408
378
  T.endBatch();
409
379
  }
410
380
  }
411
- const y = {
381
+ const m = {
412
382
  current: null,
413
- run(i, e) {
383
+ run(s, e) {
414
384
  const t = this.current;
415
- this.current = i;
385
+ this.current = s;
416
386
  try {
417
387
  return e();
418
388
  } finally {
@@ -423,18 +393,18 @@ const y = {
423
393
  return this.current;
424
394
  }
425
395
  };
426
- function he(i) {
427
- if (typeof i != "function")
428
- throw new p("Untracked callback must be a function");
429
- const e = y.current;
430
- y.current = null;
396
+ function he(s) {
397
+ if (typeof s != "function")
398
+ throw new b("Untracked callback must be a function");
399
+ const e = m.current;
400
+ m.current = null;
431
401
  try {
432
- return i();
402
+ return s();
433
403
  } finally {
434
- y.current = e;
404
+ m.current = e;
435
405
  }
436
406
  }
437
- class P {
407
+ class v {
438
408
  constructor() {
439
409
  this.subscribers = null;
440
410
  }
@@ -456,8 +426,8 @@ class P {
456
426
  const t = this.subscribers.indexOf(e);
457
427
  if (t === -1)
458
428
  return !1;
459
- const s = this.subscribers.length - 1;
460
- return t !== s && (this.subscribers[t] = this.subscribers[s]), this.subscribers.pop(), !0;
429
+ const i = this.subscribers.length - 1;
430
+ return t !== i && (this.subscribers[t] = this.subscribers[i]), this.subscribers.pop(), !0;
461
431
  }
462
432
  has(e) {
463
433
  return this.subscribers ? this.subscribers.indexOf(e) !== -1 : !1;
@@ -470,9 +440,9 @@ class P {
470
440
  /** Iterates with error handling to prevent one failure from breaking the chain */
471
441
  forEachSafe(e, t) {
472
442
  if (this.subscribers)
473
- for (let s = 0; s < this.subscribers.length; s++)
443
+ for (let i = 0; i < this.subscribers.length; i++)
474
444
  try {
475
- e(this.subscribers[s], s);
445
+ e(this.subscribers[i], i);
476
446
  } catch (n) {
477
447
  t ? t(n) : console.error("[SubscriberManager] Error in subscriber callback:", n);
478
448
  }
@@ -490,9 +460,9 @@ class P {
490
460
  return this.subscribers ? [...this.subscribers] : [];
491
461
  }
492
462
  }
493
- class B {
463
+ class k {
494
464
  constructor() {
495
- this.pool = [], this.maxPoolSize = 50, this.maxReusableCapacity = 256, this.stats = a ? {
465
+ this.pool = [], this.maxPoolSize = 50, this.maxReusableCapacity = 256, this.stats = l ? {
496
466
  acquired: 0,
497
467
  released: 0,
498
468
  rejected: { frozen: 0, tooLarge: 0, poolFull: 0 }
@@ -500,7 +470,7 @@ class B {
500
470
  }
501
471
  /** Acquires an array from the pool or creates a new one if the pool is empty. */
502
472
  acquire() {
503
- return a && this.stats && this.stats.acquired++, this.pool.pop() ?? [];
473
+ return l && this.stats && this.stats.acquired++, this.pool.pop() ?? [];
504
474
  }
505
475
  /**
506
476
  * Releases an array back to the pool.
@@ -511,102 +481,102 @@ class B {
511
481
  release(e, t) {
512
482
  if (!(t && e === t)) {
513
483
  if (Object.isFrozen(e)) {
514
- a && this.stats && this.stats.rejected.frozen++;
484
+ l && this.stats && this.stats.rejected.frozen++;
515
485
  return;
516
486
  }
517
487
  if (e.length > this.maxReusableCapacity) {
518
- a && this.stats && this.stats.rejected.tooLarge++;
488
+ l && this.stats && this.stats.rejected.tooLarge++;
519
489
  return;
520
490
  }
521
491
  if (this.pool.length >= this.maxPoolSize) {
522
- a && this.stats && this.stats.rejected.poolFull++;
492
+ l && this.stats && this.stats.rejected.poolFull++;
523
493
  return;
524
494
  }
525
- e.length = 0, this.pool.push(e), a && this.stats && this.stats.released++;
495
+ e.length = 0, this.pool.push(e), l && this.stats && this.stats.released++;
526
496
  }
527
497
  }
528
498
  /** Returns current stats for the pool (dev mode only). */
529
499
  getStats() {
530
- if (!a || !this.stats) return null;
531
- const { acquired: e, released: t, rejected: s } = this.stats, n = s.frozen + s.tooLarge + s.poolFull;
500
+ if (!l || !this.stats) return null;
501
+ const { acquired: e, released: t, rejected: i } = this.stats, n = i.frozen + i.tooLarge + i.poolFull;
532
502
  return {
533
503
  acquired: e,
534
504
  released: t,
535
- rejected: s,
505
+ rejected: i,
536
506
  leaked: e - t - n,
537
507
  poolSize: this.pool.length
538
508
  };
539
509
  }
540
510
  /** Resets the pool and its stats. */
541
511
  reset() {
542
- this.pool.length = 0, a && this.stats && (this.stats.acquired = 0, this.stats.released = 0, this.stats.rejected = { frozen: 0, tooLarge: 0, poolFull: 0 });
512
+ this.pool.length = 0, l && this.stats && (this.stats.acquired = 0, this.stats.released = 0, this.stats.rejected = { frozen: 0, tooLarge: 0, poolFull: 0 });
543
513
  }
544
514
  }
545
- const u = Object.freeze([]), l = Object.freeze([]), _ = Object.freeze([]), S = new B(), D = new B(), f = new B();
546
- function ue(i) {
547
- return i !== null && typeof i == "object" && "value" in i && "subscribe" in i && typeof i.subscribe == "function";
515
+ const u = Object.freeze([]), f = Object.freeze([]), a = Object.freeze([]), S = new k(), y = new k(), d = new k();
516
+ function ue(s) {
517
+ return s !== null && typeof s == "object" && "value" in s && "subscribe" in s && typeof s.subscribe == "function";
548
518
  }
549
- function ge(i) {
550
- if (d.enabled && (i == null || typeof i == "object")) {
551
- const e = d.getDebugType(i);
519
+ function ge(s) {
520
+ if (E.enabled && (s == null || typeof s == "object")) {
521
+ const e = E.getDebugType(s);
552
522
  if (e)
553
523
  return e === "computed";
554
524
  }
555
- return ue(i) && "invalidate" in i && typeof i.invalidate == "function";
525
+ return ue(s) && "invalidate" in s && typeof s.invalidate == "function";
556
526
  }
557
- function De(i) {
558
- return i !== null && typeof i == "object" && "dispose" in i && "run" in i && typeof i.dispose == "function" && typeof i.run == "function";
527
+ function De(s) {
528
+ return s !== null && typeof s == "object" && "dispose" in s && "run" in s && typeof s.dispose == "function" && typeof s.run == "function";
559
529
  }
560
- function J(i) {
561
- return i != null && typeof i.then == "function";
530
+ function H(s) {
531
+ return s != null && typeof s.then == "function";
562
532
  }
563
- function _e(i) {
564
- return typeof i == "object" && i !== null;
533
+ function ae(s) {
534
+ return typeof s == "object" && s !== null;
565
535
  }
566
- function ae(i) {
567
- return (typeof i == "object" || typeof i == "function") && i !== null && typeof i.addDependency == "function";
536
+ function _e(s) {
537
+ return (typeof s == "object" || typeof s == "function") && s !== null && typeof s.addDependency == "function";
568
538
  }
569
- function le(i) {
570
- return typeof i == "function" && typeof i.addDependency != "function";
539
+ function le(s) {
540
+ return typeof s == "function" && typeof s.addDependency != "function";
571
541
  }
572
- function fe(i) {
573
- return _e(i) && typeof i.execute == "function";
542
+ function fe(s) {
543
+ return ae(s) && typeof s.execute == "function";
574
544
  }
575
- function Q(i, e, t, s) {
545
+ function J(s, e, t, i) {
576
546
  if (e) {
577
- if (ae(e)) {
578
- e.addDependency(i);
547
+ if (_e(e)) {
548
+ e.addDependency(s);
579
549
  return;
580
550
  }
581
551
  if (le(e)) {
582
552
  t.add(e);
583
553
  return;
584
554
  }
585
- fe(e) && s.add(e);
555
+ fe(e) && i.add(e);
586
556
  }
587
557
  }
588
- function de(i, e, t, s) {
589
- if (e !== u && t !== l)
558
+ function de(s, e, t, i) {
559
+ if (e !== u && t !== f)
590
560
  for (let r = 0; r < e.length; r++) {
591
561
  const o = e[r];
592
562
  o && (o._tempUnsub = t[r]);
593
563
  }
594
- const n = D.acquire();
595
- n.length = i.length;
596
- for (let r = 0; r < i.length; r++) {
597
- const o = i[r];
598
- o && (o._tempUnsub ? (n[r] = o._tempUnsub, o._tempUnsub = void 0) : (d.checkCircular(o, s), n[r] = o.subscribe(s)));
564
+ const n = y.acquire();
565
+ n.length = s.length;
566
+ for (let r = 0; r < s.length; r++) {
567
+ const o = s[r];
568
+ o && (o._tempUnsub ? (n[r] = o._tempUnsub, o._tempUnsub = void 0) : (E.checkCircular(o, i), n[r] = o.subscribe(i)));
599
569
  }
600
570
  if (e !== u)
601
571
  for (let r = 0; r < e.length; r++) {
602
572
  const o = e[r];
603
573
  o?._tempUnsub && (o._tempUnsub(), o._tempUnsub = void 0);
604
574
  }
605
- return t !== l && D.release(t), n;
575
+ return t !== f && y.release(t), n;
606
576
  }
607
- class Ee extends $ {
577
+ class Ee extends Q {
608
578
  constructor(e, t) {
609
- super(), this._isNotificationScheduled = !1, this._value = e, this._functionSubscribersStore = new P(), this._objectSubscribersStore = new P(), this._sync = t, this._notifyTask = this._flushNotifications.bind(this), d.attachDebugInfo(this, "atom", this.id);
579
+ super(), this._isNotificationScheduled = !1, this._value = e, this._functionSubscribersStore = new v(), this._objectSubscribersStore = new v(), this._sync = t, this._notifyTask = this._flushNotifications.bind(this), E.attachDebugInfo(this, "atom", this.id);
610
580
  }
611
581
  /** Gets the manager for function-based subscribers. */
612
582
  get _functionSubscribers() {
@@ -620,7 +590,7 @@ class Ee extends $ {
620
590
  * Returns the current value and registers the atom as a dependency in the current tracking context.
621
591
  */
622
592
  get value() {
623
- const e = y.getCurrent();
593
+ const e = m.getCurrent();
624
594
  return e && this._track(e), this._value;
625
595
  }
626
596
  /**
@@ -633,7 +603,7 @@ class Ee extends $ {
633
603
  this.version = this.version + 1 & I, this._value = e, !(!this._functionSubscribersStore.hasSubscribers && !this._objectSubscribersStore.hasSubscribers) && this._scheduleNotification(t);
634
604
  }
635
605
  _track(e) {
636
- Q(this, e, this._functionSubscribersStore, this._objectSubscribersStore);
606
+ J(this, e, this._functionSubscribersStore, this._objectSubscribersStore);
637
607
  }
638
608
  _scheduleNotification(e) {
639
609
  this._isNotificationScheduled || (this._pendingOldValue = e, this._isNotificationScheduled = !0), this._sync && !T.isBatching ? this._flushNotifications() : T.schedule(this._notifyTask);
@@ -656,41 +626,41 @@ class Ee extends $ {
656
626
  this._functionSubscribersStore.clear(), this._objectSubscribersStore.clear(), this._value = void 0;
657
627
  }
658
628
  }
659
- function Ie(i, e = {}) {
660
- return new Ee(i, e.sync ?? !1);
629
+ function ye(s, e = {}) {
630
+ return new Ee(s, e.sync ?? !1);
661
631
  }
662
- function R(i, e, t) {
663
- if (i instanceof TypeError)
664
- return new e(`Type error (${t}): ${i.message}`, i);
665
- if (i instanceof ReferenceError)
666
- return new e(`Reference error (${t}): ${i.message}`, i);
667
- if (i instanceof p)
668
- return i;
669
- const s = i instanceof Error ? i.message : String(i), n = i instanceof Error ? i : null;
670
- return new e(`Unexpected error (${t}): ${s}`, n);
632
+ function R(s, e, t) {
633
+ if (s instanceof TypeError)
634
+ return new e(`Type error (${t}): ${s.message}`, s);
635
+ if (s instanceof ReferenceError)
636
+ return new e(`Reference error (${t}): ${s.message}`, s);
637
+ if (s instanceof b)
638
+ return s;
639
+ const i = s instanceof Error ? s.message : String(s), n = s instanceof Error ? s : null;
640
+ return new e(`Unexpected error (${t}): ${i}`, n);
671
641
  }
672
- const W = c.RESOLVED | c.PENDING | c.REJECTED, M = Array(W + 1).fill(v.IDLE);
673
- M[c.RESOLVED] = v.RESOLVED;
674
- M[c.PENDING] = v.PENDING;
675
- M[c.REJECTED] = v.REJECTED;
676
- class K extends $ {
642
+ const W = c.RESOLVED | c.PENDING | c.REJECTED, M = Array(W + 1).fill(P.IDLE);
643
+ M[c.RESOLVED] = P.RESOLVED;
644
+ M[c.PENDING] = P.PENDING;
645
+ M[c.REJECTED] = P.REJECTED;
646
+ class K extends Q {
677
647
  constructor(e, t = {}) {
678
648
  if (typeof e != "function")
679
649
  throw new N(h.COMPUTED_MUST_BE_FUNCTION);
680
- if (super(), this._cachedErrors = null, this._errorCacheEpoch = -1, this._value = void 0, this.flags = 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 : q, this._hasDefaultValue = this._defaultValue !== q, this._onError = t.onError ?? null, this.MAX_PROMISE_ID = Number.MAX_SAFE_INTEGER - 1, this._functionSubscribersStore = new P(), this._objectSubscribersStore = new P(), this._dependencies = u, this._dependencyVersions = _, this._unsubscribes = l, this._notifyJob = () => {
650
+ if (super(), this._cachedErrors = null, this._errorCacheEpoch = -1, this._value = void 0, this.flags = 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 : j, this._hasDefaultValue = this._defaultValue !== j, this._onError = t.onError ?? null, this.MAX_PROMISE_ID = Number.MAX_SAFE_INTEGER - 1, this._functionSubscribersStore = new v(), this._objectSubscribersStore = new v(), this._dependencies = u, this._dependencyVersions = a, this._unsubscribes = f, this._notifyJob = () => {
681
651
  this._functionSubscribersStore.forEachSafe(
682
- (s) => s(),
683
- (s) => console.error(s)
652
+ (i) => i(),
653
+ (i) => console.error(i)
684
654
  ), this._objectSubscribersStore.forEachSafe(
685
- (s) => s.execute(),
686
- (s) => console.error(s)
655
+ (i) => i.execute(),
656
+ (i) => console.error(i)
687
657
  );
688
658
  }, this._trackable = Object.assign(() => this._markDirty(), {
689
- addDependency: (s) => {
659
+ addDependency: (i) => {
690
660
  }
691
- }), d.attachDebugInfo(this, "computed", this.id), d.enabled) {
692
- const s = this;
693
- s.subscriberCount = () => this._functionSubscribersStore.size + this._objectSubscribersStore.size, s.isDirty = () => this._isDirty(), s.dependencies = this._dependencies, s.stateFlags = this._getFlagsAsString();
661
+ }), E.attachDebugInfo(this, "computed", this.id), E.enabled) {
662
+ const i = this;
663
+ i.subscriberCount = () => this._functionSubscribersStore.size + this._objectSubscribersStore.size, i.isDirty = () => this._isDirty(), i.dependencies = this._dependencies, i.stateFlags = this._getFlagsAsString();
694
664
  }
695
665
  if (t.lazy === !1)
696
666
  try {
@@ -734,13 +704,13 @@ class K extends $ {
734
704
  return this._cachedErrors;
735
705
  const t = /* @__PURE__ */ new Set();
736
706
  this._error && t.add(this._error);
737
- for (let s = 0; s < this._dependencies.length; s++) {
738
- const n = this._dependencies[s];
707
+ for (let i = 0; i < this._dependencies.length; i++) {
708
+ const n = this._dependencies[i];
739
709
  if (n && "errors" in n) {
740
710
  const r = n.errors;
741
711
  for (let o = 0; o < r.length; o++) {
742
- const m = r[o];
743
- m && t.add(m);
712
+ const _ = r[o];
713
+ _ && t.add(_);
744
714
  }
745
715
  }
746
716
  }
@@ -756,17 +726,17 @@ class K extends $ {
756
726
  return this._registerTracking(), this._isResolved();
757
727
  }
758
728
  invalidate() {
759
- this._markDirty(), this._dependencyVersions !== _ && (f.release(this._dependencyVersions), this._dependencyVersions = _), this._errorCacheEpoch = -1, this._cachedErrors = null;
729
+ this._markDirty(), this._dependencyVersions !== a && (d.release(this._dependencyVersions), this._dependencyVersions = a), this._errorCacheEpoch = -1, this._cachedErrors = null;
760
730
  }
761
731
  dispose() {
762
- if (this._unsubscribes !== l) {
732
+ if (this._unsubscribes !== f) {
763
733
  for (let e = 0; e < this._unsubscribes.length; e++) {
764
734
  const t = this._unsubscribes[e];
765
735
  t && t();
766
736
  }
767
- D.release(this._unsubscribes), this._unsubscribes = l;
737
+ y.release(this._unsubscribes), this._unsubscribes = f;
768
738
  }
769
- this._dependencies !== u && (S.release(this._dependencies), this._dependencies = u), this._dependencyVersions !== _ && (f.release(this._dependencyVersions), this._dependencyVersions = _), this._functionSubscribersStore.clear(), this._objectSubscribersStore.clear(), this.flags = c.DIRTY | c.IDLE, this._error = null, this._value = void 0, this._promiseId = (this._promiseId + 1) % this.MAX_PROMISE_ID, this._cachedErrors = null, this._errorCacheEpoch = -1;
739
+ this._dependencies !== u && (S.release(this._dependencies), this._dependencies = u), this._dependencyVersions !== a && (d.release(this._dependencyVersions), this._dependencyVersions = a), this._functionSubscribersStore.clear(), this._objectSubscribersStore.clear(), this.flags = c.DIRTY | c.IDLE, this._error = null, this._value = void 0, this._promiseId = (this._promiseId + 1) % this.MAX_PROMISE_ID, this._cachedErrors = null, this._errorCacheEpoch = -1;
770
740
  }
771
741
  // State flag operations
772
742
  _isDirty() {
@@ -825,32 +795,32 @@ class K extends $ {
825
795
  const e = this._prepareComputationContext();
826
796
  let t = !1;
827
797
  try {
828
- const s = y.run(this._trackable, this._fn);
829
- this._commitDependencies(e), t = !0, J(s) ? this._handleAsyncComputation(s) : this._handleSyncResult(s);
830
- } catch (s) {
798
+ const i = m.run(this._trackable, this._fn);
799
+ this._commitDependencies(e), t = !0, H(i) ? this._handleAsyncComputation(i) : this._handleSyncResult(i);
800
+ } catch (i) {
831
801
  if (!t)
832
802
  try {
833
803
  this._commitDependencies(e), t = !0;
834
804
  } catch (n) {
835
805
  this._handleComputationError(n);
836
806
  }
837
- this._handleComputationError(s);
807
+ this._handleComputationError(i);
838
808
  } finally {
839
809
  this._cleanupContext(e, t), this._setRecomputing(!1);
840
810
  }
841
811
  }
842
812
  _prepareComputationContext() {
843
- const e = this._dependencies, t = this._dependencyVersions, s = S.acquire(), n = f.acquire(), r = H(), o = { depCount: 0 }, m = (E) => {
844
- E._lastSeenEpoch !== r && (E._lastSeenEpoch = r, o.depCount < s.length ? (s[o.depCount] = E, n[o.depCount] = E.version) : (s.push(E), n.push(E.version)), o.depCount++);
813
+ const e = this._dependencies, t = this._dependencyVersions, i = S.acquire(), n = d.acquire(), r = $(), o = { depCount: 0 }, _ = (p) => {
814
+ p._lastSeenEpoch !== r && (p._lastSeenEpoch = r, o.depCount < i.length ? (i[o.depCount] = p, n[o.depCount] = p.version) : (i.push(p), n.push(p.version)), o.depCount++);
845
815
  }, C = this._trackable.addDependency;
846
- return this._trackable.addDependency = m, { prevDeps: e, prevVersions: t, nextDeps: s, nextVersions: n, originalAdd: C, state: o };
816
+ return this._trackable.addDependency = _, { prevDeps: e, prevVersions: t, nextDeps: i, nextVersions: n, originalAdd: C, state: o };
847
817
  }
848
818
  _commitDependencies(e) {
849
- const { nextDeps: t, nextVersions: s, state: n, prevDeps: r } = e;
850
- t.length = n.depCount, s.length = n.depCount, this._unsubscribes = de(t, r, this._unsubscribes, this), this._dependencies = t, this._dependencyVersions = s;
819
+ const { nextDeps: t, nextVersions: i, state: n, prevDeps: r } = e;
820
+ t.length = n.depCount, i.length = n.depCount, this._unsubscribes = de(t, r, this._unsubscribes, this), this._dependencies = t, this._dependencyVersions = i;
851
821
  }
852
822
  _cleanupContext(e, t) {
853
- this._trackable.addDependency = e.originalAdd, t ? (e.prevDeps !== u && S.release(e.prevDeps), e.prevVersions !== _ && f.release(e.prevVersions)) : (S.release(e.nextDeps), f.release(e.nextVersions));
823
+ this._trackable.addDependency = e.originalAdd, t ? (e.prevDeps !== u && S.release(e.prevDeps), e.prevVersions !== a && d.release(e.prevVersions)) : (S.release(e.nextDeps), d.release(e.nextVersions));
854
824
  }
855
825
  _handleSyncResult(e) {
856
826
  const t = !this._isResolved() || !this._equal(this._value, e);
@@ -859,10 +829,10 @@ class K extends $ {
859
829
  _handleAsyncComputation(e) {
860
830
  this._setPending(), this._clearDirty(), this._notifyJob(), this._promiseId = this._promiseId >= this.MAX_PROMISE_ID ? 1 : this._promiseId + 1;
861
831
  const t = this._promiseId;
862
- e.then((s) => {
863
- t === this._promiseId && this._handleAsyncResolution(s);
864
- }).catch((s) => {
865
- t === this._promiseId && this._handleAsyncRejection(s);
832
+ e.then((i) => {
833
+ t === this._promiseId && this._handleAsyncResolution(i);
834
+ }).catch((i) => {
835
+ t === this._promiseId && this._handleAsyncRejection(i);
866
836
  });
867
837
  }
868
838
  _handleAsyncResolution(e) {
@@ -870,8 +840,8 @@ class K extends $ {
870
840
  this.version = this.version + Number(t) & I, this._value = e, this._clearDirty(), this._setResolved(), this._error = null, this._setRecomputing(!1), this._cachedErrors = null, this._errorCacheEpoch = -1, this._notifyJob();
871
841
  }
872
842
  _handleAsyncRejection(e) {
873
- const t = R(e, N, h.COMPUTED_ASYNC_COMPUTATION_FAILED), s = !this._isRejected();
874
- if (this.version = this.version + Number(s) & I, this._error = t, this._setRejected(), this._clearDirty(), this._setRecomputing(!1), this._onError)
843
+ const t = R(e, N, h.COMPUTED_ASYNC_COMPUTATION_FAILED), i = !this._isRejected();
844
+ if (this.version = this.version + Number(i) & I, this._error = t, this._setRejected(), this._clearDirty(), this._setRecomputing(!1), this._onError)
875
845
  try {
876
846
  this._onError(t);
877
847
  } catch (n) {
@@ -884,8 +854,8 @@ class K extends $ {
884
854
  if (this._error = t, this._setRejected(), this._clearDirty(), this._setRecomputing(!1), this._onError)
885
855
  try {
886
856
  this._onError(t);
887
- } catch (s) {
888
- console.error(h.CALLBACK_ERROR_IN_ERROR_HANDLER, s);
857
+ } catch (i) {
858
+ console.error(h.CALLBACK_ERROR_IN_ERROR_HANDLER, i);
889
859
  }
890
860
  throw t;
891
861
  }
@@ -907,17 +877,17 @@ class K extends $ {
907
877
  this._isRecomputing() || this._isDirty() || (this._setDirty(), this._notifyJob());
908
878
  }
909
879
  _registerTracking() {
910
- Q(
880
+ J(
911
881
  this,
912
- y.getCurrent(),
882
+ m.getCurrent(),
913
883
  this._functionSubscribersStore,
914
884
  this._objectSubscribersStore
915
885
  );
916
886
  }
917
887
  }
918
888
  Object.freeze(K.prototype);
919
- function ye(i, e = {}) {
920
- return new K(i, e);
889
+ function Ie(s, e = {}) {
890
+ return new K(s, e);
921
891
  }
922
892
  class pe extends Y {
923
893
  /**
@@ -928,56 +898,58 @@ class pe extends Y {
928
898
  constructor(e, t = {}) {
929
899
  super(), this.run = () => {
930
900
  if (this.isDisposed)
931
- throw new b(h.EFFECT_MUST_BE_FUNCTION);
932
- this._dependencyVersions !== _ && (f.release(this._dependencyVersions), this._dependencyVersions = _), this.execute();
901
+ throw new g(h.EFFECT_MUST_BE_FUNCTION);
902
+ this._dependencyVersions !== a && (d.release(this._dependencyVersions), this._dependencyVersions = a), this.execute();
933
903
  }, this.dispose = () => {
934
904
  if (!this.isDisposed) {
935
- if (this._setDisposed(), this._safeCleanup(), this._unsubscribes !== l) {
936
- for (let s = 0; s < this._unsubscribes.length; s++) {
937
- const n = this._unsubscribes[s];
938
- n && n();
905
+ if (this._setDisposed(), this._safeCleanup(), this._unsubscribes !== f) {
906
+ for (let n = 0; n < this._unsubscribes.length; n++) {
907
+ const r = this._unsubscribes[n];
908
+ r && r();
939
909
  }
940
- D.release(this._unsubscribes), this._unsubscribes = l;
910
+ y.release(this._unsubscribes), this._unsubscribes = f;
941
911
  }
942
- this._dependencies !== u && (S.release(this._dependencies), this._dependencies = u), this._dependencyVersions !== _ && (f.release(this._dependencyVersions), this._dependencyVersions = _);
912
+ this._dependencies !== u && (S.release(this._dependencies), this._dependencies = u), this._dependencyVersions !== a && (d.release(this._dependencyVersions), this._dependencyVersions = a);
943
913
  }
944
- }, this.addDependency = (s) => {
914
+ }, this.addDependency = (n) => {
945
915
  if (this.isExecuting && this._nextDeps && this._nextUnsubs && this._nextVersions) {
946
- const n = this._currentEpoch;
947
- if (s._lastSeenEpoch === n) return;
948
- s._lastSeenEpoch = n, this._nextDeps.push(s), this._nextVersions.push(s.version), s._tempUnsub ? (this._nextUnsubs.push(s._tempUnsub), s._tempUnsub = void 0) : this._subscribeTo(s);
916
+ const r = this._currentEpoch;
917
+ if (n._lastSeenEpoch === r) return;
918
+ n._lastSeenEpoch = r, this._nextDeps.push(n), this._nextVersions.push(n.version), n._tempUnsub ? (this._nextUnsubs.push(n._tempUnsub), n._tempUnsub = void 0) : this._subscribeTo(n);
949
919
  }
950
920
  }, this.execute = () => {
951
921
  if (this.isDisposed || this.isExecuting || !this._shouldExecute()) return;
952
922
  this._checkInfiniteLoop(), this._setExecuting(!0), this._safeCleanup();
953
- const s = this._prepareEffectContext();
954
- let n = !1;
923
+ const n = this._prepareEffectContext();
924
+ let r = !1;
955
925
  try {
956
- const r = y.run(this, this._fn);
957
- this._commitEffect(s), n = !0, this._checkLoopWarnings(), J(r) ? r.then((o) => {
958
- !this.isDisposed && typeof o == "function" && (this._cleanup = o);
959
- }).catch((o) => {
960
- console.error(R(o, b, h.EFFECT_EXECUTION_FAILED));
961
- }) : this._cleanup = typeof r == "function" ? r : null;
962
- } catch (r) {
963
- n = !0, console.error(R(r, b, h.EFFECT_EXECUTION_FAILED)), this._cleanup = null;
926
+ const o = m.run(this, this._fn);
927
+ this._commitEffect(n), r = !0, this._checkLoopWarnings(), H(o) ? o.then((_) => {
928
+ !this.isDisposed && typeof _ == "function" && (this._cleanup = _);
929
+ }).catch((_) => {
930
+ this._handleExecutionError(_);
931
+ }) : this._cleanup = typeof o == "function" ? o : null;
932
+ } catch (o) {
933
+ r = !0, this._handleExecutionError(o), this._cleanup = null;
964
934
  } finally {
965
- this._cleanupEffect(s, n), this._setExecuting(!1);
935
+ this._cleanupEffect(n, r), this._setExecuting(!1);
966
936
  }
967
- }, this._currentEpoch = -1, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._fn = e, this._sync = t.sync ?? !1, this._maxExecutions = t.maxExecutionsPerSecond ?? g.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = t.maxExecutionsPerFlush ?? g.MAX_EXECUTIONS_PER_EFFECT, this._trackModifications = t.trackModifications ?? !1, this._cleanup = null, this._dependencies = u, this._dependencyVersions = _, this._unsubscribes = l, this._nextDeps = null, this._nextVersions = null, this._nextUnsubs = null, this._history = a ? [] : null, this._executionCount = 0, d.attachDebugInfo(this, "effect", this.id);
937
+ }, this._currentEpoch = -1, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._fn = e, this._sync = t.sync ?? !1, this._maxExecutions = t.maxExecutionsPerSecond ?? D.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = t.maxExecutionsPerFlush ?? D.MAX_EXECUTIONS_PER_EFFECT, this._trackModifications = t.trackModifications ?? !1, this._cleanup = null, this._dependencies = u, this._dependencyVersions = a, this._unsubscribes = f, this._nextDeps = null, this._nextVersions = null, this._nextUnsubs = null, this._onError = t.onError ?? null, this._historyPtr = 0;
938
+ const i = Number.isFinite(this._maxExecutions);
939
+ this._historyCapacity = i ? Math.min(this._maxExecutions + 1, D.MAX_EXECUTIONS_PER_SECOND + 1) : 0, this._history = l && i && this._historyCapacity > 0 ? new Array(this._historyCapacity).fill(0) : null, this._executionCount = 0, E.attachDebugInfo(this, "effect", this.id);
968
940
  }
969
941
  /**
970
942
  * Prepares the execution context by acquiring pools and setting up epoch.
971
943
  * @returns The prepared EffectContext.
972
944
  */
973
945
  _prepareEffectContext() {
974
- const e = this._dependencies, t = this._dependencyVersions, s = this._unsubscribes, n = S.acquire(), r = f.acquire(), o = D.acquire(), m = H();
975
- if (e !== u && s !== l)
946
+ const e = this._dependencies, t = this._dependencyVersions, i = this._unsubscribes, n = S.acquire(), r = d.acquire(), o = y.acquire(), _ = $();
947
+ if (e !== u && i !== f)
976
948
  for (let C = 0; C < e.length; C++) {
977
- const E = e[C];
978
- E && (E._tempUnsub = s[C]);
949
+ const p = e[C];
950
+ p && (p._tempUnsub = i[C]);
979
951
  }
980
- return this._nextDeps = n, this._nextVersions = r, this._nextUnsubs = o, this._currentEpoch = m, { prevDeps: e, prevVersions: t, prevUnsubs: s, nextDeps: n, nextVersions: r, nextUnsubs: o };
952
+ return this._nextDeps = n, this._nextVersions = r, this._nextUnsubs = o, this._currentEpoch = _, { prevDeps: e, prevVersions: t, prevUnsubs: i, nextDeps: n, nextVersions: r, nextUnsubs: o };
981
953
  }
982
954
  /**
983
955
  * Commits the tracked dependencies as the current active dependencies.
@@ -995,20 +967,20 @@ class pe extends Y {
995
967
  _cleanupEffect(e, t) {
996
968
  if (this._nextDeps = null, this._nextVersions = null, this._nextUnsubs = null, t) {
997
969
  if (e.prevDeps !== u) {
998
- for (let s = 0; s < e.prevDeps.length; s++) {
999
- const n = e.prevDeps[s];
970
+ for (let i = 0; i < e.prevDeps.length; i++) {
971
+ const n = e.prevDeps[i];
1000
972
  n?._tempUnsub && (n._tempUnsub(), n._tempUnsub = void 0);
1001
973
  }
1002
974
  S.release(e.prevDeps);
1003
975
  }
1004
- e.prevUnsubs !== l && D.release(e.prevUnsubs), e.prevVersions !== _ && f.release(e.prevVersions);
976
+ e.prevUnsubs !== f && y.release(e.prevUnsubs), e.prevVersions !== a && d.release(e.prevVersions);
1005
977
  } else {
1006
- S.release(e.nextDeps), f.release(e.nextVersions);
1007
- for (let s = 0; s < e.nextUnsubs.length; s++)
1008
- e.nextUnsubs[s]?.();
1009
- if (D.release(e.nextUnsubs), e.prevDeps !== u)
1010
- for (let s = 0; s < e.prevDeps.length; s++) {
1011
- const n = e.prevDeps[s];
978
+ S.release(e.nextDeps), d.release(e.nextVersions);
979
+ for (let i = 0; i < e.nextUnsubs.length; i++)
980
+ e.nextUnsubs[i]?.();
981
+ if (y.release(e.nextUnsubs), e.prevDeps !== u)
982
+ for (let i = 0; i < e.prevDeps.length; i++) {
983
+ const n = e.prevDeps[i];
1012
984
  n && (n._tempUnsub = void 0);
1013
985
  }
1014
986
  }
@@ -1024,7 +996,7 @@ class pe extends Y {
1024
996
  });
1025
997
  this._nextUnsubs && this._nextUnsubs.push(t);
1026
998
  } catch (t) {
1027
- console.error(R(t, b, h.EFFECT_EXECUTION_FAILED)), this._nextUnsubs && this._nextUnsubs.push(() => {
999
+ console.error(R(t, g, h.EFFECT_EXECUTION_FAILED)), this._nextUnsubs && this._nextUnsubs.push(() => {
1028
1000
  });
1029
1001
  }
1030
1002
  }
@@ -1061,7 +1033,7 @@ class pe extends Y {
1061
1033
  try {
1062
1034
  this._cleanup();
1063
1035
  } catch (e) {
1064
- console.error(R(e, b, h.EFFECT_CLEANUP_FAILED));
1036
+ console.error(R(e, g, h.EFFECT_CLEANUP_FAILED));
1065
1037
  }
1066
1038
  this._cleanup = null;
1067
1039
  }
@@ -1071,28 +1043,21 @@ class pe extends Y {
1071
1043
  * @throws {EffectError} If an infinite loop is detected.
1072
1044
  */
1073
1045
  _checkInfiniteLoop() {
1074
- if (this._lastFlushEpoch !== x && (this._lastFlushEpoch = x, this._executionsInEpoch = 0), this._executionsInEpoch++, this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), oe() > g.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++, this._history) {
1075
- const e = Date.now();
1076
- this._history.push(e), this._history.length > g.MAX_EXECUTIONS_PER_SECOND + 10 && this._history.shift(), this._checkTimestampLoop(e);
1077
- }
1078
- }
1079
- _checkTimestampLoop(e) {
1080
- const t = this._history;
1081
- if (!t || this._maxExecutions <= 0) return;
1082
- const s = e - Z.ONE_SECOND_MS;
1083
- let n = 0;
1084
- for (let r = t.length - 1; r >= 0 && !(t[r] < s); r--)
1085
- n++;
1086
- if (n > this._maxExecutions) {
1087
- const r = new b(
1088
- `Effect executed ${n} times within 1 second. Infinite loop suspected`
1089
- );
1090
- if (this.dispose(), console.error(r), a)
1091
- throw r;
1046
+ if (this._lastFlushEpoch !== U && (this._lastFlushEpoch = U, this._executionsInEpoch = 0), this._executionsInEpoch++, this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), oe() > D.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++, this._history && this._maxExecutions > 0) {
1047
+ const e = Date.now(), t = this._historyPtr, i = this._historyCapacity;
1048
+ this._history[t] = e;
1049
+ const n = (t + 1) % i, r = this._history[n] ?? 0;
1050
+ if (this._historyPtr = n, r > 0 && e - r < Z.ONE_SECOND_MS) {
1051
+ const o = new g(
1052
+ `Effect executed ${i} times within 1 second. Infinite loop suspected`
1053
+ );
1054
+ if (this.dispose(), console.error(o), this._onError && this._onError(o), l)
1055
+ throw o;
1056
+ }
1092
1057
  }
1093
1058
  }
1094
1059
  _throwInfiniteLoopError(e) {
1095
- const t = new b(
1060
+ const t = new g(
1096
1061
  `Infinite loop detected (${e}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${w}`
1097
1062
  );
1098
1063
  throw this.dispose(), console.error(t), t;
@@ -1102,7 +1067,7 @@ class pe extends Y {
1102
1067
  * @returns true if any dependency has changed or if it's the first run.
1103
1068
  */
1104
1069
  _shouldExecute() {
1105
- if (this._dependencies === u || this._dependencyVersions === _)
1070
+ if (this._dependencies === u || this._dependencyVersions === a)
1106
1071
  return !0;
1107
1072
  for (let e = 0; e < this._dependencies.length; e++) {
1108
1073
  const t = this._dependencies[e];
@@ -1119,42 +1084,50 @@ class pe extends Y {
1119
1084
  }
1120
1085
  return !1;
1121
1086
  }
1087
+ /**
1088
+ * Handles errors occurring during effect execution.
1089
+ * Wraps the error, logs it to console, and calls onError callback if provided.
1090
+ */
1091
+ _handleExecutionError(e) {
1092
+ const t = R(e, g, h.EFFECT_EXECUTION_FAILED);
1093
+ console.error(t), this._onError && this._onError(t);
1094
+ }
1122
1095
  /**
1123
1096
  * Checks for potential infinite loops where an effect modifies its own dependencies.
1124
1097
  * Only active if trackModifications is enabled and debug is on.
1125
1098
  */
1126
1099
  _checkLoopWarnings() {
1127
- if (this._trackModifications && d.enabled) {
1100
+ if (this._trackModifications && E.enabled) {
1128
1101
  const e = this._dependencies;
1129
1102
  for (let t = 0; t < e.length; t++) {
1130
- const s = e[t];
1131
- s && s._modifiedAtEpoch === this._currentEpoch && d.warn(
1103
+ const i = e[t];
1104
+ i && i._modifiedAtEpoch === this._currentEpoch && E.warn(
1132
1105
  !0,
1133
- `Effect is reading a dependency (${d.getDebugName(s) || "unknown"}) that it just modified. Infinite loop may occur`
1106
+ `Effect is reading a dependency (${E.getDebugName(i) || "unknown"}) that it just modified. Infinite loop may occur`
1134
1107
  );
1135
1108
  }
1136
1109
  }
1137
1110
  }
1138
1111
  }
1139
- function me(i, e = {}) {
1140
- if (typeof i != "function")
1141
- throw new b(h.EFFECT_MUST_BE_FUNCTION);
1142
- const t = new pe(i, e);
1112
+ function me(s, e = {}) {
1113
+ if (typeof s != "function")
1114
+ throw new g(h.EFFECT_MUST_BE_FUNCTION);
1115
+ const t = new pe(s, e);
1143
1116
  return t.execute(), t;
1144
1117
  }
1145
1118
  export {
1146
- v as AsyncState,
1147
- p as AtomError,
1119
+ P as AsyncState,
1120
+ b as AtomError,
1148
1121
  N as ComputedError,
1149
- k as DEBUG_CONFIG,
1150
- d as DEBUG_RUNTIME,
1151
- b as EffectError,
1122
+ B as DEBUG_CONFIG,
1123
+ E as DEBUG_RUNTIME,
1124
+ g as EffectError,
1152
1125
  be as POOL_CONFIG,
1153
- g as SCHEDULER_CONFIG,
1126
+ D as SCHEDULER_CONFIG,
1154
1127
  O as SchedulerError,
1155
- Ie as atom,
1128
+ ye as atom,
1156
1129
  Se as batch,
1157
- ye as computed,
1130
+ Ie as computed,
1158
1131
  me as effect,
1159
1132
  ue as isAtom,
1160
1133
  ge as isComputed,