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