@but212/atom-effect 0.24.1 → 0.25.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 +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 +31 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -34,7 +34,7 @@ var b = {
|
|
|
34
34
|
}, j = {
|
|
35
35
|
MAX_ASYNC_RETRIES: 3,
|
|
36
36
|
MAX_PROMISE_ID: Number.MAX_SAFE_INTEGER - 1
|
|
37
|
-
},
|
|
37
|
+
}, C = {
|
|
38
38
|
UNINITIALIZED: -1,
|
|
39
39
|
MIN: 1
|
|
40
40
|
}, G = 1073741823, q = { VERSION_BITS: 16 }, Ct = (typeof process < "u" && process.env, !1), W = Object.freeze([]), H = class {
|
|
@@ -48,19 +48,19 @@ var b = {
|
|
|
48
48
|
notify(t, s) {
|
|
49
49
|
this.fn ? this.fn(t, s) : this.sub && this.sub.execute();
|
|
50
50
|
}
|
|
51
|
-
},
|
|
51
|
+
}, A = class extends Error {
|
|
52
52
|
constructor(t, s = null, e = !0) {
|
|
53
53
|
super(t), this.cause = s, this.recoverable = e, this.name = "AtomError";
|
|
54
54
|
}
|
|
55
|
-
}, S = class extends
|
|
55
|
+
}, S = class extends A {
|
|
56
56
|
constructor(t, s = null) {
|
|
57
57
|
super(t, s, !0), this.name = "ComputedError";
|
|
58
58
|
}
|
|
59
|
-
}, D = class extends
|
|
59
|
+
}, D = class extends A {
|
|
60
60
|
constructor(t, s = null) {
|
|
61
61
|
super(t, s, !1), this.name = "EffectError";
|
|
62
62
|
}
|
|
63
|
-
}, R = class extends
|
|
63
|
+
}, R = class extends A {
|
|
64
64
|
constructor(t, s = null) {
|
|
65
65
|
super(t, s, !1), this.name = "SchedulerError";
|
|
66
66
|
}
|
|
@@ -85,7 +85,7 @@ var b = {
|
|
|
85
85
|
BATCH_CALLBACK_MUST_BE_FUNCTION: "Batch callback must be a function"
|
|
86
86
|
}, et = class {
|
|
87
87
|
constructor() {
|
|
88
|
-
this._s0 = null, this._s1 = null, this._s2 = null, this._s3 = null, this._count = 0, this.
|
|
88
|
+
this._s0 = null, this._s1 = null, this._s2 = null, this._s3 = null, this._count = 0, this._overflow = null;
|
|
89
89
|
}
|
|
90
90
|
get size() {
|
|
91
91
|
return this._count;
|
|
@@ -286,28 +286,28 @@ var b = {
|
|
|
286
286
|
dispose() {
|
|
287
287
|
this.clear();
|
|
288
288
|
}
|
|
289
|
-
},
|
|
289
|
+
}, K = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), lt = /* @__PURE__ */ Symbol("AtomEffect.Id"), Z = /* @__PURE__ */ Symbol("AtomEffect.Type"), U = /* @__PURE__ */ Symbol("AtomEffect.NoDefaultValue"), X = {
|
|
290
290
|
enabled: !1,
|
|
291
291
|
warnInfiniteLoop: st.WARN_INFINITE_LOOP,
|
|
292
292
|
warn(t, s) {
|
|
293
293
|
},
|
|
294
294
|
attachDebugInfo(t, s, e) {
|
|
295
295
|
},
|
|
296
|
-
getDebugName: (t) => t?.[
|
|
297
|
-
getDebugType: (t) => t?.[
|
|
296
|
+
getDebugName: (t) => t?.[K],
|
|
297
|
+
getDebugType: (t) => t?.[Z]
|
|
298
298
|
}, _t = 1, ct = () => _t++;
|
|
299
299
|
function T(t, s, e) {
|
|
300
|
-
if (t instanceof
|
|
300
|
+
if (t instanceof A) return t;
|
|
301
301
|
const i = t instanceof Error, n = i ? t.message : String(t), r = i ? t : void 0;
|
|
302
302
|
return new s(`${i ? t.constructor.name : "Unexpected error"} (${e}): ${n}`, r);
|
|
303
303
|
}
|
|
304
304
|
var V = class {
|
|
305
305
|
constructor() {
|
|
306
|
-
this.flags = 0, this.version = 0, this._lastSeenEpoch =
|
|
306
|
+
this.flags = 0, this.version = 0, this._lastSeenEpoch = C.UNINITIALIZED, this._notifying = 0, this._hotIndex = -1, this._slots = null, this._deps = null, this.id = ct() & G;
|
|
307
307
|
}
|
|
308
308
|
subscribe(t) {
|
|
309
309
|
const s = typeof t == "function";
|
|
310
|
-
if (!s && (!t || typeof t.execute != "function")) throw T(/* @__PURE__ */ new TypeError("Invalid subscriber"),
|
|
310
|
+
if (!s && (!t || typeof t.execute != "function")) throw T(/* @__PURE__ */ new TypeError("Invalid subscriber"), A, l.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
|
|
311
311
|
let e = this._slots;
|
|
312
312
|
e || (e = new et(), this._slots = e);
|
|
313
313
|
let i = !1;
|
|
@@ -340,7 +340,7 @@ var V = class {
|
|
|
340
340
|
try {
|
|
341
341
|
i.notify(t, s);
|
|
342
342
|
} catch (n) {
|
|
343
|
-
console.error(T(n,
|
|
343
|
+
console.error(T(n, A, l.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED));
|
|
344
344
|
}
|
|
345
345
|
});
|
|
346
346
|
} finally {
|
|
@@ -733,10 +733,10 @@ function mt(t) {
|
|
|
733
733
|
function ht(t) {
|
|
734
734
|
return t !== null && typeof t == "object" && typeof t.then == "function";
|
|
735
735
|
}
|
|
736
|
-
var { IDLE:
|
|
736
|
+
var { IDLE: I, DIRTY: E, PENDING: g, RESOLVED: p, REJECTED: v, HAS_ERROR: N, RECOMPUTING: O, DISPOSED: M, IS_COMPUTED: P, FORCE_COMPUTE: B } = x, pt = class extends V {
|
|
737
737
|
constructor(t, s = {}) {
|
|
738
738
|
if (typeof t != "function") throw new S(l.COMPUTED_MUST_BE_FUNCTION);
|
|
739
|
-
if (super(), this[$] = !0, this[rt] = !0, this._error = null, this._promiseId = 0, this._deps = new k(), this._asyncRetryCount = 0, this._lastDriftEpoch =
|
|
739
|
+
if (super(), this[$] = !0, this[rt] = !0, this._error = null, this._promiseId = 0, this._deps = new k(), this._asyncRetryCount = 0, this._lastDriftEpoch = C.UNINITIALIZED, this._trackEpoch = C.UNINITIALIZED, this._trackCount = 0, this._value = void 0, this.flags = P | E | I, this._equal = s.equal ?? Object.is, this._fn = t, this._defaultValue = "defaultValue" in s ? s.defaultValue : U, this._onError = s.onError ?? null, this._maxAsyncRetries = (s.maxAsyncRetries ?? j.MAX_ASYNC_RETRIES) & G, X.attachDebugInfo(this, "computed", this.id), s.lazy === !1) try {
|
|
740
740
|
this._recompute();
|
|
741
741
|
} catch {
|
|
742
742
|
}
|
|
@@ -747,13 +747,13 @@ var { IDLE: C, DIRTY: E, PENDING: g, RESOLVED: p, REJECTED: v, HAS_ERROR: A, REC
|
|
|
747
747
|
get value() {
|
|
748
748
|
this._track();
|
|
749
749
|
const t = this.flags;
|
|
750
|
-
if ((t & (p | E |
|
|
750
|
+
if ((t & (p | E | I)) === p) return this._value;
|
|
751
751
|
if (t & M) throw new S(l.COMPUTED_DISPOSED);
|
|
752
752
|
if (t & O) {
|
|
753
753
|
if (this._defaultValue !== U) return this._defaultValue;
|
|
754
754
|
throw new S(l.COMPUTED_CIRCULAR_DEPENDENCY);
|
|
755
755
|
}
|
|
756
|
-
if (t & (E |
|
|
756
|
+
if (t & (E | I) && ((t & I) === 0 && (t & B) === 0 && this._deps.size > 0 && !this._isDirty() ? this.flags &= ~E : this._recompute(), this.flags & p))
|
|
757
757
|
return this._value;
|
|
758
758
|
const s = this._defaultValue, e = s !== U;
|
|
759
759
|
if (this.flags & g) {
|
|
@@ -775,13 +775,13 @@ var { IDLE: C, DIRTY: E, PENDING: g, RESOLVED: p, REJECTED: v, HAS_ERROR: A, REC
|
|
|
775
775
|
return t & p ? b.RESOLVED : t & g ? b.PENDING : t & v ? b.REJECTED : b.IDLE;
|
|
776
776
|
}
|
|
777
777
|
get hasError() {
|
|
778
|
-
if (this._track(), this.flags & (v |
|
|
778
|
+
if (this._track(), this.flags & (v | N)) return !0;
|
|
779
779
|
const t = this._deps;
|
|
780
780
|
if (!t.hasComputeds) return !1;
|
|
781
781
|
const s = t.size;
|
|
782
782
|
for (let e = 0; e < s; e++) {
|
|
783
783
|
const i = t.getAt(e);
|
|
784
|
-
if (i != null && i.node.flags &
|
|
784
|
+
if (i != null && i.node.flags & N) return !0;
|
|
785
785
|
}
|
|
786
786
|
return !1;
|
|
787
787
|
}
|
|
@@ -799,7 +799,7 @@ var { IDLE: C, DIRTY: E, PENDING: g, RESOLVED: p, REJECTED: v, HAS_ERROR: A, REC
|
|
|
799
799
|
const n = s.getAt(i);
|
|
800
800
|
if (n == null) continue;
|
|
801
801
|
const r = n.node;
|
|
802
|
-
r.flags &
|
|
802
|
+
r.flags & N && this._collectErrorsFromDep(r, t);
|
|
803
803
|
}
|
|
804
804
|
return t.length === 0 ? W : Object.freeze(t);
|
|
805
805
|
}
|
|
@@ -823,7 +823,7 @@ var { IDLE: C, DIRTY: E, PENDING: g, RESOLVED: p, REJECTED: v, HAS_ERROR: A, REC
|
|
|
823
823
|
this.flags |= B, this._markDirty();
|
|
824
824
|
}
|
|
825
825
|
dispose() {
|
|
826
|
-
this.flags & M || (this._deps.disposeAll(), this._slots?.clear(), this.flags = M | E |
|
|
826
|
+
this.flags & M || (this._deps.disposeAll(), this._slots?.clear(), this.flags = M | E | I, this._error = null, this._value = void 0, this._hotIndex = -1);
|
|
827
827
|
}
|
|
828
828
|
[Symbol.dispose]() {
|
|
829
829
|
this.dispose();
|
|
@@ -853,11 +853,11 @@ var { IDLE: C, DIRTY: E, PENDING: g, RESOLVED: p, REJECTED: v, HAS_ERROR: A, REC
|
|
|
853
853
|
}
|
|
854
854
|
this._handleError(s, l.COMPUTED_COMPUTATION_FAILED, !0);
|
|
855
855
|
} finally {
|
|
856
|
-
this._trackEpoch =
|
|
856
|
+
this._trackEpoch = C.UNINITIALIZED, this._trackCount = 0, this.flags &= ~O;
|
|
857
857
|
}
|
|
858
858
|
}
|
|
859
859
|
_handleAsyncComputation(t) {
|
|
860
|
-
this.flags = (this.flags | g) & ~(
|
|
860
|
+
this.flags = (this.flags | g) & ~(I | E | p | v), this._notifySubscribers(void 0, void 0), this._asyncRetryCount = 0, this._promiseId = (this._promiseId + 1) % j.MAX_PROMISE_ID;
|
|
861
861
|
const s = this._promiseId;
|
|
862
862
|
t.then((e) => {
|
|
863
863
|
if (s === this._promiseId) {
|
|
@@ -871,7 +871,7 @@ var { IDLE: C, DIRTY: E, PENDING: g, RESOLVED: p, REJECTED: v, HAS_ERROR: A, REC
|
|
|
871
871
|
}
|
|
872
872
|
_handleError(t, s, e = !1) {
|
|
873
873
|
const i = T(t, S, s);
|
|
874
|
-
if (!e && !(this.flags & v) && (this.version = z(this.version)), this._error = i, this.flags = this.flags & ~(
|
|
874
|
+
if (!e && !(this.flags & v) && (this.version = z(this.version)), this._error = i, this.flags = this.flags & ~(I | E | g | p) | v | N, this._onError) try {
|
|
875
875
|
this._onError(i);
|
|
876
876
|
} catch (n) {
|
|
877
877
|
console.error(l.CALLBACK_ERROR_IN_ERROR_HANDLER, n);
|
|
@@ -880,7 +880,7 @@ var { IDLE: C, DIRTY: E, PENDING: g, RESOLVED: p, REJECTED: v, HAS_ERROR: A, REC
|
|
|
880
880
|
this._notifySubscribers(void 0, void 0);
|
|
881
881
|
}
|
|
882
882
|
_finalizeResolution(t) {
|
|
883
|
-
(!(this.flags & p) || !this._equal(this._value, t)) && (this.version = z(this.version)), this._value = t, this._error = null, this.flags = (this.flags | p) & ~(
|
|
883
|
+
(!(this.flags & p) || !this._equal(this._value, t)) && (this.version = z(this.version)), this._value = t, this._error = null, this.flags = (this.flags | p) & ~(I | E | g | v | N);
|
|
884
884
|
}
|
|
885
885
|
execute() {
|
|
886
886
|
this._markDirty();
|
|
@@ -919,7 +919,7 @@ function Tt(t, s = {}) {
|
|
|
919
919
|
}
|
|
920
920
|
var It = class extends V {
|
|
921
921
|
constructor(t, s = {}) {
|
|
922
|
-
super(), this[ot] = !0, this._cleanup = null, this._deps = new k(), this._currentEpoch =
|
|
922
|
+
super(), this[ot] = !0, this._cleanup = null, this._deps = new k(), this._currentEpoch = C.UNINITIALIZED, this._lastFlushEpoch = C.UNINITIALIZED, this._fn = t, this._onError = s.onError ?? null, this._sync = s.sync ?? !1, this._maxExecutions = s.maxExecutionsPerSecond ?? m.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = s.maxExecutionsPerFlush ?? m.MAX_EXECUTIONS_PER_EFFECT, this._cleanup = null, this._deps = new k(), this._currentEpoch = C.UNINITIALIZED, this._lastFlushEpoch = C.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 = () => y.schedule(this), X.attachDebugInfo(this, "effect", this.id);
|
|
923
923
|
}
|
|
924
924
|
run() {
|
|
925
925
|
if (this.flags & f.DISPOSED) throw new D(l.EFFECT_DISPOSED);
|
|
@@ -1064,12 +1064,12 @@ var It = class extends V {
|
|
|
1064
1064
|
}
|
|
1065
1065
|
}
|
|
1066
1066
|
};
|
|
1067
|
-
function
|
|
1067
|
+
function At(t, s = {}) {
|
|
1068
1068
|
if (typeof t != "function") throw new D(l.EFFECT_MUST_BE_FUNCTION);
|
|
1069
1069
|
const e = new It(t, s);
|
|
1070
1070
|
return e.execute(), e;
|
|
1071
1071
|
}
|
|
1072
|
-
function
|
|
1072
|
+
function Nt(t) {
|
|
1073
1073
|
if (typeof t != "function") throw new TypeError(l.BATCH_CALLBACK_MUST_BE_FUNCTION);
|
|
1074
1074
|
y.startBatch();
|
|
1075
1075
|
try {
|
|
@@ -1080,7 +1080,7 @@ function At(t) {
|
|
|
1080
1080
|
}
|
|
1081
1081
|
export {
|
|
1082
1082
|
b as AsyncState,
|
|
1083
|
-
|
|
1083
|
+
A as AtomError,
|
|
1084
1084
|
S as ComputedError,
|
|
1085
1085
|
st as DEBUG_CONFIG,
|
|
1086
1086
|
X as DEBUG_RUNTIME,
|
|
@@ -1088,9 +1088,9 @@ export {
|
|
|
1088
1088
|
m as SCHEDULER_CONFIG,
|
|
1089
1089
|
R as SchedulerError,
|
|
1090
1090
|
Dt as atom,
|
|
1091
|
-
|
|
1091
|
+
Nt as batch,
|
|
1092
1092
|
Tt as computed,
|
|
1093
|
-
|
|
1093
|
+
At as effect,
|
|
1094
1094
|
St as isAtom,
|
|
1095
1095
|
gt as isComputed,
|
|
1096
1096
|
mt as isEffect,
|