@but212/atom-effect 0.5.1 → 0.7.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/atom-effect.min.js +2 -0
- package/dist/atom-effect.min.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.mjs +246 -202
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -1
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const
|
|
1
|
+
const te = {
|
|
2
2
|
/** One second in milliseconds */
|
|
3
3
|
ONE_SECOND_MS: 1e3
|
|
4
|
-
},
|
|
4
|
+
}, v = {
|
|
5
5
|
IDLE: "idle",
|
|
6
6
|
PENDING: "pending",
|
|
7
7
|
RESOLVED: "resolved",
|
|
@@ -11,7 +11,7 @@ const Z = {
|
|
|
11
11
|
// 0001 - Effect has been disposed
|
|
12
12
|
EXECUTING: 2
|
|
13
13
|
// 0010 - Effect is currently executing
|
|
14
|
-
},
|
|
14
|
+
}, c = {
|
|
15
15
|
DIRTY: 1,
|
|
16
16
|
// 0001 - Needs recomputation
|
|
17
17
|
IDLE: 2,
|
|
@@ -26,7 +26,7 @@ const Z = {
|
|
|
26
26
|
// 100000 - Currently recomputing
|
|
27
27
|
HAS_ERROR: 64
|
|
28
28
|
// 1000000 - Has error state
|
|
29
|
-
},
|
|
29
|
+
}, pe = {
|
|
30
30
|
/** Maximum number of pooled objects to prevent memory bloat */
|
|
31
31
|
MAX_SIZE: 1e3,
|
|
32
32
|
/** Number of objects to pre-allocate for performance-critical paths */
|
|
@@ -50,13 +50,13 @@ const Z = {
|
|
|
50
50
|
MAX_FLUSH_ITERATIONS: 1e3,
|
|
51
51
|
/** Minimum allowed value for max flush iterations */
|
|
52
52
|
MIN_FLUSH_ITERATIONS: 10
|
|
53
|
-
},
|
|
53
|
+
}, k = {
|
|
54
54
|
/** Maximum dependencies before warning about large dependency graphs */
|
|
55
55
|
MAX_DEPENDENCIES: 1e3,
|
|
56
56
|
/** Enable infinite loop detection warnings */
|
|
57
57
|
WARN_INFINITE_LOOP: !0
|
|
58
|
-
},
|
|
59
|
-
class
|
|
58
|
+
}, I = 1073741823, a = typeof process < "u" && process.env && process.env.NODE_ENV !== "production", se = Object.freeze([]);
|
|
59
|
+
class p extends Error {
|
|
60
60
|
/**
|
|
61
61
|
* Creates a new AtomError
|
|
62
62
|
* @param message - Error message describing what went wrong
|
|
@@ -67,7 +67,7 @@ class E extends Error {
|
|
|
67
67
|
super(e), this.name = "AtomError", this.cause = t, this.recoverable = s, this.timestamp = /* @__PURE__ */ new Date();
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
class
|
|
70
|
+
class N extends p {
|
|
71
71
|
/**
|
|
72
72
|
* Creates a new ComputedError
|
|
73
73
|
* @param message - Error message
|
|
@@ -77,7 +77,7 @@ class m extends E {
|
|
|
77
77
|
super(e, t, !0), this.name = "ComputedError";
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
-
class b extends
|
|
80
|
+
class b extends p {
|
|
81
81
|
/**
|
|
82
82
|
* Creates a new EffectError
|
|
83
83
|
* @param message - Error message
|
|
@@ -87,7 +87,7 @@ class b extends E {
|
|
|
87
87
|
super(e, t, !1), this.name = "EffectError";
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
class
|
|
90
|
+
class O extends p {
|
|
91
91
|
/**
|
|
92
92
|
* Creates a new SchedulerError
|
|
93
93
|
* @param message - Error message
|
|
@@ -97,7 +97,7 @@ class U extends E {
|
|
|
97
97
|
super(e, t, !1), this.name = "SchedulerError";
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
const
|
|
100
|
+
const h = {
|
|
101
101
|
// ─────────────────────────────────────────────────────────────────
|
|
102
102
|
// Computed errors
|
|
103
103
|
// ─────────────────────────────────────────────────────────────────
|
|
@@ -181,28 +181,28 @@ const c = {
|
|
|
181
181
|
* @remarks This prevents cascading failures from masking the original error.
|
|
182
182
|
*/
|
|
183
183
|
CALLBACK_ERROR_IN_ERROR_HANDLER: "Error occurred during onError callback execution"
|
|
184
|
-
},
|
|
185
|
-
function
|
|
184
|
+
}, L = /* @__PURE__ */ Symbol("debugName"), ie = /* @__PURE__ */ Symbol("id"), V = /* @__PURE__ */ Symbol("type"), q = /* @__PURE__ */ Symbol("noDefaultValue");
|
|
185
|
+
function ne(i) {
|
|
186
186
|
return "dependencies" in i && Array.isArray(i.dependencies);
|
|
187
187
|
}
|
|
188
|
-
let
|
|
189
|
-
function
|
|
188
|
+
let j = 0;
|
|
189
|
+
function G(i, e, t) {
|
|
190
190
|
if (i._visitedEpoch !== t) {
|
|
191
191
|
if (i._visitedEpoch = t, i === e)
|
|
192
|
-
throw new
|
|
193
|
-
if (
|
|
192
|
+
throw new N("Indirect circular dependency detected");
|
|
193
|
+
if (ne(i)) {
|
|
194
194
|
const s = i.dependencies;
|
|
195
195
|
for (let n = 0; n < s.length; n++) {
|
|
196
196
|
const r = s[n];
|
|
197
|
-
r &&
|
|
197
|
+
r && G(r, e, t);
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
const d = {
|
|
203
203
|
enabled: typeof process < "u" && process.env?.NODE_ENV === "development",
|
|
204
|
-
maxDependencies:
|
|
205
|
-
warnInfiniteLoop:
|
|
204
|
+
maxDependencies: k.MAX_DEPENDENCIES,
|
|
205
|
+
warnInfiniteLoop: k.WARN_INFINITE_LOOP,
|
|
206
206
|
warn(i, e) {
|
|
207
207
|
this.enabled && i && console.warn(`[Atom Effect] ${e}`);
|
|
208
208
|
},
|
|
@@ -213,32 +213,32 @@ const d = {
|
|
|
213
213
|
*/
|
|
214
214
|
checkCircular(i, e) {
|
|
215
215
|
if (i === e)
|
|
216
|
-
throw new
|
|
217
|
-
this.enabled && (
|
|
216
|
+
throw new N("Direct circular dependency detected");
|
|
217
|
+
this.enabled && (j++, G(i, e, j));
|
|
218
218
|
},
|
|
219
219
|
attachDebugInfo(i, e, t) {
|
|
220
220
|
if (!this.enabled)
|
|
221
221
|
return;
|
|
222
222
|
const s = i;
|
|
223
|
-
s[
|
|
223
|
+
s[L] = `${e}_${t}`, s[ie] = t, s[V] = e;
|
|
224
224
|
},
|
|
225
225
|
getDebugName(i) {
|
|
226
|
-
if (i != null &&
|
|
227
|
-
return i[
|
|
226
|
+
if (i != null && L in i)
|
|
227
|
+
return i[L];
|
|
228
228
|
},
|
|
229
229
|
getDebugType(i) {
|
|
230
|
-
if (i != null &&
|
|
231
|
-
return i[
|
|
230
|
+
if (i != null && V in i)
|
|
231
|
+
return i[V];
|
|
232
232
|
}
|
|
233
233
|
};
|
|
234
|
-
let
|
|
235
|
-
const
|
|
236
|
-
class
|
|
234
|
+
let re = 1;
|
|
235
|
+
const oe = () => re++;
|
|
236
|
+
class Y {
|
|
237
237
|
constructor() {
|
|
238
|
-
this.id =
|
|
238
|
+
this.id = oe() & I, this.flags = 0;
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
|
-
class $ extends
|
|
241
|
+
class $ extends Y {
|
|
242
242
|
constructor() {
|
|
243
243
|
super(), this.version = 0, this._lastSeenEpoch = -1;
|
|
244
244
|
}
|
|
@@ -253,7 +253,7 @@ class $ extends G {
|
|
|
253
253
|
if (typeof e == "object" && e !== null && "execute" in e)
|
|
254
254
|
return this._objectSubscribers.add(e);
|
|
255
255
|
if (typeof e != "function")
|
|
256
|
-
throw new
|
|
256
|
+
throw new p(h.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
|
|
257
257
|
return this._functionSubscribers.add(e);
|
|
258
258
|
}
|
|
259
259
|
/**
|
|
@@ -271,30 +271,33 @@ class $ extends G {
|
|
|
271
271
|
_notifySubscribers(e, t) {
|
|
272
272
|
this._functionSubscribers.forEachSafe(
|
|
273
273
|
(s) => s(e, t),
|
|
274
|
-
(s) => console.error(new
|
|
274
|
+
(s) => console.error(new p(h.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED, s))
|
|
275
275
|
), this._objectSubscribers.forEachSafe(
|
|
276
276
|
(s) => s.execute(),
|
|
277
|
-
(s) => console.error(new
|
|
277
|
+
(s) => console.error(new p(h.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED, s))
|
|
278
278
|
);
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
|
-
let
|
|
281
|
+
let U = 0;
|
|
282
282
|
function H() {
|
|
283
|
-
return
|
|
283
|
+
return U = (U + 1 | 0) & I, U;
|
|
284
284
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
return x ? (l && console.warn(
|
|
288
|
-
"Warning: startFlush() called during flush - ignored to prevent infinite loop detection bypass"
|
|
289
|
-
), !1) : (x = !0, O = O + 1 & N, V = 0, !0);
|
|
285
|
+
function ce() {
|
|
286
|
+
return U;
|
|
290
287
|
}
|
|
288
|
+
let x = 0, w = 0, F = !1;
|
|
291
289
|
function z() {
|
|
292
|
-
|
|
290
|
+
return F ? (a && console.warn(
|
|
291
|
+
"Warning: startFlush() called during flush - ignored to prevent infinite loop detection bypass"
|
|
292
|
+
), !1) : (F = !0, x = x + 1 & I, w = 0, !0);
|
|
293
|
+
}
|
|
294
|
+
function X() {
|
|
295
|
+
F = !1;
|
|
293
296
|
}
|
|
294
|
-
function
|
|
295
|
-
return
|
|
297
|
+
function he() {
|
|
298
|
+
return F ? ++w : 0;
|
|
296
299
|
}
|
|
297
|
-
class
|
|
300
|
+
class ue {
|
|
298
301
|
constructor() {
|
|
299
302
|
this.queueA = [], this.queueB = [], this.queue = this.queueA, this.queueSize = 0, this._epoch = 0, this.isProcessing = !1, this.isBatching = !1, this.batchDepth = 0, this.batchQueue = [], this.batchQueueSize = 0, this.isFlushingSync = !1, this.maxFlushIterations = g.MAX_FLUSH_ITERATIONS;
|
|
300
303
|
}
|
|
@@ -309,7 +312,7 @@ class re {
|
|
|
309
312
|
*/
|
|
310
313
|
schedule(e) {
|
|
311
314
|
if (typeof e != "function")
|
|
312
|
-
throw new
|
|
315
|
+
throw new O("Scheduler callback must be a function");
|
|
313
316
|
e._nextEpoch !== this._epoch && (e._nextEpoch = this._epoch, this.isBatching || this.isFlushingSync ? this.batchQueue[this.batchQueueSize++] = e : (this.queue[this.queueSize++] = e, this.isProcessing || this.flush()));
|
|
314
317
|
}
|
|
315
318
|
flush() {
|
|
@@ -317,17 +320,17 @@ class re {
|
|
|
317
320
|
this.isProcessing = !0;
|
|
318
321
|
const e = this.queue, t = this.queueSize;
|
|
319
322
|
this.queue = this.queue === this.queueA ? this.queueB : this.queueA, this.queueSize = 0, this._epoch++, queueMicrotask(() => {
|
|
320
|
-
const s =
|
|
321
|
-
this._processJobs(e, t), this.isProcessing = !1, s &&
|
|
323
|
+
const s = z();
|
|
324
|
+
this._processJobs(e, t), this.isProcessing = !1, s && X(), this.queueSize > 0 && !this.isBatching && this.flush();
|
|
322
325
|
});
|
|
323
326
|
}
|
|
324
327
|
flushSync() {
|
|
325
328
|
this.isFlushingSync = !0;
|
|
326
|
-
const e =
|
|
329
|
+
const e = z();
|
|
327
330
|
try {
|
|
328
331
|
this._mergeBatchQueue(), this._drainQueue();
|
|
329
332
|
} finally {
|
|
330
|
-
this.isFlushingSync = !1, e &&
|
|
333
|
+
this.isFlushingSync = !1, e && X();
|
|
331
334
|
}
|
|
332
335
|
}
|
|
333
336
|
_mergeBatchQueue() {
|
|
@@ -355,7 +358,7 @@ class re {
|
|
|
355
358
|
}
|
|
356
359
|
_handleFlushOverflow() {
|
|
357
360
|
console.error(
|
|
358
|
-
new
|
|
361
|
+
new O(
|
|
359
362
|
`Maximum flush iterations (${this.maxFlushIterations}) exceeded. Possible infinite loop.`
|
|
360
363
|
)
|
|
361
364
|
), this.queueSize = 0, this.queue.length = 0, this.batchQueueSize = 0;
|
|
@@ -366,7 +369,7 @@ class re {
|
|
|
366
369
|
e[s]?.();
|
|
367
370
|
} catch (n) {
|
|
368
371
|
console.error(
|
|
369
|
-
new
|
|
372
|
+
new O("Error occurred during scheduler execution", n)
|
|
370
373
|
);
|
|
371
374
|
}
|
|
372
375
|
e.length = 0;
|
|
@@ -388,24 +391,24 @@ class re {
|
|
|
388
391
|
*/
|
|
389
392
|
setMaxFlushIterations(e) {
|
|
390
393
|
if (e < g.MIN_FLUSH_ITERATIONS)
|
|
391
|
-
throw new
|
|
394
|
+
throw new O(
|
|
392
395
|
`Max flush iterations must be at least ${g.MIN_FLUSH_ITERATIONS}`
|
|
393
396
|
);
|
|
394
397
|
this.maxFlushIterations = e;
|
|
395
398
|
}
|
|
396
399
|
}
|
|
397
|
-
const
|
|
398
|
-
function
|
|
400
|
+
const T = new ue();
|
|
401
|
+
function be(i) {
|
|
399
402
|
if (typeof i != "function")
|
|
400
|
-
throw new
|
|
401
|
-
|
|
403
|
+
throw new p("Batch callback must be a function");
|
|
404
|
+
T.startBatch();
|
|
402
405
|
try {
|
|
403
406
|
return i();
|
|
404
407
|
} finally {
|
|
405
|
-
|
|
408
|
+
T.endBatch();
|
|
406
409
|
}
|
|
407
410
|
}
|
|
408
|
-
const
|
|
411
|
+
const y = {
|
|
409
412
|
current: null,
|
|
410
413
|
run(i, e) {
|
|
411
414
|
const t = this.current;
|
|
@@ -420,18 +423,18 @@ const I = {
|
|
|
420
423
|
return this.current;
|
|
421
424
|
}
|
|
422
425
|
};
|
|
423
|
-
function
|
|
426
|
+
function _e(i) {
|
|
424
427
|
if (typeof i != "function")
|
|
425
|
-
throw new
|
|
426
|
-
const e =
|
|
427
|
-
|
|
428
|
+
throw new p("Untracked callback must be a function");
|
|
429
|
+
const e = y.current;
|
|
430
|
+
y.current = null;
|
|
428
431
|
try {
|
|
429
432
|
return i();
|
|
430
433
|
} finally {
|
|
431
|
-
|
|
434
|
+
y.current = e;
|
|
432
435
|
}
|
|
433
436
|
}
|
|
434
|
-
class
|
|
437
|
+
class P {
|
|
435
438
|
constructor() {
|
|
436
439
|
this.subscribers = null;
|
|
437
440
|
}
|
|
@@ -487,38 +490,38 @@ class F {
|
|
|
487
490
|
return this.subscribers ? [...this.subscribers] : [];
|
|
488
491
|
}
|
|
489
492
|
}
|
|
490
|
-
function
|
|
493
|
+
function ae(i) {
|
|
491
494
|
return i !== null && typeof i == "object" && "value" in i && "subscribe" in i && typeof i.subscribe == "function";
|
|
492
495
|
}
|
|
493
|
-
function
|
|
496
|
+
function Se(i) {
|
|
494
497
|
if (d.enabled && (i == null || typeof i == "object")) {
|
|
495
498
|
const e = d.getDebugType(i);
|
|
496
499
|
if (e)
|
|
497
500
|
return e === "computed";
|
|
498
501
|
}
|
|
499
|
-
return
|
|
502
|
+
return ae(i) && "invalidate" in i && typeof i.invalidate == "function";
|
|
500
503
|
}
|
|
501
|
-
function
|
|
504
|
+
function ge(i) {
|
|
502
505
|
return i !== null && typeof i == "object" && "dispose" in i && "run" in i && typeof i.dispose == "function" && typeof i.run == "function";
|
|
503
506
|
}
|
|
504
|
-
function
|
|
507
|
+
function J(i) {
|
|
505
508
|
return i != null && typeof i.then == "function";
|
|
506
509
|
}
|
|
507
|
-
function
|
|
510
|
+
function le(i) {
|
|
508
511
|
return typeof i == "object" && i !== null;
|
|
509
512
|
}
|
|
510
|
-
function
|
|
513
|
+
function Q(i) {
|
|
511
514
|
return (typeof i == "object" || typeof i == "function") && i !== null && typeof i.addDependency == "function";
|
|
512
515
|
}
|
|
513
|
-
function
|
|
516
|
+
function W(i) {
|
|
514
517
|
return typeof i == "function" && typeof i.addDependency != "function";
|
|
515
518
|
}
|
|
516
|
-
function
|
|
517
|
-
return
|
|
519
|
+
function K(i) {
|
|
520
|
+
return le(i) && typeof i.execute == "function";
|
|
518
521
|
}
|
|
519
|
-
class
|
|
522
|
+
class fe extends $ {
|
|
520
523
|
constructor(e, t) {
|
|
521
|
-
super(), this._isNotificationScheduled = !1, this._value = e, this._functionSubscribersStore = new
|
|
524
|
+
super(), this._isNotificationScheduled = !1, this._value = e, this._functionSubscribersStore = new P(), this._objectSubscribersStore = new P(), this._sync = t, this._notifyTask = this._flushNotifications.bind(this), d.attachDebugInfo(this, "atom", this.id);
|
|
522
525
|
}
|
|
523
526
|
/** Gets the manager for function-based subscribers. */
|
|
524
527
|
get _functionSubscribers() {
|
|
@@ -532,7 +535,7 @@ class he extends $ {
|
|
|
532
535
|
* Returns the current value and registers the atom as a dependency in the current tracking context.
|
|
533
536
|
*/
|
|
534
537
|
get value() {
|
|
535
|
-
const e =
|
|
538
|
+
const e = y.getCurrent();
|
|
536
539
|
return e && this._track(e), this._value;
|
|
537
540
|
}
|
|
538
541
|
/**
|
|
@@ -542,21 +545,21 @@ class he extends $ {
|
|
|
542
545
|
set value(e) {
|
|
543
546
|
if (Object.is(this._value, e)) return;
|
|
544
547
|
const t = this._value;
|
|
545
|
-
this.version = this.version + 1 &
|
|
548
|
+
this.version = this.version + 1 & I, this._value = e, !(!this._functionSubscribersStore.hasSubscribers && !this._objectSubscribersStore.hasSubscribers) && this._scheduleNotification(t);
|
|
546
549
|
}
|
|
547
550
|
_track(e) {
|
|
548
|
-
if (
|
|
551
|
+
if (Q(e)) {
|
|
549
552
|
e.addDependency(this);
|
|
550
553
|
return;
|
|
551
554
|
}
|
|
552
|
-
if (
|
|
555
|
+
if (W(e)) {
|
|
553
556
|
this._functionSubscribersStore.add(e);
|
|
554
557
|
return;
|
|
555
558
|
}
|
|
556
|
-
|
|
559
|
+
K(e) && this._objectSubscribersStore.add(e);
|
|
557
560
|
}
|
|
558
561
|
_scheduleNotification(e) {
|
|
559
|
-
this._isNotificationScheduled || (this._pendingOldValue = e, this._isNotificationScheduled = !0), this._sync && !
|
|
562
|
+
this._isNotificationScheduled || (this._pendingOldValue = e, this._isNotificationScheduled = !0), this._sync && !T.isBatching ? this._flushNotifications() : T.schedule(this._notifyTask);
|
|
560
563
|
}
|
|
561
564
|
_flushNotifications() {
|
|
562
565
|
if (!this._isNotificationScheduled) return;
|
|
@@ -576,12 +579,12 @@ class he extends $ {
|
|
|
576
579
|
this._functionSubscribersStore.clear(), this._objectSubscribersStore.clear(), this._value = void 0;
|
|
577
580
|
}
|
|
578
581
|
}
|
|
579
|
-
function
|
|
580
|
-
return new
|
|
582
|
+
function De(i, e = {}) {
|
|
583
|
+
return new fe(i, e.sync ?? !1);
|
|
581
584
|
}
|
|
582
|
-
class
|
|
585
|
+
class B {
|
|
583
586
|
constructor() {
|
|
584
|
-
this.pool = [], this.maxPoolSize = 50, this.maxReusableCapacity = 256, this.stats =
|
|
587
|
+
this.pool = [], this.maxPoolSize = 50, this.maxReusableCapacity = 256, this.stats = a ? {
|
|
585
588
|
acquired: 0,
|
|
586
589
|
released: 0,
|
|
587
590
|
rejected: { frozen: 0, tooLarge: 0, poolFull: 0 }
|
|
@@ -589,7 +592,7 @@ class w {
|
|
|
589
592
|
}
|
|
590
593
|
/** Acquires an array from the pool or creates a new one if the pool is empty. */
|
|
591
594
|
acquire() {
|
|
592
|
-
return
|
|
595
|
+
return a && this.stats && this.stats.acquired++, this.pool.pop() ?? [];
|
|
593
596
|
}
|
|
594
597
|
/**
|
|
595
598
|
* Releases an array back to the pool.
|
|
@@ -600,23 +603,23 @@ class w {
|
|
|
600
603
|
release(e, t) {
|
|
601
604
|
if (!(t && e === t)) {
|
|
602
605
|
if (Object.isFrozen(e)) {
|
|
603
|
-
|
|
606
|
+
a && this.stats && this.stats.rejected.frozen++;
|
|
604
607
|
return;
|
|
605
608
|
}
|
|
606
609
|
if (e.length > this.maxReusableCapacity) {
|
|
607
|
-
|
|
610
|
+
a && this.stats && this.stats.rejected.tooLarge++;
|
|
608
611
|
return;
|
|
609
612
|
}
|
|
610
613
|
if (this.pool.length >= this.maxPoolSize) {
|
|
611
|
-
|
|
614
|
+
a && this.stats && this.stats.rejected.poolFull++;
|
|
612
615
|
return;
|
|
613
616
|
}
|
|
614
|
-
e.length = 0, this.pool.push(e),
|
|
617
|
+
e.length = 0, this.pool.push(e), a && this.stats && this.stats.released++;
|
|
615
618
|
}
|
|
616
619
|
}
|
|
617
620
|
/** Returns current stats for the pool (dev mode only). */
|
|
618
621
|
getStats() {
|
|
619
|
-
if (!
|
|
622
|
+
if (!a || !this.stats) return null;
|
|
620
623
|
const { acquired: e, released: t, rejected: s } = this.stats, n = s.frozen + s.tooLarge + s.poolFull;
|
|
621
624
|
return {
|
|
622
625
|
acquired: e,
|
|
@@ -628,12 +631,12 @@ class w {
|
|
|
628
631
|
}
|
|
629
632
|
/** Resets the pool and its stats. */
|
|
630
633
|
reset() {
|
|
631
|
-
this.pool.length = 0,
|
|
634
|
+
this.pool.length = 0, a && this.stats && (this.stats.acquired = 0, this.stats.released = 0, this.stats.rejected = { frozen: 0, tooLarge: 0, poolFull: 0 });
|
|
632
635
|
}
|
|
633
636
|
}
|
|
634
|
-
const
|
|
635
|
-
function
|
|
636
|
-
if (e !==
|
|
637
|
+
const u = Object.freeze([]), l = Object.freeze([]), _ = Object.freeze([]), S = new B(), D = new B(), f = new B();
|
|
638
|
+
function de(i, e, t, s) {
|
|
639
|
+
if (e !== u && t !== l)
|
|
637
640
|
for (let r = 0; r < e.length; r++) {
|
|
638
641
|
const o = e[r];
|
|
639
642
|
o && (o._tempUnsub = t[r]);
|
|
@@ -644,28 +647,32 @@ function _e(i, e, t, s) {
|
|
|
644
647
|
const o = i[r];
|
|
645
648
|
o && (o._tempUnsub ? (n[r] = o._tempUnsub, o._tempUnsub = void 0) : (d.checkCircular(o, s), n[r] = o.subscribe(s)));
|
|
646
649
|
}
|
|
647
|
-
if (e !==
|
|
650
|
+
if (e !== u)
|
|
648
651
|
for (let r = 0; r < e.length; r++) {
|
|
649
652
|
const o = e[r];
|
|
650
653
|
o?._tempUnsub && (o._tempUnsub(), o._tempUnsub = void 0);
|
|
651
654
|
}
|
|
652
|
-
return t !==
|
|
655
|
+
return t !== l && D.release(t), n;
|
|
653
656
|
}
|
|
654
|
-
function
|
|
657
|
+
function R(i, e, t) {
|
|
655
658
|
if (i instanceof TypeError)
|
|
656
659
|
return new e(`Type error (${t}): ${i.message}`, i);
|
|
657
660
|
if (i instanceof ReferenceError)
|
|
658
661
|
return new e(`Reference error (${t}): ${i.message}`, i);
|
|
659
|
-
if (i instanceof
|
|
662
|
+
if (i instanceof p)
|
|
660
663
|
return i;
|
|
661
664
|
const s = i instanceof Error ? i.message : String(i), n = i instanceof Error ? i : null;
|
|
662
665
|
return new e(`Unexpected error (${t}): ${s}`, n);
|
|
663
666
|
}
|
|
664
|
-
|
|
667
|
+
const Z = c.RESOLVED | c.PENDING | c.REJECTED, M = Array(Z + 1).fill(v.IDLE);
|
|
668
|
+
M[c.RESOLVED] = v.RESOLVED;
|
|
669
|
+
M[c.PENDING] = v.PENDING;
|
|
670
|
+
M[c.REJECTED] = v.REJECTED;
|
|
671
|
+
class ee extends $ {
|
|
665
672
|
constructor(e, t = {}) {
|
|
666
673
|
if (typeof e != "function")
|
|
667
|
-
throw new
|
|
668
|
-
if (super(), this._value = void 0, this.flags =
|
|
674
|
+
throw new N(h.COMPUTED_MUST_BE_FUNCTION);
|
|
675
|
+
if (super(), this._cachedErrors = null, this._errorCacheEpoch = -1, this._value = void 0, this.flags = c.DIRTY | c.IDLE, this._error = null, this._promiseId = 0, this._equal = t.equal ?? Object.is, this._fn = e, this._defaultValue = "defaultValue" in t ? t.defaultValue : q, this._hasDefaultValue = this._defaultValue !== q, this._onError = t.onError ?? null, this.MAX_PROMISE_ID = Number.MAX_SAFE_INTEGER - 1, this._functionSubscribersStore = new P(), this._objectSubscribersStore = new P(), this._dependencies = u, this._dependencyVersions = _, this._unsubscribes = l, this._notifyJob = () => {
|
|
669
676
|
this._functionSubscribersStore.forEachSafe(
|
|
670
677
|
(s) => s(),
|
|
671
678
|
(s) => console.error(s)
|
|
@@ -693,83 +700,112 @@ class K extends $ {
|
|
|
693
700
|
return this._objectSubscribersStore;
|
|
694
701
|
}
|
|
695
702
|
get value() {
|
|
696
|
-
|
|
697
|
-
return this._registerTracking(), e;
|
|
703
|
+
return this._registerTracking(), this._computeValue();
|
|
698
704
|
}
|
|
699
705
|
peek() {
|
|
700
706
|
return this._value;
|
|
701
707
|
}
|
|
702
708
|
get state() {
|
|
703
|
-
return this._getAsyncState();
|
|
709
|
+
return this._registerTracking(), this._getAsyncState();
|
|
704
710
|
}
|
|
705
711
|
get hasError() {
|
|
706
|
-
|
|
712
|
+
if (this._registerTracking(), this._isRejected())
|
|
713
|
+
return !0;
|
|
714
|
+
for (let e = 0; e < this._dependencies.length; e++) {
|
|
715
|
+
const t = this._dependencies[e];
|
|
716
|
+
if (t && "hasError" in t && t.hasError)
|
|
717
|
+
return !0;
|
|
718
|
+
}
|
|
719
|
+
return !1;
|
|
720
|
+
}
|
|
721
|
+
get isValid() {
|
|
722
|
+
return !this.hasError;
|
|
723
|
+
}
|
|
724
|
+
get errors() {
|
|
725
|
+
if (this._registerTracking(), !this.hasError)
|
|
726
|
+
return se;
|
|
727
|
+
const e = ce();
|
|
728
|
+
if (this._errorCacheEpoch === e && this._cachedErrors !== null)
|
|
729
|
+
return this._cachedErrors;
|
|
730
|
+
const t = /* @__PURE__ */ new Set();
|
|
731
|
+
this._error && t.add(this._error);
|
|
732
|
+
for (let s = 0; s < this._dependencies.length; s++) {
|
|
733
|
+
const n = this._dependencies[s];
|
|
734
|
+
if (n && "errors" in n) {
|
|
735
|
+
const r = n.errors;
|
|
736
|
+
for (let o = 0; o < r.length; o++) {
|
|
737
|
+
const m = r[o];
|
|
738
|
+
m && t.add(m);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
return this._cachedErrors = Object.freeze([...t]), this._errorCacheEpoch = e, this._cachedErrors;
|
|
707
743
|
}
|
|
708
744
|
get lastError() {
|
|
709
|
-
return this._error;
|
|
745
|
+
return this._registerTracking(), this._error;
|
|
710
746
|
}
|
|
711
747
|
get isPending() {
|
|
712
|
-
return this._isPending();
|
|
748
|
+
return this._registerTracking(), this._isPending();
|
|
713
749
|
}
|
|
714
750
|
get isResolved() {
|
|
715
|
-
return this._isResolved();
|
|
751
|
+
return this._registerTracking(), this._isResolved();
|
|
716
752
|
}
|
|
717
753
|
invalidate() {
|
|
718
|
-
this._markDirty(), this._dependencyVersions !== _ && (f.release(this._dependencyVersions), this._dependencyVersions = _);
|
|
754
|
+
this._markDirty(), this._dependencyVersions !== _ && (f.release(this._dependencyVersions), this._dependencyVersions = _), this._errorCacheEpoch = -1, this._cachedErrors = null;
|
|
719
755
|
}
|
|
720
756
|
dispose() {
|
|
721
|
-
if (this._unsubscribes !==
|
|
757
|
+
if (this._unsubscribes !== l) {
|
|
722
758
|
for (let e = 0; e < this._unsubscribes.length; e++) {
|
|
723
759
|
const t = this._unsubscribes[e];
|
|
724
760
|
t && t();
|
|
725
761
|
}
|
|
726
|
-
D.release(this._unsubscribes), this._unsubscribes =
|
|
762
|
+
D.release(this._unsubscribes), this._unsubscribes = l;
|
|
727
763
|
}
|
|
728
|
-
this._dependencies !==
|
|
764
|
+
this._dependencies !== u && (S.release(this._dependencies), this._dependencies = u), this._dependencyVersions !== _ && (f.release(this._dependencyVersions), this._dependencyVersions = _), this._functionSubscribersStore.clear(), this._objectSubscribersStore.clear(), this.flags = c.DIRTY | c.IDLE, this._error = null, this._value = void 0, this._promiseId = (this._promiseId + 1) % this.MAX_PROMISE_ID, this._cachedErrors = null, this._errorCacheEpoch = -1;
|
|
729
765
|
}
|
|
730
766
|
// State flag operations
|
|
731
767
|
_isDirty() {
|
|
732
|
-
return (this.flags &
|
|
768
|
+
return (this.flags & c.DIRTY) !== 0;
|
|
733
769
|
}
|
|
734
770
|
_setDirty() {
|
|
735
|
-
this.flags |=
|
|
771
|
+
this.flags |= c.DIRTY;
|
|
736
772
|
}
|
|
737
773
|
_clearDirty() {
|
|
738
774
|
this.flags &= -2;
|
|
739
775
|
}
|
|
740
776
|
_isIdle() {
|
|
741
|
-
return (this.flags &
|
|
777
|
+
return (this.flags & c.IDLE) !== 0;
|
|
742
778
|
}
|
|
743
779
|
_setIdle() {
|
|
744
|
-
this.flags |=
|
|
780
|
+
this.flags |= c.IDLE, this.flags &= -29;
|
|
745
781
|
}
|
|
746
782
|
_isPending() {
|
|
747
|
-
return (this.flags &
|
|
783
|
+
return (this.flags & c.PENDING) !== 0;
|
|
748
784
|
}
|
|
749
785
|
_setPending() {
|
|
750
|
-
this.flags |=
|
|
786
|
+
this.flags |= c.PENDING, this.flags &= -27;
|
|
751
787
|
}
|
|
752
788
|
_isResolved() {
|
|
753
|
-
return (this.flags &
|
|
789
|
+
return (this.flags & c.RESOLVED) !== 0;
|
|
754
790
|
}
|
|
755
791
|
_setResolved() {
|
|
756
|
-
this.flags |=
|
|
792
|
+
this.flags |= c.RESOLVED, this.flags &= -87;
|
|
757
793
|
}
|
|
758
794
|
_isRejected() {
|
|
759
|
-
return (this.flags &
|
|
795
|
+
return (this.flags & c.REJECTED) !== 0;
|
|
760
796
|
}
|
|
761
797
|
_setRejected() {
|
|
762
|
-
this.flags |=
|
|
798
|
+
this.flags |= c.REJECTED | c.HAS_ERROR, this.flags &= -15;
|
|
763
799
|
}
|
|
764
800
|
_isRecomputing() {
|
|
765
|
-
return (this.flags &
|
|
801
|
+
return (this.flags & c.RECOMPUTING) !== 0;
|
|
766
802
|
}
|
|
767
803
|
_setRecomputing(e) {
|
|
768
|
-
const t =
|
|
804
|
+
const t = c.RECOMPUTING;
|
|
769
805
|
this.flags = this.flags & ~t | -Number(e) & t;
|
|
770
806
|
}
|
|
771
807
|
_getAsyncState() {
|
|
772
|
-
return this.
|
|
808
|
+
return M[this.flags & Z];
|
|
773
809
|
}
|
|
774
810
|
_getFlagsAsString() {
|
|
775
811
|
const e = [];
|
|
@@ -784,32 +820,39 @@ class K extends $ {
|
|
|
784
820
|
const e = this._prepareComputationContext();
|
|
785
821
|
let t = !1;
|
|
786
822
|
try {
|
|
787
|
-
const s =
|
|
788
|
-
|
|
823
|
+
const s = y.run(this._trackable, this._fn);
|
|
824
|
+
this._commitDependencies(e), t = !0, J(s) ? this._handleAsyncComputation(s) : this._handleSyncResult(s);
|
|
789
825
|
} catch (s) {
|
|
790
|
-
|
|
826
|
+
if (!t)
|
|
827
|
+
try {
|
|
828
|
+
this._commitDependencies(e), t = !0;
|
|
829
|
+
} catch (n) {
|
|
830
|
+
this._handleComputationError(n);
|
|
831
|
+
}
|
|
832
|
+
this._handleComputationError(s);
|
|
791
833
|
} finally {
|
|
792
834
|
this._cleanupContext(e, t), this._setRecomputing(!1);
|
|
793
835
|
}
|
|
794
836
|
}
|
|
795
837
|
_prepareComputationContext() {
|
|
796
|
-
const e = this._dependencies, t = this._dependencyVersions, s = S.acquire(), n = f.acquire(), r = H(), o = { depCount: 0 },
|
|
797
|
-
|
|
798
|
-
},
|
|
799
|
-
return this._trackable.addDependency =
|
|
838
|
+
const e = this._dependencies, t = this._dependencyVersions, s = S.acquire(), n = f.acquire(), r = H(), o = { depCount: 0 }, m = (E) => {
|
|
839
|
+
E._lastSeenEpoch !== r && (E._lastSeenEpoch = r, o.depCount < s.length ? (s[o.depCount] = E, n[o.depCount] = E.version) : (s.push(E), n.push(E.version)), o.depCount++);
|
|
840
|
+
}, C = this._trackable.addDependency;
|
|
841
|
+
return this._trackable.addDependency = m, { prevDeps: e, prevVersions: t, nextDeps: s, nextVersions: n, originalAdd: C, state: o };
|
|
800
842
|
}
|
|
801
843
|
_commitDependencies(e) {
|
|
802
844
|
const { nextDeps: t, nextVersions: s, state: n, prevDeps: r } = e;
|
|
803
|
-
t.length = n.depCount, s.length = n.depCount, this._unsubscribes =
|
|
845
|
+
t.length = n.depCount, s.length = n.depCount, this._unsubscribes = de(t, r, this._unsubscribes, this), this._dependencies = t, this._dependencyVersions = s;
|
|
804
846
|
}
|
|
805
847
|
_cleanupContext(e, t) {
|
|
806
|
-
this._trackable.addDependency = e.originalAdd, t ? (e.prevDeps !==
|
|
848
|
+
this._trackable.addDependency = e.originalAdd, t ? (e.prevDeps !== u && S.release(e.prevDeps), e.prevVersions !== _ && f.release(e.prevVersions)) : (S.release(e.nextDeps), f.release(e.nextVersions));
|
|
807
849
|
}
|
|
808
850
|
_handleSyncResult(e) {
|
|
809
|
-
|
|
851
|
+
const t = !this._isResolved() || !this._equal(this._value, e);
|
|
852
|
+
this.version = this.version + Number(t) & I, this._value = e, this._clearDirty(), this._setResolved(), this._error = null, this._setRecomputing(!1), this._cachedErrors = null, this._errorCacheEpoch = -1;
|
|
810
853
|
}
|
|
811
854
|
_handleAsyncComputation(e) {
|
|
812
|
-
this._setPending(), this._clearDirty(), this._promiseId = this._promiseId >= this.MAX_PROMISE_ID ? 1 : this._promiseId + 1;
|
|
855
|
+
this._setPending(), this._clearDirty(), this._notifyJob(), this._promiseId = this._promiseId >= this.MAX_PROMISE_ID ? 1 : this._promiseId + 1;
|
|
813
856
|
const t = this._promiseId;
|
|
814
857
|
e.then((s) => {
|
|
815
858
|
t === this._promiseId && this._handleAsyncResolution(s);
|
|
@@ -818,32 +861,33 @@ class K extends $ {
|
|
|
818
861
|
});
|
|
819
862
|
}
|
|
820
863
|
_handleAsyncResolution(e) {
|
|
821
|
-
|
|
864
|
+
const t = !this._isResolved() || !this._equal(this._value, e);
|
|
865
|
+
this.version = this.version + Number(t) & I, this._value = e, this._clearDirty(), this._setResolved(), this._error = null, this._setRecomputing(!1), this._cachedErrors = null, this._errorCacheEpoch = -1, this._notifyJob();
|
|
822
866
|
}
|
|
823
867
|
_handleAsyncRejection(e) {
|
|
824
|
-
const t =
|
|
825
|
-
if (this._error = t, this._setRejected(), this._clearDirty(), this._setRecomputing(!1), this._onError)
|
|
868
|
+
const t = R(e, N, h.COMPUTED_ASYNC_COMPUTATION_FAILED), s = !this._isRejected();
|
|
869
|
+
if (this.version = this.version + Number(s) & I, this._error = t, this._setRejected(), this._clearDirty(), this._setRecomputing(!1), this._onError)
|
|
826
870
|
try {
|
|
827
871
|
this._onError(t);
|
|
828
|
-
} catch (
|
|
829
|
-
console.error(
|
|
872
|
+
} catch (n) {
|
|
873
|
+
console.error(h.CALLBACK_ERROR_IN_ERROR_HANDLER, n);
|
|
830
874
|
}
|
|
831
|
-
this.
|
|
875
|
+
this._notifyJob();
|
|
832
876
|
}
|
|
833
877
|
_handleComputationError(e) {
|
|
834
|
-
const t =
|
|
878
|
+
const t = R(e, N, h.COMPUTED_COMPUTATION_FAILED);
|
|
835
879
|
if (this._error = t, this._setRejected(), this._clearDirty(), this._setRecomputing(!1), this._onError)
|
|
836
880
|
try {
|
|
837
881
|
this._onError(t);
|
|
838
882
|
} catch (s) {
|
|
839
|
-
console.error(
|
|
883
|
+
console.error(h.CALLBACK_ERROR_IN_ERROR_HANDLER, s);
|
|
840
884
|
}
|
|
841
885
|
throw t;
|
|
842
886
|
}
|
|
843
887
|
_handlePending() {
|
|
844
888
|
if (this._hasDefaultValue)
|
|
845
889
|
return this._defaultValue;
|
|
846
|
-
throw new
|
|
890
|
+
throw new N(h.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
|
|
847
891
|
}
|
|
848
892
|
_handleRejected() {
|
|
849
893
|
if (this._error?.recoverable && this._hasDefaultValue)
|
|
@@ -858,25 +902,25 @@ class K extends $ {
|
|
|
858
902
|
this._isRecomputing() || this._isDirty() || (this._setDirty(), this._notifyJob());
|
|
859
903
|
}
|
|
860
904
|
_registerTracking() {
|
|
861
|
-
const e =
|
|
905
|
+
const e = y.getCurrent();
|
|
862
906
|
if (e) {
|
|
863
|
-
if (
|
|
907
|
+
if (Q(e)) {
|
|
864
908
|
e.addDependency(this);
|
|
865
909
|
return;
|
|
866
910
|
}
|
|
867
|
-
if (
|
|
911
|
+
if (W(e)) {
|
|
868
912
|
this._functionSubscribersStore.add(e);
|
|
869
913
|
return;
|
|
870
914
|
}
|
|
871
|
-
|
|
915
|
+
K(e) && this._objectSubscribersStore.add(e);
|
|
872
916
|
}
|
|
873
917
|
}
|
|
874
918
|
}
|
|
875
|
-
Object.freeze(
|
|
876
|
-
function
|
|
877
|
-
return new
|
|
919
|
+
Object.freeze(ee.prototype);
|
|
920
|
+
function Ie(i, e = {}) {
|
|
921
|
+
return new ee(i, e);
|
|
878
922
|
}
|
|
879
|
-
class
|
|
923
|
+
class Ee extends Y {
|
|
880
924
|
/**
|
|
881
925
|
* Creates a new EffectImpl instance.
|
|
882
926
|
* @param fn - The effect function to run.
|
|
@@ -885,18 +929,18 @@ class le extends G {
|
|
|
885
929
|
constructor(e, t = {}) {
|
|
886
930
|
super(), this.run = () => {
|
|
887
931
|
if (this.isDisposed)
|
|
888
|
-
throw new b(
|
|
932
|
+
throw new b(h.EFFECT_MUST_BE_FUNCTION);
|
|
889
933
|
this._dependencyVersions !== _ && (f.release(this._dependencyVersions), this._dependencyVersions = _), this.execute();
|
|
890
934
|
}, this.dispose = () => {
|
|
891
935
|
if (!this.isDisposed) {
|
|
892
|
-
if (this._setDisposed(), this._safeCleanup(), this._unsubscribes !==
|
|
936
|
+
if (this._setDisposed(), this._safeCleanup(), this._unsubscribes !== l) {
|
|
893
937
|
for (let s = 0; s < this._unsubscribes.length; s++) {
|
|
894
938
|
const n = this._unsubscribes[s];
|
|
895
939
|
n && n();
|
|
896
940
|
}
|
|
897
|
-
D.release(this._unsubscribes), this._unsubscribes =
|
|
941
|
+
D.release(this._unsubscribes), this._unsubscribes = l;
|
|
898
942
|
}
|
|
899
|
-
this._dependencies !==
|
|
943
|
+
this._dependencies !== u && (S.release(this._dependencies), this._dependencies = u), this._dependencyVersions !== _ && (f.release(this._dependencyVersions), this._dependencyVersions = _);
|
|
900
944
|
}
|
|
901
945
|
}, this.addDependency = (s) => {
|
|
902
946
|
if (this.isExecuting && this._nextDeps && this._nextUnsubs && this._nextVersions) {
|
|
@@ -910,31 +954,31 @@ class le extends G {
|
|
|
910
954
|
const s = this._prepareEffectContext();
|
|
911
955
|
let n = !1;
|
|
912
956
|
try {
|
|
913
|
-
const r =
|
|
914
|
-
this._commitEffect(s), n = !0, this._checkLoopWarnings(),
|
|
957
|
+
const r = y.run(this, this._fn);
|
|
958
|
+
this._commitEffect(s), n = !0, this._checkLoopWarnings(), J(r) ? r.then((o) => {
|
|
915
959
|
!this.isDisposed && typeof o == "function" && (this._cleanup = o);
|
|
916
960
|
}).catch((o) => {
|
|
917
|
-
console.error(
|
|
961
|
+
console.error(R(o, b, h.EFFECT_EXECUTION_FAILED));
|
|
918
962
|
}) : this._cleanup = typeof r == "function" ? r : null;
|
|
919
963
|
} catch (r) {
|
|
920
|
-
n = !0, console.error(
|
|
964
|
+
n = !0, console.error(R(r, b, h.EFFECT_EXECUTION_FAILED)), this._cleanup = null;
|
|
921
965
|
} finally {
|
|
922
966
|
this._cleanupEffect(s, n), this._setExecuting(!1);
|
|
923
967
|
}
|
|
924
|
-
}, this._currentEpoch = -1, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._fn = e, this._sync = t.sync ?? !1, this._maxExecutions = t.maxExecutionsPerSecond ?? g.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = t.maxExecutionsPerFlush ?? g.MAX_EXECUTIONS_PER_EFFECT, this._trackModifications = t.trackModifications ?? !1, this._cleanup = null, this._dependencies =
|
|
968
|
+
}, this._currentEpoch = -1, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._fn = e, this._sync = t.sync ?? !1, this._maxExecutions = t.maxExecutionsPerSecond ?? g.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = t.maxExecutionsPerFlush ?? g.MAX_EXECUTIONS_PER_EFFECT, this._trackModifications = t.trackModifications ?? !1, this._cleanup = null, this._dependencies = u, this._dependencyVersions = _, this._unsubscribes = l, this._nextDeps = null, this._nextVersions = null, this._nextUnsubs = null, this._history = a ? [] : null, this._executionCount = 0, d.attachDebugInfo(this, "effect", this.id);
|
|
925
969
|
}
|
|
926
970
|
/**
|
|
927
971
|
* Prepares the execution context by acquiring pools and setting up epoch.
|
|
928
972
|
* @returns The prepared EffectContext.
|
|
929
973
|
*/
|
|
930
974
|
_prepareEffectContext() {
|
|
931
|
-
const e = this._dependencies, t = this._dependencyVersions, s = this._unsubscribes, n = S.acquire(), r = f.acquire(), o = D.acquire(),
|
|
932
|
-
if (e !==
|
|
933
|
-
for (let
|
|
934
|
-
const
|
|
935
|
-
|
|
975
|
+
const e = this._dependencies, t = this._dependencyVersions, s = this._unsubscribes, n = S.acquire(), r = f.acquire(), o = D.acquire(), m = H();
|
|
976
|
+
if (e !== u && s !== l)
|
|
977
|
+
for (let C = 0; C < e.length; C++) {
|
|
978
|
+
const E = e[C];
|
|
979
|
+
E && (E._tempUnsub = s[C]);
|
|
936
980
|
}
|
|
937
|
-
return this._nextDeps = n, this._nextVersions = r, this._nextUnsubs = o, this._currentEpoch =
|
|
981
|
+
return this._nextDeps = n, this._nextVersions = r, this._nextUnsubs = o, this._currentEpoch = m, { prevDeps: e, prevVersions: t, prevUnsubs: s, nextDeps: n, nextVersions: r, nextUnsubs: o };
|
|
938
982
|
}
|
|
939
983
|
/**
|
|
940
984
|
* Commits the tracked dependencies as the current active dependencies.
|
|
@@ -951,19 +995,19 @@ class le extends G {
|
|
|
951
995
|
*/
|
|
952
996
|
_cleanupEffect(e, t) {
|
|
953
997
|
if (this._nextDeps = null, this._nextVersions = null, this._nextUnsubs = null, t) {
|
|
954
|
-
if (e.prevDeps !==
|
|
998
|
+
if (e.prevDeps !== u) {
|
|
955
999
|
for (let s = 0; s < e.prevDeps.length; s++) {
|
|
956
1000
|
const n = e.prevDeps[s];
|
|
957
1001
|
n?._tempUnsub && (n._tempUnsub(), n._tempUnsub = void 0);
|
|
958
1002
|
}
|
|
959
1003
|
S.release(e.prevDeps);
|
|
960
1004
|
}
|
|
961
|
-
e.prevUnsubs !==
|
|
1005
|
+
e.prevUnsubs !== l && D.release(e.prevUnsubs), e.prevVersions !== _ && f.release(e.prevVersions);
|
|
962
1006
|
} else {
|
|
963
1007
|
S.release(e.nextDeps), f.release(e.nextVersions);
|
|
964
1008
|
for (let s = 0; s < e.nextUnsubs.length; s++)
|
|
965
1009
|
e.nextUnsubs[s]?.();
|
|
966
|
-
if (D.release(e.nextUnsubs), e.prevDeps !==
|
|
1010
|
+
if (D.release(e.nextUnsubs), e.prevDeps !== u)
|
|
967
1011
|
for (let s = 0; s < e.prevDeps.length; s++) {
|
|
968
1012
|
const n = e.prevDeps[s];
|
|
969
1013
|
n && (n._tempUnsub = void 0);
|
|
@@ -977,11 +1021,11 @@ class le extends G {
|
|
|
977
1021
|
_subscribeTo(e) {
|
|
978
1022
|
try {
|
|
979
1023
|
const t = e.subscribe(() => {
|
|
980
|
-
this._trackModifications && this.isExecuting && (e._modifiedAtEpoch = this._currentEpoch), this._sync ? this.execute() :
|
|
1024
|
+
this._trackModifications && this.isExecuting && (e._modifiedAtEpoch = this._currentEpoch), this._sync ? this.execute() : T.schedule(this.execute);
|
|
981
1025
|
});
|
|
982
1026
|
this._nextUnsubs && this._nextUnsubs.push(t);
|
|
983
1027
|
} catch (t) {
|
|
984
|
-
console.error(
|
|
1028
|
+
console.error(R(t, b, h.EFFECT_EXECUTION_FAILED)), this._nextUnsubs && this._nextUnsubs.push(() => {
|
|
985
1029
|
});
|
|
986
1030
|
}
|
|
987
1031
|
}
|
|
@@ -1018,7 +1062,7 @@ class le extends G {
|
|
|
1018
1062
|
try {
|
|
1019
1063
|
this._cleanup();
|
|
1020
1064
|
} catch (e) {
|
|
1021
|
-
console.error(
|
|
1065
|
+
console.error(R(e, b, h.EFFECT_CLEANUP_FAILED));
|
|
1022
1066
|
}
|
|
1023
1067
|
this._cleanup = null;
|
|
1024
1068
|
}
|
|
@@ -1028,7 +1072,7 @@ class le extends G {
|
|
|
1028
1072
|
* @throws {EffectError} If an infinite loop is detected.
|
|
1029
1073
|
*/
|
|
1030
1074
|
_checkInfiniteLoop() {
|
|
1031
|
-
if (this._lastFlushEpoch !==
|
|
1075
|
+
if (this._lastFlushEpoch !== x && (this._lastFlushEpoch = x, this._executionsInEpoch = 0), this._executionsInEpoch++, this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), he() > g.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++, this._history) {
|
|
1032
1076
|
const e = Date.now();
|
|
1033
1077
|
this._history.push(e), this._history.length > g.MAX_EXECUTIONS_PER_SECOND + 10 && this._history.shift(), this._checkTimestampLoop(e);
|
|
1034
1078
|
}
|
|
@@ -1036,7 +1080,7 @@ class le extends G {
|
|
|
1036
1080
|
_checkTimestampLoop(e) {
|
|
1037
1081
|
const t = this._history;
|
|
1038
1082
|
if (!t || this._maxExecutions <= 0) return;
|
|
1039
|
-
const s = e -
|
|
1083
|
+
const s = e - te.ONE_SECOND_MS;
|
|
1040
1084
|
let n = 0;
|
|
1041
1085
|
for (let r = t.length - 1; r >= 0 && !(t[r] < s); r--)
|
|
1042
1086
|
n++;
|
|
@@ -1044,13 +1088,13 @@ class le extends G {
|
|
|
1044
1088
|
const r = new b(
|
|
1045
1089
|
`Effect executed ${n} times within 1 second. Infinite loop suspected`
|
|
1046
1090
|
);
|
|
1047
|
-
if (this.dispose(), console.error(r),
|
|
1091
|
+
if (this.dispose(), console.error(r), a)
|
|
1048
1092
|
throw r;
|
|
1049
1093
|
}
|
|
1050
1094
|
}
|
|
1051
1095
|
_throwInfiniteLoopError(e) {
|
|
1052
1096
|
const t = new b(
|
|
1053
|
-
`Infinite loop detected (${e}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${
|
|
1097
|
+
`Infinite loop detected (${e}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${w}`
|
|
1054
1098
|
);
|
|
1055
1099
|
throw this.dispose(), console.error(t), t;
|
|
1056
1100
|
}
|
|
@@ -1059,14 +1103,14 @@ class le extends G {
|
|
|
1059
1103
|
* @returns true if any dependency has changed or if it's the first run.
|
|
1060
1104
|
*/
|
|
1061
1105
|
_shouldExecute() {
|
|
1062
|
-
if (this._dependencies ===
|
|
1106
|
+
if (this._dependencies === u || this._dependencyVersions === _)
|
|
1063
1107
|
return !0;
|
|
1064
1108
|
for (let e = 0; e < this._dependencies.length; e++) {
|
|
1065
1109
|
const t = this._dependencies[e];
|
|
1066
1110
|
if (t) {
|
|
1067
1111
|
if ("value" in t)
|
|
1068
1112
|
try {
|
|
1069
|
-
|
|
1113
|
+
_e(() => t.value);
|
|
1070
1114
|
} catch {
|
|
1071
1115
|
return !0;
|
|
1072
1116
|
}
|
|
@@ -1093,30 +1137,30 @@ class le extends G {
|
|
|
1093
1137
|
}
|
|
1094
1138
|
}
|
|
1095
1139
|
}
|
|
1096
|
-
function
|
|
1140
|
+
function ye(i, e = {}) {
|
|
1097
1141
|
if (typeof i != "function")
|
|
1098
|
-
throw new b(
|
|
1099
|
-
const t = new
|
|
1142
|
+
throw new b(h.EFFECT_MUST_BE_FUNCTION);
|
|
1143
|
+
const t = new Ee(i, e);
|
|
1100
1144
|
return t.execute(), t;
|
|
1101
1145
|
}
|
|
1102
1146
|
export {
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1147
|
+
v as AsyncState,
|
|
1148
|
+
p as AtomError,
|
|
1149
|
+
N as ComputedError,
|
|
1150
|
+
k as DEBUG_CONFIG,
|
|
1107
1151
|
d as DEBUG_RUNTIME,
|
|
1108
1152
|
b as EffectError,
|
|
1109
|
-
|
|
1153
|
+
pe as POOL_CONFIG,
|
|
1110
1154
|
g as SCHEDULER_CONFIG,
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1155
|
+
O as SchedulerError,
|
|
1156
|
+
De as atom,
|
|
1157
|
+
be as batch,
|
|
1158
|
+
Ie as computed,
|
|
1159
|
+
ye as effect,
|
|
1160
|
+
ae as isAtom,
|
|
1161
|
+
Se as isComputed,
|
|
1162
|
+
ge as isEffect,
|
|
1163
|
+
T as scheduler,
|
|
1164
|
+
_e as untracked
|
|
1121
1165
|
};
|
|
1122
1166
|
//# sourceMappingURL=index.mjs.map
|