@but212/atom-effect 0.22.0 → 0.22.2
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 +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.mjs +46 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -35,13 +35,13 @@ const b = {
|
|
|
35
35
|
MIN_FLUSH_ITERATIONS: 10,
|
|
36
36
|
// Memory management
|
|
37
37
|
BATCH_QUEUE_SHRINK_THRESHOLD: 1e3
|
|
38
|
-
},
|
|
38
|
+
}, rt = {
|
|
39
39
|
WARN_INFINITE_LOOP: !0,
|
|
40
40
|
EFFECT_FREQUENCY_WINDOW: 1e3
|
|
41
41
|
}, H = {
|
|
42
42
|
MAX_ASYNC_RETRIES: 3,
|
|
43
43
|
MAX_PROMISE_ID: Number.MAX_SAFE_INTEGER - 1
|
|
44
|
-
},
|
|
44
|
+
}, L = 1073741823, W = typeof process < "u" && process.env && !1 || !1, ot = Object.freeze([]);
|
|
45
45
|
class D extends Error {
|
|
46
46
|
constructor(t, e = null, s = !0) {
|
|
47
47
|
super(t), this.cause = e, this.recoverable = s, this.name = "AtomError";
|
|
@@ -62,10 +62,10 @@ class m extends D {
|
|
|
62
62
|
super(t, e, !1), this.name = "SchedulerError";
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
const
|
|
65
|
+
const ht = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), ct = /* @__PURE__ */ Symbol("AtomEffect.Type"), x = /* @__PURE__ */ Symbol("AtomEffect.NoDefaultValue"), F = {
|
|
66
66
|
// Dev mode flag
|
|
67
67
|
enabled: W,
|
|
68
|
-
warnInfiniteLoop:
|
|
68
|
+
warnInfiniteLoop: rt.WARN_INFINITE_LOOP,
|
|
69
69
|
warn(i, t) {
|
|
70
70
|
},
|
|
71
71
|
checkCircular(i, t) {
|
|
@@ -74,11 +74,11 @@ const ot = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), ht = /* @__PURE__ */
|
|
|
74
74
|
},
|
|
75
75
|
attachDebugInfo(i, t, e) {
|
|
76
76
|
},
|
|
77
|
-
getDebugName: (i) => i?.[
|
|
78
|
-
getDebugType: (i) => i?.[
|
|
77
|
+
getDebugName: (i) => i?.[ht],
|
|
78
|
+
getDebugType: (i) => i?.[ct]
|
|
79
79
|
};
|
|
80
|
-
let
|
|
81
|
-
const
|
|
80
|
+
let ut = 1;
|
|
81
|
+
const _t = () => ut++;
|
|
82
82
|
function K(i, t, e) {
|
|
83
83
|
if (typeof t == "function") {
|
|
84
84
|
const n = t;
|
|
@@ -146,7 +146,7 @@ function S(i, t, e) {
|
|
|
146
146
|
}
|
|
147
147
|
class J {
|
|
148
148
|
constructor() {
|
|
149
|
-
this.flags = 0, this.version = 0, this._lastSeenEpoch = -1, this.id =
|
|
149
|
+
this.flags = 0, this.version = 0, this._lastSeenEpoch = -1, this.id = _t() & L;
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
class Z extends J {
|
|
@@ -195,15 +195,15 @@ class Z extends J {
|
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
let k = 0;
|
|
198
|
-
const w = () => (k = k + 1 &
|
|
199
|
-
let B = 0,
|
|
200
|
-
const
|
|
198
|
+
const w = () => (k = k + 1 & L || 1, k), M = (i) => i + 1 & L;
|
|
199
|
+
let B = 0, R = !1, tt = 0;
|
|
200
|
+
const et = () => tt;
|
|
201
201
|
function X() {
|
|
202
|
-
return
|
|
202
|
+
return R ? !1 : (R = !0, tt = w(), B = 0, !0);
|
|
203
203
|
}
|
|
204
204
|
const G = () => {
|
|
205
|
-
|
|
206
|
-
}, at = () =>
|
|
205
|
+
R = !1;
|
|
206
|
+
}, at = () => R ? ++B : 0;
|
|
207
207
|
class lt {
|
|
208
208
|
constructor() {
|
|
209
209
|
this._queueBuffer = [[], []], this._bufferIndex = 0, this._size = 0, this._epoch = 0, this._isProcessing = !1, this._isBatching = !1, this._isFlushingSync = !1, this._batchDepth = 0, this._batchQueue = [], this._batchQueueSize = 0, this._maxFlushIterations = d.MAX_FLUSH_ITERATIONS, this.onOverflow = null, this._boundRunLoop = this._runLoop.bind(this);
|
|
@@ -311,7 +311,7 @@ class lt {
|
|
|
311
311
|
this._maxFlushIterations = t;
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
|
-
const T = new lt(), z = /* @__PURE__ */ Symbol.for("atom-effect/atom"),
|
|
314
|
+
const T = new lt(), z = /* @__PURE__ */ Symbol.for("atom-effect/atom"), st = /* @__PURE__ */ Symbol.for("atom-effect/computed"), it = /* @__PURE__ */ Symbol.for("atom-effect/effect"), _ = {
|
|
315
315
|
/** Active listener. */
|
|
316
316
|
current: null,
|
|
317
317
|
/**
|
|
@@ -460,25 +460,25 @@ function Tt(i) {
|
|
|
460
460
|
return i !== null && typeof i == "object" && z in i;
|
|
461
461
|
}
|
|
462
462
|
function Ot(i) {
|
|
463
|
-
return i !== null && typeof i == "object" &&
|
|
463
|
+
return i !== null && typeof i == "object" && st in i;
|
|
464
464
|
}
|
|
465
465
|
function bt(i) {
|
|
466
|
-
return i !== null && typeof i == "object" &&
|
|
466
|
+
return i !== null && typeof i == "object" && it in i;
|
|
467
467
|
}
|
|
468
|
-
function
|
|
468
|
+
function nt(i) {
|
|
469
469
|
return i !== null && typeof i == "object" && typeof i.then == "function";
|
|
470
470
|
}
|
|
471
471
|
var Y, q;
|
|
472
|
-
const { IDLE: A, DIRTY: p, PENDING:
|
|
472
|
+
const { IDLE: A, DIRTY: p, PENDING: N, RESOLVED: E, REJECTED: g, HAS_ERROR: y, RECOMPUTING: C, DISPOSED: U, IS_COMPUTED: dt } = $;
|
|
473
473
|
function pt(i) {
|
|
474
|
-
return i & E ? b.RESOLVED : i &
|
|
474
|
+
return i & E ? b.RESOLVED : i & N ? b.PENDING : i & g ? b.REJECTED : b.IDLE;
|
|
475
475
|
}
|
|
476
476
|
class It extends Z {
|
|
477
477
|
constructor(t, e = {}) {
|
|
478
478
|
if (typeof t != "function") throw new f(h.COMPUTED_MUST_BE_FUNCTION);
|
|
479
|
-
super(), this[q] = !0, this[Y] = !0, this._error = null, this._promiseId = 0, this._subscribers = [], this._links = c, this._asyncStartAggregateVersion = 0, this._asyncRetryCount = 0, this._trackEpoch = -1, this._trackLinks = c, this._trackCount = 0, this._value = void 0, this.flags = dt | p | A, this._equal = e.equal ?? Object.is, this._fn = t, this._defaultValue = "defaultValue" in e ? e.defaultValue : x, this._onError = e.onError ?? null;
|
|
479
|
+
super(), this[q] = !0, this[Y] = !0, this._error = null, this._promiseId = 0, this._subscribers = [], this._links = c, this._asyncStartAggregateVersion = 0, this._asyncRetryCount = 0, this._lastDriftEpoch = -1, this._trackEpoch = -1, this._trackLinks = c, this._trackCount = 0, this._value = void 0, this.flags = dt | p | A, this._equal = e.equal ?? Object.is, this._fn = t, this._defaultValue = "defaultValue" in e ? e.defaultValue : x, this._onError = e.onError ?? null;
|
|
480
480
|
const s = e.maxAsyncRetries;
|
|
481
|
-
if (this._maxAsyncRetries = (s ?? H.MAX_ASYNC_RETRIES) &
|
|
481
|
+
if (this._maxAsyncRetries = (s ?? H.MAX_ASYNC_RETRIES) & L, F.attachDebugInfo(this, "computed", this.id), e.lazy === !1)
|
|
482
482
|
try {
|
|
483
483
|
this._recompute();
|
|
484
484
|
} catch {
|
|
@@ -502,7 +502,7 @@ class It extends Z {
|
|
|
502
502
|
if (t & (p | A) && (this._recompute(), this.flags & E))
|
|
503
503
|
return this._value;
|
|
504
504
|
const e = this._defaultValue, s = e !== x;
|
|
505
|
-
if (this.flags &
|
|
505
|
+
if (this.flags & N) {
|
|
506
506
|
if (s) return e;
|
|
507
507
|
throw new f(h.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
|
|
508
508
|
}
|
|
@@ -519,17 +519,17 @@ class It extends Z {
|
|
|
519
519
|
return this._track(), pt(this.flags);
|
|
520
520
|
}
|
|
521
521
|
get hasError() {
|
|
522
|
-
return this._track(), this.flags & (g |
|
|
522
|
+
return this._track(), this.flags & (g | y) ? !0 : this._links.some((t) => t?.node?.flags & y);
|
|
523
523
|
}
|
|
524
524
|
get isValid() {
|
|
525
525
|
return !this.hasError;
|
|
526
526
|
}
|
|
527
527
|
get errors() {
|
|
528
|
-
if (this._track(), !this.hasError) return
|
|
528
|
+
if (this._track(), !this.hasError) return ot;
|
|
529
529
|
const t = [];
|
|
530
530
|
return this._error && t.push(this._error), this._links.forEach((s) => {
|
|
531
531
|
const n = s.node;
|
|
532
|
-
n.flags &
|
|
532
|
+
n.flags & y && n.errors.forEach((o) => {
|
|
533
533
|
o && !t.includes(o) && t.push(o);
|
|
534
534
|
});
|
|
535
535
|
}), Object.freeze(t);
|
|
@@ -538,7 +538,7 @@ class It extends Z {
|
|
|
538
538
|
return this._track(), this._error;
|
|
539
539
|
}
|
|
540
540
|
get isPending() {
|
|
541
|
-
return this._track(), (this.flags &
|
|
541
|
+
return this._track(), (this.flags & N) !== 0;
|
|
542
542
|
}
|
|
543
543
|
get isResolved() {
|
|
544
544
|
return this._track(), (this.flags & E) !== 0;
|
|
@@ -551,7 +551,7 @@ class It extends Z {
|
|
|
551
551
|
const t = this._links;
|
|
552
552
|
t !== c && (t.forEach((e) => e.unsub?.()), l.release(t), this._links = c), this._subscribers.length = 0, this.flags = U | p | A, this._error = null, this._value = void 0;
|
|
553
553
|
}
|
|
554
|
-
[(q = z, Y =
|
|
554
|
+
[(q = z, Y = st, Symbol.dispose)]() {
|
|
555
555
|
this.dispose();
|
|
556
556
|
}
|
|
557
557
|
addDependency(t) {
|
|
@@ -572,7 +572,7 @@ class It extends Z {
|
|
|
572
572
|
let e = !1;
|
|
573
573
|
try {
|
|
574
574
|
const s = _.run(this, this._fn);
|
|
575
|
-
this._trackLinks.length = this._trackCount, V(this._trackLinks, t, this), this._links = this._trackLinks, e = !0,
|
|
575
|
+
this._trackLinks.length = this._trackCount, V(this._trackLinks, t, this), this._links = this._trackLinks, e = !0, nt(s) ? this._handleAsyncComputation(s) : this._finalizeResolution(s);
|
|
576
576
|
} catch (s) {
|
|
577
577
|
if (!e)
|
|
578
578
|
try {
|
|
@@ -585,18 +585,20 @@ class It extends Z {
|
|
|
585
585
|
}
|
|
586
586
|
}
|
|
587
587
|
_handleAsyncComputation(t) {
|
|
588
|
-
this.flags = (this.flags |
|
|
588
|
+
this.flags = (this.flags | N) & -217, this._notifySubscribers(void 0, void 0), this._asyncStartAggregateVersion = this._captureVersionSnapshot(), this._asyncRetryCount = 0, this._promiseId = (this._promiseId + 1) % H.MAX_PROMISE_ID;
|
|
589
589
|
const e = this._promiseId;
|
|
590
590
|
t.then(
|
|
591
591
|
(s) => {
|
|
592
592
|
if (e === this._promiseId) {
|
|
593
|
-
if (this._captureVersionSnapshot() !== this._asyncStartAggregateVersion)
|
|
594
|
-
|
|
593
|
+
if (this._captureVersionSnapshot() !== this._asyncStartAggregateVersion) {
|
|
594
|
+
const n = et();
|
|
595
|
+
return this._lastDriftEpoch !== n && (this._lastDriftEpoch = n, this._asyncRetryCount = 0), this._asyncRetryCount++ < this._maxAsyncRetries ? this._markDirty() : this._handleError(
|
|
595
596
|
new f(
|
|
596
597
|
`Async drift threshold exceeded after ${this._maxAsyncRetries} retries.`
|
|
597
598
|
),
|
|
598
599
|
h.COMPUTED_ASYNC_COMPUTATION_FAILED
|
|
599
600
|
);
|
|
601
|
+
}
|
|
600
602
|
this._finalizeResolution(s), this._notifySubscribers(s, void 0);
|
|
601
603
|
}
|
|
602
604
|
},
|
|
@@ -612,7 +614,7 @@ class It extends Z {
|
|
|
612
614
|
}
|
|
613
615
|
_handleError(t, e, s = !1) {
|
|
614
616
|
const n = S(t, f, e);
|
|
615
|
-
if (!s && !(this.flags & g) && (this.version = M(this.version)), this._error = n, this.flags = this.flags & -121 | g |
|
|
617
|
+
if (!s && !(this.flags & g) && (this.version = M(this.version)), this._error = n, this.flags = this.flags & -121 | g | y, this._onError)
|
|
616
618
|
try {
|
|
617
619
|
this._onError(n);
|
|
618
620
|
} catch (r) {
|
|
@@ -648,7 +650,7 @@ class St extends J {
|
|
|
648
650
|
dispose() {
|
|
649
651
|
this.flags & u.DISPOSED || (this.flags |= u.DISPOSED, this._execCleanup(), this._unsubLinks(this._links), this._links !== c && l.release(this._links), this._links = c, this._prevLinks = c);
|
|
650
652
|
}
|
|
651
|
-
[(j =
|
|
653
|
+
[(j = it, Symbol.dispose)]() {
|
|
652
654
|
this.dispose();
|
|
653
655
|
}
|
|
654
656
|
addDependency(t) {
|
|
@@ -686,7 +688,7 @@ class St extends J {
|
|
|
686
688
|
let s = !1;
|
|
687
689
|
try {
|
|
688
690
|
const n = _.run(this, this._fn);
|
|
689
|
-
this._links = e, s = !0,
|
|
691
|
+
this._links = e, s = !0, nt(n) ? this._handleAsyncResult(n) : this._cleanup = typeof n == "function" ? n : null;
|
|
690
692
|
} catch (n) {
|
|
691
693
|
this._links = e, s = !0, this._handleExecutionError(n), this._cleanup = null;
|
|
692
694
|
} finally {
|
|
@@ -746,7 +748,7 @@ class St extends J {
|
|
|
746
748
|
}
|
|
747
749
|
}
|
|
748
750
|
_checkInfiniteLoops() {
|
|
749
|
-
const t =
|
|
751
|
+
const t = et();
|
|
750
752
|
this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), at() > d.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++;
|
|
751
753
|
}
|
|
752
754
|
get isDisposed() {
|
|
@@ -774,13 +776,13 @@ class St extends J {
|
|
|
774
776
|
}
|
|
775
777
|
}
|
|
776
778
|
}
|
|
777
|
-
function
|
|
779
|
+
function yt(i, t = {}) {
|
|
778
780
|
if (typeof i != "function")
|
|
779
781
|
throw new I(h.EFFECT_MUST_BE_FUNCTION);
|
|
780
782
|
const e = new St(i, t);
|
|
781
783
|
return e.execute(), e;
|
|
782
784
|
}
|
|
783
|
-
function
|
|
785
|
+
function Nt(i) {
|
|
784
786
|
if (typeof i != "function")
|
|
785
787
|
throw new TypeError("Batch callback must be a function");
|
|
786
788
|
T.startBatch();
|
|
@@ -794,19 +796,19 @@ export {
|
|
|
794
796
|
z as ATOM_BRAND,
|
|
795
797
|
b as AsyncState,
|
|
796
798
|
D as AtomError,
|
|
797
|
-
|
|
799
|
+
st as COMPUTED_BRAND,
|
|
798
800
|
f as ComputedError,
|
|
799
|
-
|
|
801
|
+
rt as DEBUG_CONFIG,
|
|
800
802
|
F as DEBUG_RUNTIME,
|
|
801
|
-
|
|
803
|
+
it as EFFECT_BRAND,
|
|
802
804
|
I as EffectError,
|
|
803
805
|
Dt as POOL_CONFIG,
|
|
804
806
|
d as SCHEDULER_CONFIG,
|
|
805
807
|
m as SchedulerError,
|
|
806
808
|
gt as atom,
|
|
807
|
-
|
|
809
|
+
Nt as batch,
|
|
808
810
|
At as computed,
|
|
809
|
-
|
|
811
|
+
yt as effect,
|
|
810
812
|
Tt as isAtom,
|
|
811
813
|
Ot as isComputed,
|
|
812
814
|
bt as isEffect,
|