@but212/atom-effect 0.19.1 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,17 +1,13 @@
1
- const tt = {
2
- ONE_SECOND_MS: 1e3
3
- }, k = {
1
+ const k = {
4
2
  IDLE: "idle",
5
3
  PENDING: "pending",
6
4
  RESOLVED: "resolved",
7
5
  REJECTED: "rejected"
8
- }, w = {
9
- DISPOSED: 1
10
6
  }, l = {
11
- ...w,
7
+ DISPOSED: 1,
12
8
  EXECUTING: 8
13
- }, o = {
14
- ...w,
9
+ }, q = {
10
+ DISPOSED: 1,
15
11
  /** Marker bit: identifies this node as a computed. */
16
12
  IS_COMPUTED: 2,
17
13
  DIRTY: 8,
@@ -21,15 +17,15 @@ const tt = {
21
17
  REJECTED: 128,
22
18
  RECOMPUTING: 256,
23
19
  HAS_ERROR: 512
24
- }, d = {
25
- ...w,
20
+ }, E = {
21
+ DISPOSED: 1,
26
22
  SYNC: 8,
27
23
  NOTIFICATION_SCHEDULED: 16
28
- }, It = {
24
+ }, St = {
29
25
  MAX_SIZE: 1e3,
30
26
  WARMUP_SIZE: 100,
31
27
  ENABLE_STATS: !1
32
- }, I = {
28
+ }, S = {
33
29
  // Infinite loop protection
34
30
  MAX_EXECUTIONS_PER_SECOND: 1e3,
35
31
  MAX_EXECUTIONS_PER_EFFECT: 100,
@@ -42,71 +38,71 @@ const tt = {
42
38
  BATCH_QUEUE_SHRINK_THRESHOLD: 1e3
43
39
  }, et = {
44
40
  WARN_INFINITE_LOOP: !0
45
- }, y = 1073741823, _ = typeof process < "u" && process.env && process.env.NODE_ENV !== "production" || typeof __DEV__ < "u" && !!__DEV__, st = Object.freeze([]);
46
- class T extends Error {
41
+ }, z = 1073741823, u = typeof process < "u" && process.env && process.env.NODE_ENV !== "production" || typeof __DEV__ < "u" && !!__DEV__, st = Object.freeze([]);
42
+ class O extends Error {
47
43
  constructor(t, e = null, s = !0) {
48
- super(t), this.cause = e, this.recoverable = s, this.timestamp = /* @__PURE__ */ new Date(), this.name = "AtomError";
44
+ super(t), this.cause = e, this.recoverable = s, this.name = "AtomError";
49
45
  }
50
46
  }
51
- class p extends T {
47
+ class d extends O {
52
48
  constructor(t, e = null) {
53
49
  super(t, e, !0), this.name = "ComputedError";
54
50
  }
55
51
  }
56
- class S extends T {
52
+ class I extends O {
57
53
  constructor(t, e = null) {
58
54
  super(t, e, !1), this.name = "EffectError";
59
55
  }
60
56
  }
61
- class b extends T {
57
+ class L extends O {
62
58
  constructor(t, e = null) {
63
59
  super(t, e, !1), this.name = "SchedulerError";
64
60
  }
65
61
  }
66
- const z = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), it = /* @__PURE__ */ Symbol("AtomEffect.Id"), G = /* @__PURE__ */ Symbol("AtomEffect.Type"), x = /* @__PURE__ */ Symbol("AtomEffect.NoDefaultValue"), nt = (i) => "dependencies" in i && Array.isArray(i.dependencies);
67
- function Q(i, t, e) {
62
+ const X = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), it = /* @__PURE__ */ Symbol("AtomEffect.Id"), G = /* @__PURE__ */ Symbol("AtomEffect.Type"), v = /* @__PURE__ */ Symbol("AtomEffect.NoDefaultValue"), nt = (i) => "dependencies" in i && Array.isArray(i.dependencies);
63
+ function $(i, t, e) {
68
64
  if (i === t)
69
- throw new p(
65
+ throw new d(
70
66
  "Circular dependency detected: The computation refers to itself explicitly or implicitly."
71
67
  );
72
68
  if (!e.has(i.id) && (e.add(i.id), nt(i))) {
73
69
  const s = i.dependencies;
74
70
  for (let n = 0; n < s.length; n++) {
75
71
  const r = s[n];
76
- r && Q(r, t, e);
72
+ r && $(r, t, e);
77
73
  }
78
74
  }
79
75
  }
80
- const g = {
76
+ const D = {
81
77
  // Dev mode flag
82
- enabled: _,
78
+ enabled: u,
83
79
  warnInfiniteLoop: et.WARN_INFINITE_LOOP,
84
80
  warn(i, t) {
85
- _ && this.enabled && i && console.warn(`[Atom Effect] ${t}`);
81
+ u && this.enabled && i && console.warn(`[Atom Effect] ${t}`);
86
82
  },
87
83
  checkCircular(i, t) {
88
84
  if (i === t)
89
- throw new p("Direct circular dependency detected");
90
- _ && this.enabled && Q(i, t, /* @__PURE__ */ new Set());
85
+ throw new d("Direct circular dependency detected");
86
+ u && this.enabled && $(i, t, /* @__PURE__ */ new Set());
91
87
  },
92
88
  attachDebugInfo(i, t, e) {
93
- if (!_ || !this.enabled) return;
89
+ if (!u || !this.enabled) return;
94
90
  const s = i;
95
- s[z] = `${t}_${e}`, s[it] = e, s[G] = t;
91
+ s[X] = `${t}_${e}`, s[it] = e, s[G] = t;
96
92
  },
97
- getDebugName: (i) => i?.[z],
93
+ getDebugName: (i) => i?.[X],
98
94
  getDebugType: (i) => i?.[G]
99
95
  };
100
96
  let rt = 1;
101
97
  const ot = () => rt++;
102
- function j(i, t, e) {
98
+ function K(i, t, e) {
103
99
  if (typeof t == "function") {
104
100
  const n = t;
105
- for (let r = 0, h = e.length; r < h; r++) {
106
- const c = e[r];
107
- if (c && c.fn === n) return;
101
+ for (let r = 0, o = e.length; r < o; r++) {
102
+ const h = e[r];
103
+ if (h && h.fn === n) return;
108
104
  }
109
- e.push(new P(n, void 0));
105
+ e.push(new M(n, void 0));
110
106
  return;
111
107
  }
112
108
  if ("addDependency" in t) {
@@ -115,37 +111,37 @@ function j(i, t, e) {
115
111
  }
116
112
  const s = t;
117
113
  for (let n = 0, r = e.length; n < r; n++) {
118
- const h = e[n];
119
- if (h && h.sub === s) return;
114
+ const o = e[n];
115
+ if (o && o.sub === s) return;
120
116
  }
121
- e.push(new P(void 0, s));
117
+ e.push(new M(void 0, s));
122
118
  }
123
- function ht(i, t, e) {
119
+ function Q(i, t, e) {
124
120
  const s = /* @__PURE__ */ new Map();
125
121
  for (let n = 0, r = t.length; n < r; n++) {
126
- const h = t[n];
127
- h?.unsub && (s.set(h.node, h.unsub), h.unsub = void 0);
122
+ const o = t[n];
123
+ o?.unsub && s.set(o.node, o.unsub);
128
124
  }
129
125
  for (let n = 0, r = i.length; n < r; n++) {
130
- const h = i[n];
131
- if (!h) continue;
132
- const c = h.node, E = s.get(c);
133
- E !== void 0 ? (h.unsub = E, s.delete(c)) : (g.checkCircular(c, e), h.unsub = c.subscribe(e));
126
+ const o = i[n];
127
+ if (!o) continue;
128
+ const h = o.node, f = s.get(h);
129
+ f !== void 0 ? (o.unsub = f, s.delete(h)) : (D.checkCircular(h, e), o.unsub = h.subscribe(e));
134
130
  }
135
131
  for (const n of s.values())
136
132
  n();
137
133
  }
138
- class R {
134
+ class x {
139
135
  constructor(t, e, s = void 0) {
140
136
  this.node = t, this.version = e, this.unsub = s;
141
137
  }
142
138
  }
143
- class P {
139
+ class M {
144
140
  constructor(t, e) {
145
141
  this.fn = t, this.sub = e;
146
142
  }
147
143
  }
148
- const u = {
144
+ const c = {
149
145
  // Computed Errors
150
146
  COMPUTED_MUST_BE_FUNCTION: "Computed target must be a function",
151
147
  COMPUTED_ASYNC_PENDING_NO_DEFAULT: "Async computation pending with no default value",
@@ -168,40 +164,37 @@ const u = {
168
164
  // Effect frequency
169
165
  EFFECT_FREQUENCY_LIMIT_EXCEEDED: "Effect executed too frequently within 1 second. Suspected infinite loop."
170
166
  };
171
- function C(i, t, e) {
172
- if (i instanceof T)
167
+ function b(i, t, e) {
168
+ if (i instanceof O)
173
169
  return i;
174
- const s = i instanceof Error, n = s ? i.message : String(i), r = s ? i : void 0;
175
- let h = "Unexpected error";
176
- i instanceof TypeError ? h = "Type error" : i instanceof ReferenceError && (h = "Reference error");
177
- const c = `${h} (${e}): ${n}`;
178
- return new t(c, r);
170
+ const s = i instanceof Error, n = s ? i.message : String(i), r = s ? i : void 0, h = `${s ? i.constructor.name : "Unexpected error"} (${e}): ${n}`;
171
+ return new t(h, r);
179
172
  }
180
- class q {
173
+ class W {
181
174
  constructor() {
182
- this.flags = 0, this.version = 0, this._lastSeenEpoch = -1, this._modifiedAtEpoch = -1, this.id = ot() & y;
175
+ this.flags = 0, this.version = 0, this._lastSeenEpoch = -1, this.id = ot() & z;
183
176
  }
184
177
  }
185
- class $ extends q {
178
+ class J extends W {
186
179
  /**
187
180
  * Adds subscriber.
188
181
  */
189
182
  subscribe(t) {
190
183
  const e = typeof t == "function";
191
184
  if (!e && (!t || typeof t.execute != "function"))
192
- throw C(
185
+ throw b(
193
186
  new TypeError("Invalid subscriber"),
194
- T,
195
- u.ATOM_SUBSCRIBER_MUST_BE_FUNCTION
187
+ O,
188
+ c.ATOM_SUBSCRIBER_MUST_BE_FUNCTION
196
189
  );
197
190
  const s = this._subscribers;
198
- for (let r = 0, h = s.length; r < h; r++) {
199
- const c = s[r];
200
- if (c && (e ? c.fn === t : c.sub === t))
201
- return _ && console.warn("Duplicate subscription ignored."), () => {
191
+ for (let r = 0, o = s.length; r < o; r++) {
192
+ const h = s[r];
193
+ if (h && (e ? h.fn === t : h.sub === t))
194
+ return u && console.warn("Duplicate subscription ignored."), () => {
202
195
  };
203
196
  }
204
- const n = new P(
197
+ const n = new M(
205
198
  e ? t : void 0,
206
199
  e ? void 0 : t
207
200
  );
@@ -220,31 +213,32 @@ class $ extends q {
220
213
  if (this._subscribers.length === 0) return;
221
214
  const s = this._subscribers.slice(0), n = s.length;
222
215
  for (let r = 0; r < n; r++) {
223
- const h = s[r];
224
- if (h)
216
+ const o = s[r];
217
+ if (o)
225
218
  try {
226
- h.fn ? h.fn(t, e) : h.sub && h.sub.execute();
227
- } catch (c) {
228
- this._handleNotifyError(c);
219
+ o.fn ? o.fn(t, e) : o.sub && o.sub.execute();
220
+ } catch (h) {
221
+ this._handleNotifyError(h);
229
222
  }
230
223
  }
231
224
  }
232
225
  _handleNotifyError(t) {
233
- console.error(C(t, T, u.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED));
226
+ console.error(b(t, O, c.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED));
234
227
  }
235
228
  }
236
- let A = 0;
237
- const J = () => (A = A + 1 & y || 1, A), ct = () => A, v = (i) => i + 1 & y;
238
- let M = 0, B = 0, L = !1;
239
- function H() {
240
- return L ? (_ && console.warn("startFlush() called during flush - ignored"), !1) : (L = !0, M = M + 1 & y || 1, B = 0, !0);
229
+ let w = 0;
230
+ const V = () => (w = w + 1 & z || 1, w), B = (i) => i + 1 & z;
231
+ let H = 0, U = !1, Z = 0;
232
+ const ht = () => Z;
233
+ function Y() {
234
+ return U ? (u && console.warn("startFlush() called during flush - ignored"), !1) : (U = !0, Z = V(), H = 0, !0);
241
235
  }
242
- const X = () => {
243
- L = !1;
244
- }, ut = () => L ? ++B : 0;
245
- class _t {
236
+ const j = () => {
237
+ U = !1;
238
+ }, ct = () => U ? ++H : 0;
239
+ class ut {
246
240
  constructor() {
247
- this._queueBuffer = [[], []], this._bufferIndex = 0, this._size = 0, this._epoch = 0, this._isProcessing = !1, this._isBatching = !1, this._isFlushingSync = !1, this._batchDepth = 0, this._batchQueue = [], this._batchQueueSize = 0, this._maxFlushIterations = I.MAX_FLUSH_ITERATIONS, this.onOverflow = null, this._boundRunLoop = this._runLoop.bind(this);
241
+ this._queueBuffer = [[], []], this._bufferIndex = 0, this._size = 0, this._epoch = 0, this._isProcessing = !1, this._isBatching = !1, this._isFlushingSync = !1, this._batchDepth = 0, this._batchQueue = [], this._batchQueueSize = 0, this._maxFlushIterations = S.MAX_FLUSH_ITERATIONS, this.onOverflow = null, this._boundRunLoop = this._runLoop.bind(this);
248
242
  }
249
243
  get phase() {
250
244
  return this._isProcessing || this._isFlushingSync ? 2 : this._isBatching ? 1 : 0;
@@ -259,8 +253,8 @@ class _t {
259
253
  * Schedules job.
260
254
  */
261
255
  schedule(t) {
262
- if (_ && typeof t != "function")
263
- throw new b("Scheduler callback must be a function");
256
+ if (u && typeof t != "function")
257
+ throw new L("Scheduler callback must be a function");
264
258
  if (t._nextEpoch !== this._epoch) {
265
259
  if (t._nextEpoch = this._epoch, this._isBatching || this._isFlushingSync) {
266
260
  this._batchQueue[this._batchQueueSize++] = t;
@@ -281,19 +275,19 @@ class _t {
281
275
  _runLoop() {
282
276
  try {
283
277
  if (this._size === 0) return;
284
- const t = H();
285
- this._drainQueue(), t && X();
278
+ const t = Y();
279
+ this._drainQueue(), t && j();
286
280
  } finally {
287
281
  this._isProcessing = !1, this._size > 0 && !this._isBatching && this._flush();
288
282
  }
289
283
  }
290
284
  _flushSync() {
291
285
  this._isFlushingSync = !0;
292
- const t = H();
286
+ const t = Y();
293
287
  try {
294
288
  this._mergeBatchQueue(), this._drainQueue();
295
289
  } finally {
296
- this._isFlushingSync = !1, t && X();
290
+ this._isFlushingSync = !1, t && j();
297
291
  }
298
292
  }
299
293
  _mergeBatchQueue() {
@@ -301,10 +295,10 @@ class _t {
301
295
  const t = ++this._epoch, e = this._batchQueue, s = this._queueBuffer[this._bufferIndex];
302
296
  let n = this._size;
303
297
  for (let r = 0; r < this._batchQueueSize; r++) {
304
- const h = e[r];
305
- h._nextEpoch !== t && (h._nextEpoch = t, s[n++] = h);
298
+ const o = e[r];
299
+ o._nextEpoch !== t && (o._nextEpoch = t, s[n++] = o);
306
300
  }
307
- this._size = n, this._batchQueueSize = 0, e.length > I.BATCH_QUEUE_SHRINK_THRESHOLD && (e.length = 0);
301
+ this._size = n, this._batchQueueSize = 0, e.length > S.BATCH_QUEUE_SHRINK_THRESHOLD && (e.length = 0);
308
302
  }
309
303
  _drainQueue() {
310
304
  let t = 0;
@@ -323,15 +317,15 @@ class _t {
323
317
  try {
324
318
  e[n]();
325
319
  } catch (r) {
326
- console.error(new b("Error occurred during scheduler execution", r));
320
+ console.error(new L("Error occurred during scheduler execution", r));
327
321
  }
328
322
  e.length = 0;
329
323
  }
330
324
  _handleFlushOverflow() {
331
325
  const t = this._size + this._batchQueueSize;
332
326
  if (console.error(
333
- new b(
334
- u.SCHEDULER_FLUSH_OVERFLOW(this._maxFlushIterations, t)
327
+ new L(
328
+ c.SCHEDULER_FLUSH_OVERFLOW(this._maxFlushIterations, t)
335
329
  )
336
330
  ), this._size = 0, this._queueBuffer[this._bufferIndex].length = 0, this._batchQueueSize = 0, this.onOverflow)
337
331
  try {
@@ -344,20 +338,20 @@ class _t {
344
338
  }
345
339
  endBatch() {
346
340
  if (this._batchDepth === 0) {
347
- _ && console.warn("endBatch() called without matching startBatch(). Ignoring.");
341
+ u && console.warn("endBatch() called without matching startBatch(). Ignoring.");
348
342
  return;
349
343
  }
350
344
  --this._batchDepth === 0 && (this._flushSync(), this._isBatching = !1);
351
345
  }
352
346
  setMaxFlushIterations(t) {
353
- if (t < I.MIN_FLUSH_ITERATIONS)
354
- throw new b(
355
- `Max flush iterations must be at least ${I.MIN_FLUSH_ITERATIONS}`
347
+ if (t < S.MIN_FLUSH_ITERATIONS)
348
+ throw new L(
349
+ `Max flush iterations must be at least ${S.MIN_FLUSH_ITERATIONS}`
356
350
  );
357
351
  this._maxFlushIterations = t;
358
352
  }
359
353
  }
360
- const O = new _t(), f = {
354
+ const N = new ut(), a = {
361
355
  /** Active listener. */
362
356
  current: null,
363
357
  /**
@@ -378,34 +372,34 @@ const O = new _t(), f = {
378
372
  }
379
373
  };
380
374
  function Dt(i) {
381
- const t = f.current;
375
+ const t = a.current;
382
376
  if (t === null) return i();
383
- f.current = null;
377
+ a.current = null;
384
378
  try {
385
379
  return i();
386
380
  } finally {
387
- f.current = t;
381
+ a.current = t;
388
382
  }
389
383
  }
390
- class lt extends $ {
384
+ class lt extends J {
391
385
  constructor(t, e) {
392
- super(), this._pendingOldValue = void 0, this._notifyTask = void 0, this._subscribers = [], this._value = t, e && (this.flags |= d.SYNC), g.attachDebugInfo(this, "atom", this.id);
386
+ super(), this._pendingOldValue = void 0, this._notifyTask = void 0, this._subscribers = [], this._value = t, e && (this.flags |= E.SYNC), D.attachDebugInfo(this, "atom", this.id);
393
387
  }
394
388
  get value() {
395
- const t = f.current;
396
- return t && j(this, t, this._subscribers), this._value;
389
+ const t = a.current;
390
+ return t && K(this, t, this._subscribers), this._value;
397
391
  }
398
392
  set value(t) {
399
393
  const e = this._value;
400
394
  if (Object.is(e, t)) return;
401
- this._value = t, this.version = v(this.version);
395
+ this._value = t, this.version = B(this.version);
402
396
  const s = this.flags;
403
- if (!(this._subscribers.length === 0 || s & d.NOTIFICATION_SCHEDULED)) {
404
- if (this._pendingOldValue = e, this.flags = s | d.NOTIFICATION_SCHEDULED, s & d.SYNC && !O.isBatching) {
397
+ if (!(this._subscribers.length === 0 || s & E.NOTIFICATION_SCHEDULED)) {
398
+ if (this._pendingOldValue = e, this.flags = s | E.NOTIFICATION_SCHEDULED, s & E.SYNC && !N.isBatching) {
405
399
  this._flushNotifications();
406
400
  return;
407
401
  }
408
- this._notifyTask || (this._notifyTask = () => this._flushNotifications()), O.schedule(this._notifyTask);
402
+ this._notifyTask || (this._notifyTask = () => this._flushNotifications()), N.schedule(this._notifyTask);
409
403
  }
410
404
  }
411
405
  /**
@@ -413,7 +407,7 @@ class lt extends $ {
413
407
  */
414
408
  _flushNotifications() {
415
409
  const t = this.flags;
416
- if (!(t & d.NOTIFICATION_SCHEDULED) || t & d.DISPOSED)
410
+ if (!(t & E.NOTIFICATION_SCHEDULED) || t & E.DISPOSED)
417
411
  return;
418
412
  const e = this._pendingOldValue;
419
413
  this._pendingOldValue = void 0, this.flags &= -17, this._notifySubscribers(this._value, e);
@@ -422,20 +416,20 @@ class lt extends $ {
422
416
  return this._value;
423
417
  }
424
418
  dispose() {
425
- this.flags & d.DISPOSED || (this._subscribers.length = 0, this.flags |= d.DISPOSED, this._value = void 0, this._pendingOldValue = void 0, this._notifyTask = void 0);
419
+ this.flags & E.DISPOSED || (this._subscribers.length = 0, this.flags |= E.DISPOSED, this._value = void 0, this._pendingOldValue = void 0, this._notifyTask = void 0);
426
420
  }
427
421
  }
428
- function St(i, t = {}) {
422
+ function Ct(i, t = {}) {
429
423
  return new lt(i, t.sync ?? !1);
430
424
  }
431
- class at {
425
+ class _t {
432
426
  /**
433
427
  * @param limit - Max unique arrays to hold (default: 50). Prevents the pool itself from consuming too much memory.
434
428
  * @param capacity - Max length of an array to accept (default: 256).
435
429
  * @param enableStats - Force-enable stats even in production (default: false).
436
430
  */
437
431
  constructor(t = 50, e = 256, s = !1) {
438
- this.limit = t, this.capacity = e, this.pool = [], this.stats = null, this.stats = _ || s ? {
432
+ this.limit = t, this.capacity = e, this.pool = [], this.stats = null, this.stats = u || s ? {
439
433
  acquired: 0,
440
434
  released: 0,
441
435
  rejected: { frozen: 0, tooLarge: 0, poolFull: 0 }
@@ -495,63 +489,59 @@ class at {
495
489
  });
496
490
  }
497
491
  }
498
- const N = (i) => Object.freeze(i);
499
- N([]);
500
- N([]);
501
- N([]);
502
- N([]);
503
- const a = N([]), D = new at();
504
- function ft(i) {
492
+ const _ = Object.freeze(
493
+ []
494
+ ), p = new _t();
495
+ function at(i) {
505
496
  return i !== null && typeof i == "object" && "value" in i && typeof i.subscribe == "function";
506
497
  }
507
- function gt(i) {
508
- return ft(i) && typeof i.invalidate == "function";
498
+ function Tt(i) {
499
+ return at(i) && typeof i.invalidate == "function";
509
500
  }
510
- function Ct(i) {
501
+ function bt(i) {
511
502
  return i !== null && typeof i == "object" && typeof i.dispose == "function" && typeof i.run == "function";
512
503
  }
513
- function K(i) {
504
+ function tt(i) {
514
505
  return i !== null && typeof i == "object" && typeof i.then == "function";
515
506
  }
516
- const W = o.RESOLVED | o.PENDING | o.REJECTED, m = Array(W + 1).fill(k.IDLE);
517
- m[o.RESOLVED] = k.RESOLVED;
518
- m[o.PENDING] = k.PENDING;
519
- m[o.REJECTED] = k.REJECTED;
520
- const Et = 3, Y = Number.MAX_SAFE_INTEGER - 1, dt = o.REJECTED | o.HAS_ERROR;
521
- class Z extends $ {
507
+ const ft = 3, Et = Number.MAX_SAFE_INTEGER - 1, { IDLE: F, DIRTY: T, PENDING: R, RESOLVED: g, REJECTED: A, HAS_ERROR: m, RECOMPUTING: y, DISPOSED: P, IS_COMPUTED: dt } = q;
508
+ function pt(i) {
509
+ return i & g ? k.RESOLVED : i & R ? k.PENDING : i & A ? k.REJECTED : k.IDLE;
510
+ }
511
+ class It extends J {
522
512
  constructor(t, e = {}) {
523
- if (typeof t != "function") throw new p(u.COMPUTED_MUST_BE_FUNCTION);
524
- super(), this._error = null, this._promiseId = 0, this._subscribers = [], this._links = a, this._cachedErrors = null, this._errorCacheEpoch = -1, this._asyncStartAggregateVersion = 0, this._asyncRetryCount = 0, this._errorDepCount = 0, this._trackEpoch = -1, this._trackLinks = a, this._trackCount = 0, this._value = void 0, this.flags = o.IS_COMPUTED | o.DIRTY | o.IDLE, this._equal = e.equal ?? Object.is, this._fn = t, this._defaultValue = "defaultValue" in e ? e.defaultValue : x, this._onError = e.onError ?? null;
513
+ if (typeof t != "function") throw new d(c.COMPUTED_MUST_BE_FUNCTION);
514
+ super(), this._error = null, this._promiseId = 0, this._subscribers = [], this._links = _, this._asyncStartAggregateVersion = 0, this._asyncRetryCount = 0, this._trackEpoch = -1, this._trackLinks = _, this._trackCount = 0, this._value = void 0, this.flags = dt | T | F, this._equal = e.equal ?? Object.is, this._fn = t, this._defaultValue = "defaultValue" in e ? e.defaultValue : v, this._onError = e.onError ?? null;
525
515
  const s = e.maxAsyncRetries;
526
- if (this._maxAsyncRetries = s != null && s >= 0 ? s : Et, g.attachDebugInfo(this, "computed", this.id), e.lazy === !1)
516
+ if (this._maxAsyncRetries = s != null && s >= 0 ? s : ft, D.attachDebugInfo(this, "computed", this.id), e.lazy === !1)
527
517
  try {
528
518
  this._recompute();
529
519
  } catch {
530
520
  }
531
521
  }
532
522
  _track() {
533
- const t = f.current;
534
- t && j(this, t, this._subscribers);
523
+ const t = a.current;
524
+ t && K(this, t, this._subscribers);
535
525
  }
536
526
  get value() {
537
527
  this._track();
538
528
  const t = this.flags;
539
- if ((t & (o.RESOLVED | o.DIRTY | o.IDLE)) === o.RESOLVED)
529
+ if ((t & (g | T | F)) === g)
540
530
  return this._value;
541
- if (t & o.DISPOSED)
542
- throw new p(u.COMPUTED_DISPOSED);
543
- if (t & o.RECOMPUTING) {
544
- if (this._defaultValue !== x) return this._defaultValue;
545
- throw new p(u.COMPUTED_CIRCULAR_DEPENDENCY);
531
+ if (t & P)
532
+ throw new d(c.COMPUTED_DISPOSED);
533
+ if (t & y) {
534
+ if (this._defaultValue !== v) return this._defaultValue;
535
+ throw new d(c.COMPUTED_CIRCULAR_DEPENDENCY);
546
536
  }
547
- if (t & (o.DIRTY | o.IDLE) && (this._recompute(), this.flags & o.RESOLVED))
537
+ if (t & (T | F) && (this._recompute(), this.flags & g))
548
538
  return this._value;
549
- const e = this._defaultValue, s = e !== x;
550
- if (this.flags & o.PENDING) {
539
+ const e = this._defaultValue, s = e !== v;
540
+ if (this.flags & R) {
551
541
  if (s) return e;
552
- throw new p(u.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
542
+ throw new d(c.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
553
543
  }
554
- if (this.flags & o.REJECTED) {
544
+ if (this.flags & A) {
555
545
  if (this._error?.recoverable && s) return e;
556
546
  throw this._error;
557
547
  }
@@ -561,65 +551,61 @@ class Z extends $ {
561
551
  return this._value;
562
552
  }
563
553
  get state() {
564
- return this._track(), m[this.flags & W];
554
+ return this._track(), pt(this.flags);
565
555
  }
566
556
  get hasError() {
567
- if (this._track(), this.flags & (o.REJECTED | o.HAS_ERROR) || this._errorDepCount > 0) return !0;
557
+ if (this._track(), this.flags & (A | m)) return !0;
568
558
  const t = this._links;
569
559
  for (let e = 0, s = t.length; e < s; e++) {
570
560
  const n = t[e]?.node;
571
- if (n && n.flags & o.HAS_ERROR) return !0;
561
+ if (n && n.flags & m) return !0;
572
562
  }
573
563
  return !1;
574
564
  }
575
- // ... (isValid, errors, lastError getters remain structurally similar, omitted for brevity if mostly unchanged) ...
576
565
  get isValid() {
577
566
  return !this.hasError;
578
567
  }
579
568
  get errors() {
580
569
  if (this._track(), !this.hasError) return st;
581
- const t = ct();
582
- if (this._errorCacheEpoch === t && this._cachedErrors) return this._cachedErrors;
583
- const e = [];
584
- this._error && e.push(this._error);
585
- const s = this._links;
586
- for (let r = 0, h = s.length; r < h; r++) {
587
- const c = s[r].node;
588
- if (c.flags & o.HAS_ERROR) {
589
- const E = c;
590
- if (E.errors) {
591
- const V = E.errors;
592
- for (let F = 0; F < V.length; F++) {
593
- const U = V[F];
594
- U && e.indexOf(U) === -1 && e.push(U);
570
+ const t = [];
571
+ this._error && t.push(this._error);
572
+ const e = this._links;
573
+ for (let s = 0, n = e.length; s < n; s++) {
574
+ const r = e[s].node;
575
+ if (r.flags & m) {
576
+ const o = r;
577
+ if (o.errors) {
578
+ const h = o.errors;
579
+ for (let f = 0; f < h.length; f++) {
580
+ const C = h[f];
581
+ C && t.indexOf(C) === -1 && t.push(C);
595
582
  }
596
583
  }
597
584
  }
598
585
  }
599
- const n = Object.freeze(e);
600
- return this._errorCacheEpoch = t, this._cachedErrors = n, n;
586
+ return Object.freeze(t);
601
587
  }
602
588
  get lastError() {
603
589
  return this._track(), this._error;
604
590
  }
605
591
  get isPending() {
606
- return this._track(), (this.flags & o.PENDING) !== 0;
592
+ return this._track(), (this.flags & R) !== 0;
607
593
  }
608
594
  get isResolved() {
609
- return this._track(), (this.flags & o.RESOLVED) !== 0;
595
+ return this._track(), (this.flags & g) !== 0;
610
596
  }
611
597
  invalidate() {
612
- this._markDirty(), this._errorCacheEpoch = -1, this._cachedErrors = null;
598
+ this._markDirty();
613
599
  }
614
600
  dispose() {
615
- if (this.flags & o.DISPOSED) return;
601
+ if (this.flags & P) return;
616
602
  const t = this._links;
617
- if (t !== a) {
603
+ if (t !== _) {
618
604
  for (let e = 0, s = t.length; e < s; e++)
619
605
  t[e].unsub?.();
620
- D.release(t), this._links = a;
606
+ p.release(t), this._links = _;
621
607
  }
622
- this._subscribers.length = 0, this.flags = o.DISPOSED | o.DIRTY | o.IDLE, this._error = null, this._value = void 0, this._promiseId = (this._promiseId + 1) % Y, this._cachedErrors = null, this._errorCacheEpoch = -1;
608
+ this._subscribers.length = 0, this.flags = P | T | F, this._error = null, this._value = void 0;
623
609
  }
624
610
  addDependency(t) {
625
611
  if (t._lastSeenEpoch !== this._trackEpoch) {
@@ -627,131 +613,120 @@ class Z extends $ {
627
613
  const e = this._trackLinks[this._trackCount];
628
614
  e.node = t, e.version = t.version;
629
615
  } else
630
- this._trackLinks.push(new R(t, t.version));
616
+ this._trackLinks.push(new x(t, t.version));
631
617
  this._trackCount++;
632
618
  }
633
619
  }
634
- _commitDeps(t) {
635
- this._trackLinks.length = this._trackCount, ht(this._trackLinks, t, this), this._links = this._trackLinks;
636
- }
637
- _updateErrorDepCount() {
638
- let t = 0;
639
- const e = this._links;
640
- for (let s = 0, n = e.length; s < n; s++) {
641
- const r = e[s]?.node;
642
- r && r.flags & o.HAS_ERROR && t++;
643
- }
644
- this._errorDepCount = t;
645
- }
646
620
  _recompute() {
647
- if (this.flags & o.RECOMPUTING) return;
648
- this.flags |= o.RECOMPUTING;
621
+ if (this.flags & y) return;
622
+ this.flags |= y;
649
623
  const t = this._links;
650
- this._trackEpoch = J(), this._trackLinks = D.acquire(), this._trackCount = 0;
624
+ this._trackEpoch = V(), this._trackLinks = p.acquire(), this._trackCount = 0;
651
625
  let e = !1;
652
626
  try {
653
- const s = f.run(this, this._fn);
654
- this._commitDeps(t), e = !0, this._updateErrorDepCount(), K(s) ? this._handleAsyncComputation(s) : this._finalizeResolution(s);
627
+ const s = a.run(this, this._fn);
628
+ this._trackLinks.length = this._trackCount, Q(this._trackLinks, t, this), this._links = this._trackLinks, e = !0, tt(s) ? this._handleAsyncComputation(s) : this._finalizeResolution(s);
655
629
  } catch (s) {
656
630
  if (!e)
657
631
  try {
658
- this._commitDeps(t), e = !0, this._updateErrorDepCount();
632
+ this._trackLinks.length = this._trackCount, Q(this._trackLinks, t, this), this._links = this._trackLinks, e = !0;
659
633
  } catch (n) {
660
- _ && console.warn("[atom-effect] _commitDeps failed during error recovery:", n);
634
+ u && console.warn("[atom-effect] _commitDeps failed during error recovery:", n);
661
635
  }
662
- this._handleError(s, u.COMPUTED_COMPUTATION_FAILED, !0);
636
+ this._handleError(s, c.COMPUTED_COMPUTATION_FAILED, !0);
663
637
  } finally {
664
- e && t !== a ? D.release(t) : e || D.release(this._trackLinks), this._trackEpoch = -1, this._trackLinks = a, this._trackCount = 0, this.flags &= -257;
638
+ e && t !== _ ? p.release(t) : e || p.release(this._trackLinks), this._trackEpoch = -1, this._trackLinks = _, this._trackCount = 0, this.flags &= ~y;
665
639
  }
666
640
  }
667
641
  _handleAsyncComputation(t) {
668
- this.flags = (this.flags | o.PENDING) & -217, this._notifySubscribers(void 0, void 0), this._asyncStartAggregateVersion = this._captureVersionSnapshot(), this._asyncRetryCount = 0, this._promiseId = (this._promiseId + 1) % Y;
642
+ this.flags = (this.flags | R) & -217, this._notifySubscribers(void 0, void 0), this._asyncStartAggregateVersion = this._captureVersionSnapshot(), this._asyncRetryCount = 0, this._promiseId = (this._promiseId + 1) % Et;
669
643
  const e = this._promiseId;
670
644
  t.then(
671
645
  (s) => {
672
646
  if (e === this._promiseId) {
673
647
  if (this._captureVersionSnapshot() !== this._asyncStartAggregateVersion)
674
648
  return this._asyncRetryCount++ < this._maxAsyncRetries ? this._markDirty() : this._handleError(
675
- new p(
649
+ new d(
676
650
  `Async drift threshold exceeded after ${this._maxAsyncRetries} retries.`
677
651
  ),
678
- u.COMPUTED_ASYNC_COMPUTATION_FAILED
652
+ c.COMPUTED_ASYNC_COMPUTATION_FAILED
679
653
  );
680
654
  this._finalizeResolution(s), this._notifySubscribers(s, void 0);
681
655
  }
682
656
  },
683
- (s) => e === this._promiseId && this._handleError(s, u.COMPUTED_ASYNC_COMPUTATION_FAILED)
657
+ (s) => e === this._promiseId && this._handleError(s, c.COMPUTED_ASYNC_COMPUTATION_FAILED)
684
658
  );
685
659
  }
686
660
  _captureVersionSnapshot() {
687
661
  let t = 0;
688
662
  const e = this._links;
689
663
  for (let s = 0, n = e.length; s < n; s++)
690
- t = ((t << 5) - t | 0) + e[s].node.version & y;
664
+ t += e[s].node.version;
691
665
  return t;
692
666
  }
693
667
  _handleError(t, e, s = !1) {
694
- const n = C(t, p, e);
695
- if (!s && !(this.flags & o.REJECTED) && (this.version = v(this.version)), this._error = n, this.flags = this.flags & -121 | dt, this._onError)
668
+ const n = b(t, d, e);
669
+ if (!s && !(this.flags & A) && (this.version = B(this.version)), this._error = n, this.flags = this.flags & -121 | A | m, this._onError)
696
670
  try {
697
671
  this._onError(n);
698
672
  } catch (r) {
699
- console.error(u.CALLBACK_ERROR_IN_ERROR_HANDLER, r);
673
+ console.error(c.CALLBACK_ERROR_IN_ERROR_HANDLER, r);
700
674
  }
701
675
  if (s) throw n;
702
676
  this._notifySubscribers(void 0, void 0);
703
677
  }
704
678
  _finalizeResolution(t) {
705
- (!(this.flags & o.RESOLVED) || !this._equal(this._value, t)) && (this.version = v(this.version)), this._value = t, this._error = null, this.flags = (this.flags | o.RESOLVED) & -697, this._cachedErrors = null, this._errorCacheEpoch = -1;
679
+ (!(this.flags & g) || !this._equal(this._value, t)) && (this.version = B(this.version)), this._value = t, this._error = null, this.flags = (this.flags | g) & -697;
706
680
  }
707
681
  execute() {
708
682
  this._markDirty();
709
683
  }
710
684
  /** @internal */
711
685
  _markDirty() {
712
- this.flags & (o.RECOMPUTING | o.DIRTY) || (this.flags |= o.DIRTY, this._notifySubscribers(void 0, void 0));
686
+ this.flags & (y | T) || (this.flags |= T, this._notifySubscribers(void 0, void 0));
713
687
  }
714
688
  }
715
- Object.freeze(Z.prototype);
716
- function Tt(i, t = {}) {
717
- return new Z(i, t);
689
+ function Ot(i, t = {}) {
690
+ return new It(i, t);
718
691
  }
719
- class pt extends q {
692
+ class gt extends W {
720
693
  constructor(t, e = {}) {
721
- super(), this._cleanup = null, this._links = a, this._nextLinks = null, this._parkedUnsubs = null, this._currentEpoch = -1, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._executionCount = 0, this._historyPtr = 0, this._execId = 0, this._fn = t, this._onError = e.onError ?? null, this._sync = e.sync ?? !1, this._maxExecutions = e.maxExecutionsPerSecond ?? I.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = e.maxExecutionsPerFlush ?? I.MAX_EXECUTIONS_PER_EFFECT, this._trackModifications = e.trackModifications ?? !1;
722
- const s = Number.isFinite(this._maxExecutions), n = s ? Math.min(this._maxExecutions + 1, I.MAX_EXECUTIONS_PER_SECOND + 1) : 0;
723
- this._historyCapacity = n, this._history = _ && s && n > 0 ? new Array(n).fill(0) : null, g.attachDebugInfo(this, "effect", this.id);
694
+ super(), this._cleanup = null, this._links = _, this._nextLinks = null, this._prevLinks = null, this._currentEpoch = -1, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._executionCount = 0, this._windowStart = 0, this._windowCount = 0, this._execId = 0, this._fn = t, this._onError = e.onError ?? null, this._sync = e.sync ?? !1, this._maxExecutions = e.maxExecutionsPerSecond ?? S.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = e.maxExecutionsPerFlush ?? S.MAX_EXECUTIONS_PER_EFFECT, this._trackModifications = e.trackModifications ?? !1, D.attachDebugInfo(this, "effect", this.id);
724
695
  }
725
696
  run() {
726
697
  if (this.flags & l.DISPOSED)
727
- throw new S(u.EFFECT_DISPOSED);
698
+ throw new I(c.EFFECT_DISPOSED);
728
699
  this.execute(!0);
729
700
  }
730
701
  dispose() {
731
- this.flags & l.DISPOSED || (this.flags |= l.DISPOSED, this._execCleanup(), this._releaseLinks(this._links), this._links = a, this._executeTask = void 0);
702
+ this.flags & l.DISPOSED || (this.flags |= l.DISPOSED, this._execCleanup(), this._unsubLinks(this._links), this._links !== _ && p.release(this._links), this._links = _, this._executeTask = void 0);
732
703
  }
733
704
  addDependency(t) {
734
705
  if (!(this.flags & l.EXECUTING) || t._lastSeenEpoch === this._currentEpoch) return;
735
706
  t._lastSeenEpoch = this._currentEpoch;
736
- const e = this._nextLinks, s = this._parkedUnsubs?.get(t);
737
- if (s) {
738
- e.push(new R(t, t.version, s)), this._parkedUnsubs.delete(t);
739
- return;
740
- }
707
+ const e = this._nextLinks, s = this._prevLinks;
708
+ if (s)
709
+ for (let n = 0, r = s.length; n < r; n++) {
710
+ const o = s[n];
711
+ if (o && o.node === t && o.unsub) {
712
+ e.push(new x(t, t.version, o.unsub)), o.unsub = void 0;
713
+ return;
714
+ }
715
+ }
741
716
  try {
742
717
  const n = t.subscribe(() => {
743
718
  if (this._trackModifications && this.flags & l.EXECUTING && (t._modifiedAtEpoch = this._currentEpoch), this._sync) return this.execute();
744
- this._executeTask || (this._executeTask = () => this.execute()), O.schedule(this._executeTask);
719
+ this._executeTask || (this._executeTask = () => this.execute()), N.schedule(this._executeTask);
745
720
  });
746
- e.push(new R(t, t.version, n));
721
+ e.push(new x(t, t.version, n));
747
722
  } catch (n) {
748
- const r = C(n, S, u.EFFECT_EXECUTION_FAILED);
723
+ const r = b(n, I, c.EFFECT_EXECUTION_FAILED);
749
724
  if (console.error(r), this._onError)
750
725
  try {
751
726
  this._onError(r);
752
727
  } catch {
753
728
  }
754
- e.push(new R(t, t.version, void 0));
729
+ e.push(new x(t, t.version, void 0));
755
730
  }
756
731
  }
757
732
  /**
@@ -761,20 +736,23 @@ class pt extends q {
761
736
  if (this.flags & (l.DISPOSED | l.EXECUTING) || !t && this._links.length > 0 && !this._isDirty()) return;
762
737
  this._checkInfiniteLoops(), this.flags |= l.EXECUTING, this._execCleanup();
763
738
  const e = this._links;
764
- if (e !== a) {
765
- const r = /* @__PURE__ */ new Map();
766
- for (let h = 0, c = e.length; h < c; h++) {
767
- const E = e[h];
768
- E?.unsub && r.set(E.node, E.unsub);
769
- }
770
- this._parkedUnsubs = r;
771
- }
772
- const s = D.acquire();
773
- this._nextLinks = s, this._currentEpoch = J();
739
+ this._prevLinks = e !== _ ? e : null;
740
+ const s = p.acquire();
741
+ this._nextLinks = s, this._currentEpoch = V();
774
742
  let n = !1;
775
743
  try {
776
- const r = f.run(this, this._fn);
777
- this._links = s, n = !0, this._checkLoopWarnings(), K(r) ? this._handleAsyncResult(r) : this._cleanup = typeof r == "function" ? r : null;
744
+ const r = a.run(this, this._fn);
745
+ if (this._links = s, n = !0, this._trackModifications && D.enabled) {
746
+ const o = this._currentEpoch;
747
+ for (let h = 0, f = s.length; h < f; h++) {
748
+ const C = s[h].node;
749
+ C._modifiedAtEpoch === o && D.warn(
750
+ !0,
751
+ `Effect is reading a dependency (${D.getDebugName(C) || "unknown"}) that it just modified. Infinite loop may occur`
752
+ );
753
+ }
754
+ }
755
+ tt(r) ? this._handleAsyncResult(r) : this._cleanup = typeof r == "function" ? r : null;
778
756
  } catch (r) {
779
757
  n = !0, this._handleExecutionError(r), this._cleanup = null;
780
758
  } finally {
@@ -790,7 +768,7 @@ class pt extends q {
790
768
  try {
791
769
  s();
792
770
  } catch (n) {
793
- this._handleExecutionError(n, u.EFFECT_CLEANUP_FAILED);
771
+ this._handleExecutionError(n, c.EFFECT_CLEANUP_FAILED);
794
772
  }
795
773
  return;
796
774
  }
@@ -801,38 +779,36 @@ class pt extends q {
801
779
  }
802
780
  _finalizeDependencies(t, e, s) {
803
781
  if (this._nextLinks = null, t) {
804
- if (this._parkedUnsubs)
805
- for (const n of this._parkedUnsubs.values())
806
- n();
807
- e !== a && D.release(e);
782
+ const n = this._prevLinks;
783
+ if (n)
784
+ for (let r = 0, o = n.length; r < o; r++)
785
+ n[r]?.unsub?.();
786
+ e !== _ && p.release(e);
808
787
  } else
809
- this._releaseLinks(s), D.release(s);
810
- this._parkedUnsubs = null;
788
+ this._unsubLinks(s), p.release(s);
789
+ this._prevLinks = null;
811
790
  }
812
- _releaseLinks(t) {
813
- if (t !== a) {
814
- for (let e = 0, s = t.length; e < s; e++)
815
- t[e]?.unsub?.();
816
- D.release(t);
817
- }
791
+ _unsubLinks(t) {
792
+ for (let e = 0, s = t.length; e < s; e++)
793
+ t[e]?.unsub?.();
818
794
  }
819
795
  _isDirty() {
820
- const t = this._links, e = f.current;
821
- f.current = null;
796
+ const t = this._links, e = a.current;
797
+ a.current = null;
822
798
  try {
823
799
  for (let s = 0, n = t.length; s < n; s++) {
824
- const r = t[s], h = r.node;
825
- if (h.flags & o.IS_COMPUTED)
800
+ const r = t[s], o = r.node;
801
+ if (o.flags & q.IS_COMPUTED)
826
802
  try {
827
- h.value;
803
+ o.value;
828
804
  } catch {
829
- return _ && console.warn(`[atom-effect] Dependency #${h.id} threw during dirty check`), !0;
805
+ return u && console.warn(`[atom-effect] Dependency #${o.id} threw during dirty check`), !0;
830
806
  }
831
- if (h.version !== r.version) return !0;
807
+ if (o.version !== r.version) return !0;
832
808
  }
833
809
  return !1;
834
810
  } finally {
835
- f.current = e;
811
+ a.current = e;
836
812
  }
837
813
  }
838
814
  _execCleanup() {
@@ -840,20 +816,20 @@ class pt extends q {
840
816
  try {
841
817
  this._cleanup();
842
818
  } catch (t) {
843
- this._handleExecutionError(t, u.EFFECT_CLEANUP_FAILED);
819
+ this._handleExecutionError(t, c.EFFECT_CLEANUP_FAILED);
844
820
  }
845
821
  this._cleanup = null;
846
822
  }
847
823
  }
848
824
  _checkInfiniteLoops() {
849
- const t = M;
850
- if (this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), ut() > I.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++, this._history) {
825
+ const t = ht();
826
+ if (this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), ct() > S.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++, u && Number.isFinite(this._maxExecutions)) {
851
827
  const e = Date.now();
852
- this._history[this._historyPtr] = e, this._historyPtr = (this._historyPtr + 1) % this._historyCapacity;
853
- const s = this._history[this._historyPtr] || 0;
854
- if (s > 0 && e - s < tt.ONE_SECOND_MS) {
855
- const n = new S(u.EFFECT_FREQUENCY_LIMIT_EXCEEDED);
856
- if (this.dispose(), this._handleExecutionError(n), _) throw n;
828
+ if (e - this._windowStart >= 1e3)
829
+ this._windowStart = e, this._windowCount = 1;
830
+ else if (++this._windowCount > this._maxExecutions) {
831
+ const s = new I(c.EFFECT_FREQUENCY_LIMIT_EXCEEDED);
832
+ throw this.dispose(), this._handleExecutionError(s), s;
857
833
  }
858
834
  }
859
835
  }
@@ -867,67 +843,55 @@ class pt extends q {
867
843
  return (this.flags & l.EXECUTING) !== 0;
868
844
  }
869
845
  _throwInfiniteLoopError(t) {
870
- const e = new S(
871
- `Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${B}`
846
+ const e = new I(
847
+ `Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${H}`
872
848
  );
873
849
  throw this.dispose(), console.error(e), e;
874
850
  }
875
- _handleExecutionError(t, e = u.EFFECT_EXECUTION_FAILED) {
876
- const s = C(t, S, e);
851
+ _handleExecutionError(t, e = c.EFFECT_EXECUTION_FAILED) {
852
+ const s = b(t, I, e);
877
853
  if (console.error(s), this._onError)
878
854
  try {
879
855
  this._onError(s);
880
856
  } catch (n) {
881
- console.error(C(n, S, u.CALLBACK_ERROR_IN_ERROR_HANDLER));
857
+ console.error(b(n, I, c.CALLBACK_ERROR_IN_ERROR_HANDLER));
882
858
  }
883
859
  }
884
- _checkLoopWarnings() {
885
- if (this._trackModifications && g.enabled) {
886
- const t = this._currentEpoch, e = this._links;
887
- for (let s = 0, n = e.length; s < n; s++) {
888
- const r = e[s].node;
889
- r._modifiedAtEpoch === t && g.warn(
890
- !0,
891
- `Effect is reading a dependency (${g.getDebugName(r) || "unknown"}) that it just modified. Infinite loop may occur`
892
- );
893
- }
894
- }
895
- }
896
860
  }
897
- function Ot(i, t = {}) {
861
+ function yt(i, t = {}) {
898
862
  if (typeof i != "function")
899
- throw new S(u.EFFECT_MUST_BE_FUNCTION);
900
- const e = new pt(i, t);
863
+ throw new I(c.EFFECT_MUST_BE_FUNCTION);
864
+ const e = new gt(i, t);
901
865
  return e.execute(), e;
902
866
  }
903
- function yt(i) {
867
+ function At(i) {
904
868
  if (typeof i != "function")
905
869
  throw new TypeError("Batch callback must be a function");
906
- O.startBatch();
870
+ N.startBatch();
907
871
  try {
908
872
  return i();
909
873
  } finally {
910
- O.endBatch();
874
+ N.endBatch();
911
875
  }
912
876
  }
913
877
  export {
914
878
  k as AsyncState,
915
- T as AtomError,
916
- p as ComputedError,
879
+ O as AtomError,
880
+ d as ComputedError,
917
881
  et as DEBUG_CONFIG,
918
- g as DEBUG_RUNTIME,
919
- S as EffectError,
920
- It as POOL_CONFIG,
921
- I as SCHEDULER_CONFIG,
922
- b as SchedulerError,
923
- St as atom,
924
- yt as batch,
925
- Tt as computed,
926
- Ot as effect,
927
- ft as isAtom,
928
- gt as isComputed,
929
- Ct as isEffect,
930
- O as scheduler,
882
+ D as DEBUG_RUNTIME,
883
+ I as EffectError,
884
+ St as POOL_CONFIG,
885
+ S as SCHEDULER_CONFIG,
886
+ L as SchedulerError,
887
+ Ct as atom,
888
+ At as batch,
889
+ Ot as computed,
890
+ yt as effect,
891
+ at as isAtom,
892
+ Tt as isComputed,
893
+ bt as isEffect,
894
+ N as scheduler,
931
895
  Dt as untracked
932
896
  };
933
897
  //# sourceMappingURL=index.mjs.map