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