@but212/atom-effect 0.9.1 → 0.10.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/README.md +4 -4
- package/dist/atom-effect.min.js +1 -1
- package/dist/atom-effect.min.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -9
- package/dist/index.mjs +166 -153
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -26,7 +26,7 @@ const Z = {
|
|
|
26
26
|
// 100000 - Currently recomputing
|
|
27
27
|
HAS_ERROR: 64
|
|
28
28
|
// 1000000 - Has error state
|
|
29
|
-
},
|
|
29
|
+
}, Se = {
|
|
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 */
|
|
@@ -63,8 +63,8 @@ class b extends Error {
|
|
|
63
63
|
* @param cause - Original error that caused this error
|
|
64
64
|
* @param recoverable - Whether the operation can be retried
|
|
65
65
|
*/
|
|
66
|
-
constructor(e, t = null,
|
|
67
|
-
super(e), this.name = "AtomError", this.cause = t, this.recoverable =
|
|
66
|
+
constructor(e, t = null, s = !0) {
|
|
67
|
+
super(e), this.name = "AtomError", this.cause = t, this.recoverable = s, this.timestamp = /* @__PURE__ */ new Date();
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
class N extends b {
|
|
@@ -150,18 +150,18 @@ const h = {
|
|
|
150
150
|
*/
|
|
151
151
|
CALLBACK_ERROR_IN_ERROR_HANDLER: "Error occurred during onError callback execution"
|
|
152
152
|
}, L = /* @__PURE__ */ Symbol("debugName"), te = /* @__PURE__ */ Symbol("id"), V = /* @__PURE__ */ Symbol("type"), j = /* @__PURE__ */ Symbol("noDefaultValue");
|
|
153
|
-
function se(
|
|
154
|
-
return "dependencies" in
|
|
153
|
+
function se(i) {
|
|
154
|
+
return "dependencies" in i && Array.isArray(i.dependencies);
|
|
155
155
|
}
|
|
156
156
|
let q = 0;
|
|
157
|
-
function G(
|
|
158
|
-
if (
|
|
159
|
-
if (
|
|
157
|
+
function G(i, e, t) {
|
|
158
|
+
if (i._visitedEpoch !== t) {
|
|
159
|
+
if (i._visitedEpoch = t, i === e)
|
|
160
160
|
throw new N("Indirect circular dependency detected");
|
|
161
|
-
if (se(
|
|
162
|
-
const
|
|
163
|
-
for (let n = 0; n <
|
|
164
|
-
const r =
|
|
161
|
+
if (se(i)) {
|
|
162
|
+
const s = i.dependencies;
|
|
163
|
+
for (let n = 0; n < s.length; n++) {
|
|
164
|
+
const r = s[n];
|
|
165
165
|
r && G(r, e, t);
|
|
166
166
|
}
|
|
167
167
|
}
|
|
@@ -171,32 +171,32 @@ const E = {
|
|
|
171
171
|
enabled: typeof process < "u" && process.env?.NODE_ENV === "development",
|
|
172
172
|
maxDependencies: B.MAX_DEPENDENCIES,
|
|
173
173
|
warnInfiniteLoop: B.WARN_INFINITE_LOOP,
|
|
174
|
-
warn(
|
|
175
|
-
this.enabled &&
|
|
174
|
+
warn(i, e) {
|
|
175
|
+
this.enabled && i && console.warn(`[Atom Effect] ${e}`);
|
|
176
176
|
},
|
|
177
177
|
/**
|
|
178
178
|
* Checks for circular dependencies.
|
|
179
179
|
* Direct check runs always; indirect check only in dev mode.
|
|
180
180
|
* @throws {ComputedError} When circular dependency detected
|
|
181
181
|
*/
|
|
182
|
-
checkCircular(
|
|
183
|
-
if (
|
|
182
|
+
checkCircular(i, e) {
|
|
183
|
+
if (i === e)
|
|
184
184
|
throw new N("Direct circular dependency detected");
|
|
185
|
-
this.enabled && (q++, G(
|
|
185
|
+
this.enabled && (q++, G(i, e, q));
|
|
186
186
|
},
|
|
187
|
-
attachDebugInfo(
|
|
187
|
+
attachDebugInfo(i, e, t) {
|
|
188
188
|
if (!this.enabled)
|
|
189
189
|
return;
|
|
190
|
-
const
|
|
191
|
-
|
|
190
|
+
const s = i;
|
|
191
|
+
s[L] = `${e}_${t}`, s[te] = t, s[V] = e;
|
|
192
192
|
},
|
|
193
|
-
getDebugName(
|
|
194
|
-
if (
|
|
195
|
-
return
|
|
193
|
+
getDebugName(i) {
|
|
194
|
+
if (i != null && L in i)
|
|
195
|
+
return i[L];
|
|
196
196
|
},
|
|
197
|
-
getDebugType(
|
|
198
|
-
if (
|
|
199
|
-
return
|
|
197
|
+
getDebugType(i) {
|
|
198
|
+
if (i != null && V in i)
|
|
199
|
+
return i[V];
|
|
200
200
|
}
|
|
201
201
|
};
|
|
202
202
|
let ie = 1;
|
|
@@ -238,11 +238,11 @@ class Q extends Y {
|
|
|
238
238
|
*/
|
|
239
239
|
_notifySubscribers(e, t) {
|
|
240
240
|
this._functionSubscribers.forEachSafe(
|
|
241
|
-
(
|
|
242
|
-
(
|
|
241
|
+
(s) => s(e, t),
|
|
242
|
+
(s) => console.error(new b(h.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED, s))
|
|
243
243
|
), this._objectSubscribers.forEachSafe(
|
|
244
|
-
(
|
|
245
|
-
(
|
|
244
|
+
(s) => s.execute(),
|
|
245
|
+
(s) => console.error(new b(h.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED, s))
|
|
246
246
|
);
|
|
247
247
|
}
|
|
248
248
|
}
|
|
@@ -334,9 +334,9 @@ class ce {
|
|
|
334
334
|
), this.queueSize = 0, this.queue.length = 0, this.batchQueueSize = 0;
|
|
335
335
|
}
|
|
336
336
|
_processJobs(e, t) {
|
|
337
|
-
for (let
|
|
337
|
+
for (let s = 0; s < t; s++)
|
|
338
338
|
try {
|
|
339
|
-
e[
|
|
339
|
+
e[s]?.();
|
|
340
340
|
} catch (n) {
|
|
341
341
|
console.error(
|
|
342
342
|
new O("Error occurred during scheduler execution", n)
|
|
@@ -368,38 +368,51 @@ class ce {
|
|
|
368
368
|
}
|
|
369
369
|
}
|
|
370
370
|
const T = new ce();
|
|
371
|
-
function
|
|
372
|
-
if (typeof
|
|
371
|
+
function ge(i) {
|
|
372
|
+
if (typeof i != "function")
|
|
373
373
|
throw new b("Batch callback must be a function");
|
|
374
374
|
T.startBatch();
|
|
375
375
|
try {
|
|
376
|
-
return
|
|
376
|
+
return i();
|
|
377
377
|
} finally {
|
|
378
378
|
T.endBatch();
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
381
|
+
class he {
|
|
382
|
+
constructor() {
|
|
383
|
+
this.current = null;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Runs the provided function within the context of the given listener.
|
|
387
|
+
* Restores the previous context after the function completes or throws.
|
|
388
|
+
*
|
|
389
|
+
* @param listener - The tracking listener to associate with the current execution.
|
|
390
|
+
* @param fn - The function to execute.
|
|
391
|
+
*/
|
|
392
|
+
run(e, t) {
|
|
393
|
+
const s = this.current;
|
|
394
|
+
this.current = e;
|
|
386
395
|
try {
|
|
387
|
-
return
|
|
396
|
+
return t();
|
|
388
397
|
} finally {
|
|
389
|
-
this.current =
|
|
398
|
+
this.current = s;
|
|
390
399
|
}
|
|
391
|
-
}
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Retrieves the listener currently associated with the tracking context.
|
|
403
|
+
*/
|
|
392
404
|
getCurrent() {
|
|
393
405
|
return this.current;
|
|
394
406
|
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
|
|
407
|
+
}
|
|
408
|
+
const m = new he();
|
|
409
|
+
function ue(i) {
|
|
410
|
+
if (typeof i != "function")
|
|
398
411
|
throw new b("Untracked callback must be a function");
|
|
399
412
|
const e = m.current;
|
|
400
413
|
m.current = null;
|
|
401
414
|
try {
|
|
402
|
-
return
|
|
415
|
+
return i();
|
|
403
416
|
} finally {
|
|
404
417
|
m.current = e;
|
|
405
418
|
}
|
|
@@ -426,8 +439,8 @@ class v {
|
|
|
426
439
|
const t = this.subscribers.indexOf(e);
|
|
427
440
|
if (t === -1)
|
|
428
441
|
return !1;
|
|
429
|
-
const
|
|
430
|
-
return t !==
|
|
442
|
+
const s = this.subscribers.length - 1;
|
|
443
|
+
return t !== s && (this.subscribers[t] = this.subscribers[s]), this.subscribers.pop(), !0;
|
|
431
444
|
}
|
|
432
445
|
has(e) {
|
|
433
446
|
return this.subscribers ? this.subscribers.indexOf(e) !== -1 : !1;
|
|
@@ -440,9 +453,9 @@ class v {
|
|
|
440
453
|
/** Iterates with error handling to prevent one failure from breaking the chain */
|
|
441
454
|
forEachSafe(e, t) {
|
|
442
455
|
if (this.subscribers)
|
|
443
|
-
for (let
|
|
456
|
+
for (let s = 0; s < this.subscribers.length; s++)
|
|
444
457
|
try {
|
|
445
|
-
e(this.subscribers[
|
|
458
|
+
e(this.subscribers[s], s);
|
|
446
459
|
} catch (n) {
|
|
447
460
|
t ? t(n) : console.error("[SubscriberManager] Error in subscriber callback:", n);
|
|
448
461
|
}
|
|
@@ -498,11 +511,11 @@ class k {
|
|
|
498
511
|
/** Returns current stats for the pool (dev mode only). */
|
|
499
512
|
getStats() {
|
|
500
513
|
if (!l || !this.stats) return null;
|
|
501
|
-
const { acquired: e, released: t, rejected:
|
|
514
|
+
const { acquired: e, released: t, rejected: s } = this.stats, n = s.frozen + s.tooLarge + s.poolFull;
|
|
502
515
|
return {
|
|
503
516
|
acquired: e,
|
|
504
517
|
released: t,
|
|
505
|
-
rejected:
|
|
518
|
+
rejected: s,
|
|
506
519
|
leaked: e - t - n,
|
|
507
520
|
poolSize: this.pool.length
|
|
508
521
|
};
|
|
@@ -513,59 +526,59 @@ class k {
|
|
|
513
526
|
}
|
|
514
527
|
}
|
|
515
528
|
const u = Object.freeze([]), f = Object.freeze([]), a = Object.freeze([]), S = new k(), y = new k(), d = new k();
|
|
516
|
-
function
|
|
517
|
-
return
|
|
529
|
+
function ae(i) {
|
|
530
|
+
return i !== null && typeof i == "object" && "value" in i && "subscribe" in i && typeof i.subscribe == "function";
|
|
518
531
|
}
|
|
519
|
-
function
|
|
520
|
-
if (E.enabled && (
|
|
521
|
-
const e = E.getDebugType(
|
|
532
|
+
function De(i) {
|
|
533
|
+
if (E.enabled && (i == null || typeof i == "object")) {
|
|
534
|
+
const e = E.getDebugType(i);
|
|
522
535
|
if (e)
|
|
523
536
|
return e === "computed";
|
|
524
537
|
}
|
|
525
|
-
return
|
|
538
|
+
return ae(i) && "invalidate" in i && typeof i.invalidate == "function";
|
|
526
539
|
}
|
|
527
|
-
function
|
|
528
|
-
return
|
|
540
|
+
function ye(i) {
|
|
541
|
+
return i !== null && typeof i == "object" && "dispose" in i && "run" in i && typeof i.dispose == "function" && typeof i.run == "function";
|
|
529
542
|
}
|
|
530
|
-
function H(
|
|
531
|
-
return
|
|
543
|
+
function H(i) {
|
|
544
|
+
return i != null && typeof i.then == "function";
|
|
532
545
|
}
|
|
533
|
-
function
|
|
534
|
-
return typeof
|
|
546
|
+
function _e(i) {
|
|
547
|
+
return typeof i == "object" && i !== null;
|
|
535
548
|
}
|
|
536
|
-
function
|
|
537
|
-
return (typeof
|
|
549
|
+
function le(i) {
|
|
550
|
+
return (typeof i == "object" || typeof i == "function") && i !== null && typeof i.addDependency == "function";
|
|
538
551
|
}
|
|
539
|
-
function
|
|
540
|
-
return typeof
|
|
552
|
+
function fe(i) {
|
|
553
|
+
return typeof i == "function" && typeof i.addDependency != "function";
|
|
541
554
|
}
|
|
542
|
-
function
|
|
543
|
-
return
|
|
555
|
+
function de(i) {
|
|
556
|
+
return _e(i) && typeof i.execute == "function";
|
|
544
557
|
}
|
|
545
|
-
function J(
|
|
558
|
+
function J(i, e, t, s) {
|
|
546
559
|
if (e) {
|
|
547
|
-
if (
|
|
548
|
-
e.addDependency(
|
|
560
|
+
if (le(e)) {
|
|
561
|
+
e.addDependency(i);
|
|
549
562
|
return;
|
|
550
563
|
}
|
|
551
|
-
if (
|
|
564
|
+
if (fe(e)) {
|
|
552
565
|
t.add(e);
|
|
553
566
|
return;
|
|
554
567
|
}
|
|
555
|
-
|
|
568
|
+
de(e) && s.add(e);
|
|
556
569
|
}
|
|
557
570
|
}
|
|
558
|
-
function
|
|
571
|
+
function Ee(i, e, t, s) {
|
|
559
572
|
if (e !== u && t !== f)
|
|
560
573
|
for (let r = 0; r < e.length; r++) {
|
|
561
574
|
const o = e[r];
|
|
562
575
|
o && (o._tempUnsub = t[r]);
|
|
563
576
|
}
|
|
564
577
|
const n = y.acquire();
|
|
565
|
-
n.length =
|
|
566
|
-
for (let r = 0; r <
|
|
567
|
-
const o =
|
|
568
|
-
o && (o._tempUnsub ? (n[r] = o._tempUnsub, o._tempUnsub = void 0) : (E.checkCircular(o,
|
|
578
|
+
n.length = i.length;
|
|
579
|
+
for (let r = 0; r < i.length; r++) {
|
|
580
|
+
const o = i[r];
|
|
581
|
+
o && (o._tempUnsub ? (n[r] = o._tempUnsub, o._tempUnsub = void 0) : (E.checkCircular(o, s), n[r] = o.subscribe(s)));
|
|
569
582
|
}
|
|
570
583
|
if (e !== u)
|
|
571
584
|
for (let r = 0; r < e.length; r++) {
|
|
@@ -574,7 +587,7 @@ function de(s, e, t, i) {
|
|
|
574
587
|
}
|
|
575
588
|
return t !== f && y.release(t), n;
|
|
576
589
|
}
|
|
577
|
-
class
|
|
590
|
+
class pe extends Q {
|
|
578
591
|
constructor(e, t) {
|
|
579
592
|
super(), this._isNotificationScheduled = !1, this._value = e, this._functionSubscribersStore = new v(), this._objectSubscribersStore = new v(), this._sync = t, this._notifyTask = this._flushNotifications.bind(this), E.attachDebugInfo(this, "atom", this.id);
|
|
580
593
|
}
|
|
@@ -626,18 +639,18 @@ class Ee extends Q {
|
|
|
626
639
|
this._functionSubscribersStore.clear(), this._objectSubscribersStore.clear(), this._value = void 0;
|
|
627
640
|
}
|
|
628
641
|
}
|
|
629
|
-
function
|
|
630
|
-
return new
|
|
642
|
+
function Ie(i, e = {}) {
|
|
643
|
+
return new pe(i, e.sync ?? !1);
|
|
631
644
|
}
|
|
632
|
-
function R(
|
|
633
|
-
if (
|
|
634
|
-
return new e(`Type error (${t}): ${
|
|
635
|
-
if (
|
|
636
|
-
return new e(`Reference error (${t}): ${
|
|
637
|
-
if (
|
|
638
|
-
return
|
|
639
|
-
const
|
|
640
|
-
return new e(`Unexpected error (${t}): ${
|
|
645
|
+
function R(i, e, t) {
|
|
646
|
+
if (i instanceof TypeError)
|
|
647
|
+
return new e(`Type error (${t}): ${i.message}`, i);
|
|
648
|
+
if (i instanceof ReferenceError)
|
|
649
|
+
return new e(`Reference error (${t}): ${i.message}`, i);
|
|
650
|
+
if (i instanceof b)
|
|
651
|
+
return i;
|
|
652
|
+
const s = i instanceof Error ? i.message : String(i), n = i instanceof Error ? i : null;
|
|
653
|
+
return new e(`Unexpected error (${t}): ${s}`, n);
|
|
641
654
|
}
|
|
642
655
|
const W = c.RESOLVED | c.PENDING | c.REJECTED, M = Array(W + 1).fill(P.IDLE);
|
|
643
656
|
M[c.RESOLVED] = P.RESOLVED;
|
|
@@ -649,18 +662,18 @@ class K extends Q {
|
|
|
649
662
|
throw new N(h.COMPUTED_MUST_BE_FUNCTION);
|
|
650
663
|
if (super(), this._cachedErrors = null, this._errorCacheEpoch = -1, this._value = void 0, this.flags = c.DIRTY | c.IDLE, this._error = null, this._promiseId = 0, this._equal = t.equal ?? Object.is, this._fn = e, this._defaultValue = "defaultValue" in t ? t.defaultValue : j, this._hasDefaultValue = this._defaultValue !== j, this._onError = t.onError ?? null, this.MAX_PROMISE_ID = Number.MAX_SAFE_INTEGER - 1, this._functionSubscribersStore = new v(), this._objectSubscribersStore = new v(), this._dependencies = u, this._dependencyVersions = a, this._unsubscribes = f, this._notifyJob = () => {
|
|
651
664
|
this._functionSubscribersStore.forEachSafe(
|
|
652
|
-
(
|
|
653
|
-
(
|
|
665
|
+
(s) => s(),
|
|
666
|
+
(s) => console.error(s)
|
|
654
667
|
), this._objectSubscribersStore.forEachSafe(
|
|
655
|
-
(
|
|
656
|
-
(
|
|
668
|
+
(s) => s.execute(),
|
|
669
|
+
(s) => console.error(s)
|
|
657
670
|
);
|
|
658
671
|
}, this._trackable = Object.assign(() => this._markDirty(), {
|
|
659
|
-
addDependency: (
|
|
672
|
+
addDependency: (s) => {
|
|
660
673
|
}
|
|
661
674
|
}), E.attachDebugInfo(this, "computed", this.id), E.enabled) {
|
|
662
|
-
const
|
|
663
|
-
|
|
675
|
+
const s = this;
|
|
676
|
+
s.subscriberCount = () => this._functionSubscribersStore.size + this._objectSubscribersStore.size, s.isDirty = () => this._isDirty(), s.dependencies = this._dependencies, s.stateFlags = this._getFlagsAsString();
|
|
664
677
|
}
|
|
665
678
|
if (t.lazy === !1)
|
|
666
679
|
try {
|
|
@@ -704,8 +717,8 @@ class K extends Q {
|
|
|
704
717
|
return this._cachedErrors;
|
|
705
718
|
const t = /* @__PURE__ */ new Set();
|
|
706
719
|
this._error && t.add(this._error);
|
|
707
|
-
for (let
|
|
708
|
-
const n = this._dependencies[
|
|
720
|
+
for (let s = 0; s < this._dependencies.length; s++) {
|
|
721
|
+
const n = this._dependencies[s];
|
|
709
722
|
if (n && "errors" in n) {
|
|
710
723
|
const r = n.errors;
|
|
711
724
|
for (let o = 0; o < r.length; o++) {
|
|
@@ -795,29 +808,29 @@ class K extends Q {
|
|
|
795
808
|
const e = this._prepareComputationContext();
|
|
796
809
|
let t = !1;
|
|
797
810
|
try {
|
|
798
|
-
const
|
|
799
|
-
this._commitDependencies(e), t = !0, H(
|
|
800
|
-
} catch (
|
|
811
|
+
const s = m.run(this._trackable, this._fn);
|
|
812
|
+
this._commitDependencies(e), t = !0, H(s) ? this._handleAsyncComputation(s) : this._handleSyncResult(s);
|
|
813
|
+
} catch (s) {
|
|
801
814
|
if (!t)
|
|
802
815
|
try {
|
|
803
816
|
this._commitDependencies(e), t = !0;
|
|
804
817
|
} catch (n) {
|
|
805
818
|
this._handleComputationError(n);
|
|
806
819
|
}
|
|
807
|
-
this._handleComputationError(
|
|
820
|
+
this._handleComputationError(s);
|
|
808
821
|
} finally {
|
|
809
822
|
this._cleanupContext(e, t), this._setRecomputing(!1);
|
|
810
823
|
}
|
|
811
824
|
}
|
|
812
825
|
_prepareComputationContext() {
|
|
813
|
-
const e = this._dependencies, t = this._dependencyVersions,
|
|
814
|
-
p._lastSeenEpoch !== r && (p._lastSeenEpoch = r, o.depCount <
|
|
826
|
+
const e = this._dependencies, t = this._dependencyVersions, s = S.acquire(), n = d.acquire(), r = $(), o = { depCount: 0 }, _ = (p) => {
|
|
827
|
+
p._lastSeenEpoch !== r && (p._lastSeenEpoch = r, o.depCount < s.length ? (s[o.depCount] = p, n[o.depCount] = p.version) : (s.push(p), n.push(p.version)), o.depCount++);
|
|
815
828
|
}, C = this._trackable.addDependency;
|
|
816
|
-
return this._trackable.addDependency = _, { prevDeps: e, prevVersions: t, nextDeps:
|
|
829
|
+
return this._trackable.addDependency = _, { prevDeps: e, prevVersions: t, nextDeps: s, nextVersions: n, originalAdd: C, state: o };
|
|
817
830
|
}
|
|
818
831
|
_commitDependencies(e) {
|
|
819
|
-
const { nextDeps: t, nextVersions:
|
|
820
|
-
t.length = n.depCount,
|
|
832
|
+
const { nextDeps: t, nextVersions: s, state: n, prevDeps: r } = e;
|
|
833
|
+
t.length = n.depCount, s.length = n.depCount, this._unsubscribes = Ee(t, r, this._unsubscribes, this), this._dependencies = t, this._dependencyVersions = s;
|
|
821
834
|
}
|
|
822
835
|
_cleanupContext(e, t) {
|
|
823
836
|
this._trackable.addDependency = e.originalAdd, t ? (e.prevDeps !== u && S.release(e.prevDeps), e.prevVersions !== a && d.release(e.prevVersions)) : (S.release(e.nextDeps), d.release(e.nextVersions));
|
|
@@ -829,10 +842,10 @@ class K extends Q {
|
|
|
829
842
|
_handleAsyncComputation(e) {
|
|
830
843
|
this._setPending(), this._clearDirty(), this._notifyJob(), this._promiseId = this._promiseId >= this.MAX_PROMISE_ID ? 1 : this._promiseId + 1;
|
|
831
844
|
const t = this._promiseId;
|
|
832
|
-
e.then((
|
|
833
|
-
t === this._promiseId && this._handleAsyncResolution(
|
|
834
|
-
}).catch((
|
|
835
|
-
t === this._promiseId && this._handleAsyncRejection(
|
|
845
|
+
e.then((s) => {
|
|
846
|
+
t === this._promiseId && this._handleAsyncResolution(s);
|
|
847
|
+
}).catch((s) => {
|
|
848
|
+
t === this._promiseId && this._handleAsyncRejection(s);
|
|
836
849
|
});
|
|
837
850
|
}
|
|
838
851
|
_handleAsyncResolution(e) {
|
|
@@ -840,8 +853,8 @@ class K extends Q {
|
|
|
840
853
|
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();
|
|
841
854
|
}
|
|
842
855
|
_handleAsyncRejection(e) {
|
|
843
|
-
const t = R(e, N, h.COMPUTED_ASYNC_COMPUTATION_FAILED),
|
|
844
|
-
if (this.version = this.version + Number(
|
|
856
|
+
const t = R(e, N, h.COMPUTED_ASYNC_COMPUTATION_FAILED), s = !this._isRejected();
|
|
857
|
+
if (this.version = this.version + Number(s) & I, this._error = t, this._setRejected(), this._clearDirty(), this._setRecomputing(!1), this._onError)
|
|
845
858
|
try {
|
|
846
859
|
this._onError(t);
|
|
847
860
|
} catch (n) {
|
|
@@ -854,8 +867,8 @@ class K extends Q {
|
|
|
854
867
|
if (this._error = t, this._setRejected(), this._clearDirty(), this._setRecomputing(!1), this._onError)
|
|
855
868
|
try {
|
|
856
869
|
this._onError(t);
|
|
857
|
-
} catch (
|
|
858
|
-
console.error(h.CALLBACK_ERROR_IN_ERROR_HANDLER,
|
|
870
|
+
} catch (s) {
|
|
871
|
+
console.error(h.CALLBACK_ERROR_IN_ERROR_HANDLER, s);
|
|
859
872
|
}
|
|
860
873
|
throw t;
|
|
861
874
|
}
|
|
@@ -886,10 +899,10 @@ class K extends Q {
|
|
|
886
899
|
}
|
|
887
900
|
}
|
|
888
901
|
Object.freeze(K.prototype);
|
|
889
|
-
function
|
|
890
|
-
return new K(
|
|
902
|
+
function me(i, e = {}) {
|
|
903
|
+
return new K(i, e);
|
|
891
904
|
}
|
|
892
|
-
class
|
|
905
|
+
class be extends Y {
|
|
893
906
|
/**
|
|
894
907
|
* Creates a new EffectImpl instance.
|
|
895
908
|
* @param fn - The effect function to run.
|
|
@@ -935,21 +948,21 @@ class pe extends Y {
|
|
|
935
948
|
this._cleanupEffect(n, r), this._setExecuting(!1);
|
|
936
949
|
}
|
|
937
950
|
}, this._currentEpoch = -1, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._fn = e, this._sync = t.sync ?? !1, this._maxExecutions = t.maxExecutionsPerSecond ?? D.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = t.maxExecutionsPerFlush ?? D.MAX_EXECUTIONS_PER_EFFECT, this._trackModifications = t.trackModifications ?? !1, this._cleanup = null, this._dependencies = u, this._dependencyVersions = a, this._unsubscribes = f, this._nextDeps = null, this._nextVersions = null, this._nextUnsubs = null, this._onError = t.onError ?? null, this._historyPtr = 0;
|
|
938
|
-
const
|
|
939
|
-
this._historyCapacity =
|
|
951
|
+
const s = Number.isFinite(this._maxExecutions);
|
|
952
|
+
this._historyCapacity = s ? Math.min(this._maxExecutions + 1, D.MAX_EXECUTIONS_PER_SECOND + 1) : 0, this._history = l && s && this._historyCapacity > 0 ? new Array(this._historyCapacity).fill(0) : null, this._executionCount = 0, E.attachDebugInfo(this, "effect", this.id);
|
|
940
953
|
}
|
|
941
954
|
/**
|
|
942
955
|
* Prepares the execution context by acquiring pools and setting up epoch.
|
|
943
956
|
* @returns The prepared EffectContext.
|
|
944
957
|
*/
|
|
945
958
|
_prepareEffectContext() {
|
|
946
|
-
const e = this._dependencies, t = this._dependencyVersions,
|
|
947
|
-
if (e !== u &&
|
|
959
|
+
const e = this._dependencies, t = this._dependencyVersions, s = this._unsubscribes, n = S.acquire(), r = d.acquire(), o = y.acquire(), _ = $();
|
|
960
|
+
if (e !== u && s !== f)
|
|
948
961
|
for (let C = 0; C < e.length; C++) {
|
|
949
962
|
const p = e[C];
|
|
950
|
-
p && (p._tempUnsub =
|
|
963
|
+
p && (p._tempUnsub = s[C]);
|
|
951
964
|
}
|
|
952
|
-
return this._nextDeps = n, this._nextVersions = r, this._nextUnsubs = o, this._currentEpoch = _, { prevDeps: e, prevVersions: t, prevUnsubs:
|
|
965
|
+
return this._nextDeps = n, this._nextVersions = r, this._nextUnsubs = o, this._currentEpoch = _, { prevDeps: e, prevVersions: t, prevUnsubs: s, nextDeps: n, nextVersions: r, nextUnsubs: o };
|
|
953
966
|
}
|
|
954
967
|
/**
|
|
955
968
|
* Commits the tracked dependencies as the current active dependencies.
|
|
@@ -967,8 +980,8 @@ class pe extends Y {
|
|
|
967
980
|
_cleanupEffect(e, t) {
|
|
968
981
|
if (this._nextDeps = null, this._nextVersions = null, this._nextUnsubs = null, t) {
|
|
969
982
|
if (e.prevDeps !== u) {
|
|
970
|
-
for (let
|
|
971
|
-
const n = e.prevDeps[
|
|
983
|
+
for (let s = 0; s < e.prevDeps.length; s++) {
|
|
984
|
+
const n = e.prevDeps[s];
|
|
972
985
|
n?._tempUnsub && (n._tempUnsub(), n._tempUnsub = void 0);
|
|
973
986
|
}
|
|
974
987
|
S.release(e.prevDeps);
|
|
@@ -976,11 +989,11 @@ class pe extends Y {
|
|
|
976
989
|
e.prevUnsubs !== f && y.release(e.prevUnsubs), e.prevVersions !== a && d.release(e.prevVersions);
|
|
977
990
|
} else {
|
|
978
991
|
S.release(e.nextDeps), d.release(e.nextVersions);
|
|
979
|
-
for (let
|
|
980
|
-
e.nextUnsubs[
|
|
992
|
+
for (let s = 0; s < e.nextUnsubs.length; s++)
|
|
993
|
+
e.nextUnsubs[s]?.();
|
|
981
994
|
if (y.release(e.nextUnsubs), e.prevDeps !== u)
|
|
982
|
-
for (let
|
|
983
|
-
const n = e.prevDeps[
|
|
995
|
+
for (let s = 0; s < e.prevDeps.length; s++) {
|
|
996
|
+
const n = e.prevDeps[s];
|
|
984
997
|
n && (n._tempUnsub = void 0);
|
|
985
998
|
}
|
|
986
999
|
}
|
|
@@ -1044,12 +1057,12 @@ class pe extends Y {
|
|
|
1044
1057
|
*/
|
|
1045
1058
|
_checkInfiniteLoop() {
|
|
1046
1059
|
if (this._lastFlushEpoch !== U && (this._lastFlushEpoch = U, this._executionsInEpoch = 0), this._executionsInEpoch++, this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), oe() > D.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++, this._history && this._maxExecutions > 0) {
|
|
1047
|
-
const e = Date.now(), t = this._historyPtr,
|
|
1060
|
+
const e = Date.now(), t = this._historyPtr, s = this._historyCapacity;
|
|
1048
1061
|
this._history[t] = e;
|
|
1049
|
-
const n = (t + 1) %
|
|
1062
|
+
const n = (t + 1) % s, r = this._history[n] ?? 0;
|
|
1050
1063
|
if (this._historyPtr = n, r > 0 && e - r < Z.ONE_SECOND_MS) {
|
|
1051
1064
|
const o = new g(
|
|
1052
|
-
`Effect executed ${
|
|
1065
|
+
`Effect executed ${s} times within 1 second. Infinite loop suspected`
|
|
1053
1066
|
);
|
|
1054
1067
|
if (this.dispose(), console.error(o), this._onError && this._onError(o), l)
|
|
1055
1068
|
throw o;
|
|
@@ -1074,7 +1087,7 @@ class pe extends Y {
|
|
|
1074
1087
|
if (t) {
|
|
1075
1088
|
if ("value" in t)
|
|
1076
1089
|
try {
|
|
1077
|
-
|
|
1090
|
+
ue(() => t.value);
|
|
1078
1091
|
} catch {
|
|
1079
1092
|
return !0;
|
|
1080
1093
|
}
|
|
@@ -1100,19 +1113,19 @@ class pe extends Y {
|
|
|
1100
1113
|
if (this._trackModifications && E.enabled) {
|
|
1101
1114
|
const e = this._dependencies;
|
|
1102
1115
|
for (let t = 0; t < e.length; t++) {
|
|
1103
|
-
const
|
|
1104
|
-
|
|
1116
|
+
const s = e[t];
|
|
1117
|
+
s && s._modifiedAtEpoch === this._currentEpoch && E.warn(
|
|
1105
1118
|
!0,
|
|
1106
|
-
`Effect is reading a dependency (${E.getDebugName(
|
|
1119
|
+
`Effect is reading a dependency (${E.getDebugName(s) || "unknown"}) that it just modified. Infinite loop may occur`
|
|
1107
1120
|
);
|
|
1108
1121
|
}
|
|
1109
1122
|
}
|
|
1110
1123
|
}
|
|
1111
1124
|
}
|
|
1112
|
-
function
|
|
1113
|
-
if (typeof
|
|
1125
|
+
function Ce(i, e = {}) {
|
|
1126
|
+
if (typeof i != "function")
|
|
1114
1127
|
throw new g(h.EFFECT_MUST_BE_FUNCTION);
|
|
1115
|
-
const t = new
|
|
1128
|
+
const t = new be(i, e);
|
|
1116
1129
|
return t.execute(), t;
|
|
1117
1130
|
}
|
|
1118
1131
|
export {
|
|
@@ -1122,17 +1135,17 @@ export {
|
|
|
1122
1135
|
B as DEBUG_CONFIG,
|
|
1123
1136
|
E as DEBUG_RUNTIME,
|
|
1124
1137
|
g as EffectError,
|
|
1125
|
-
|
|
1138
|
+
Se as POOL_CONFIG,
|
|
1126
1139
|
D as SCHEDULER_CONFIG,
|
|
1127
1140
|
O as SchedulerError,
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1141
|
+
Ie as atom,
|
|
1142
|
+
ge as batch,
|
|
1143
|
+
me as computed,
|
|
1144
|
+
Ce as effect,
|
|
1145
|
+
ae as isAtom,
|
|
1146
|
+
De as isComputed,
|
|
1147
|
+
ye as isEffect,
|
|
1135
1148
|
T as scheduler,
|
|
1136
|
-
|
|
1149
|
+
ue as untracked
|
|
1137
1150
|
};
|
|
1138
1151
|
//# sourceMappingURL=index.mjs.map
|