@but212/atom-effect 0.30.0 → 0.30.1
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 +89 -84
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -12,7 +12,7 @@ var u = {
|
|
|
12
12
|
ATOM_SYNC: 16777216,
|
|
13
13
|
ATOM_NOTIFICATION_SCHEDULED: 33554432,
|
|
14
14
|
EFFECT_EXECUTING: 268435456
|
|
15
|
-
},
|
|
15
|
+
}, At = Object.freeze({
|
|
16
16
|
ASYNC_STATE: u.IDLE | u.PENDING | u.RESOLVED | u.REJECTED,
|
|
17
17
|
COMPUTED_DIRTY_MASK: u.DIRTY | u.RECOMPUTING | u.FORCE_COMPUTE
|
|
18
18
|
}), U = Object.freeze({
|
|
@@ -49,7 +49,7 @@ var u = {
|
|
|
49
49
|
WARN_INFINITE_LOOP: !0,
|
|
50
50
|
EFFECT_FREQUENCY_WINDOW: 1e3,
|
|
51
51
|
LOOP_THRESHOLD: 100
|
|
52
|
-
}),
|
|
52
|
+
}), ft = Object.freeze({ MAX_PROMISE_ID: k }), w = Object.freeze({
|
|
53
53
|
UNINITIALIZED: -1,
|
|
54
54
|
MIN: 1
|
|
55
55
|
}), ot = !1;
|
|
@@ -132,7 +132,7 @@ var _ = (typeof process < "u" && process.env, typeof __DEV__ < "u" && !!__DEV__
|
|
|
132
132
|
SCHEDULER_END_BATCH_WITHOUT_START: "endBatch() called without matching startBatch(). Ignoring.",
|
|
133
133
|
BATCH_CALLBACK_MUST_BE_FUNCTION: "Batch callback must be a function"
|
|
134
134
|
};
|
|
135
|
-
function
|
|
135
|
+
function N(t, e, s) {
|
|
136
136
|
if (t instanceof g) return new e(g.format(t.name, s, t.message), t, t.recoverable, t.code);
|
|
137
137
|
if (t instanceof Error) {
|
|
138
138
|
const i = t.name || t.constructor.name || "Error";
|
|
@@ -140,10 +140,10 @@ function O(t, e, s) {
|
|
|
140
140
|
}
|
|
141
141
|
return new e(g.format("Unexpected error", s, String(t)), t);
|
|
142
142
|
}
|
|
143
|
-
var st = /* @__PURE__ */ Symbol("AtomEffect.DebugName"),
|
|
143
|
+
var st = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), Et = /* @__PURE__ */ Symbol("AtomEffect.Id"), it = /* @__PURE__ */ Symbol("AtomEffect.Type"), B = /* @__PURE__ */ Symbol("AtomEffect.NoDefaultValue"), dt = "[Atom Effect]", pt = class {
|
|
144
144
|
constructor() {
|
|
145
145
|
this.enabled = !0, this.warnInfiniteLoop = Y.WARN_INFINITE_LOOP, this._updateCounts = /* @__PURE__ */ new Map(), this._nodeRegistry = /* @__PURE__ */ new Map(), this._threshold = Y.LOOP_THRESHOLD, this._cleanupScheduled = !1, this.warn = (t, e) => {
|
|
146
|
-
this.enabled && t && console.warn(`${
|
|
146
|
+
this.enabled && t && console.warn(`${dt} ${e}`);
|
|
147
147
|
}, this.registerNode = (t) => {
|
|
148
148
|
this._nodeRegistry.set(t.id, new WeakRef(t));
|
|
149
149
|
}, this.attachDebugInfo = (t, e, s, i) => {
|
|
@@ -152,7 +152,7 @@ var st = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), ft = /* @__PURE__ */ Sy
|
|
|
152
152
|
value: i ?? `${e}_${s}`,
|
|
153
153
|
configurable: !0
|
|
154
154
|
},
|
|
155
|
-
[
|
|
155
|
+
[Et]: {
|
|
156
156
|
value: s,
|
|
157
157
|
configurable: !0
|
|
158
158
|
},
|
|
@@ -187,7 +187,7 @@ var st = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), ft = /* @__PURE__ */ Sy
|
|
|
187
187
|
return t[it];
|
|
188
188
|
};
|
|
189
189
|
}
|
|
190
|
-
},
|
|
190
|
+
}, It = {
|
|
191
191
|
enabled: !1,
|
|
192
192
|
warnInfiniteLoop: !1,
|
|
193
193
|
warn: () => {
|
|
@@ -203,7 +203,7 @@ var st = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), ft = /* @__PURE__ */ Sy
|
|
|
203
203
|
},
|
|
204
204
|
getDebugType: () => {
|
|
205
205
|
}
|
|
206
|
-
}, d = _ ? new
|
|
206
|
+
}, d = _ ? new pt() : It, Ct = 1, gt = () => Ct++ | 0, ut = class {
|
|
207
207
|
constructor() {
|
|
208
208
|
this._s0 = null, this._s1 = null, this._s2 = null, this._s3 = null, this._count = 0, this._actualCount = 0, this._overflow = null, this._freeIndices = null;
|
|
209
209
|
}
|
|
@@ -404,31 +404,31 @@ var st = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), ft = /* @__PURE__ */ Sy
|
|
|
404
404
|
Computed: 4,
|
|
405
405
|
Effect: 8
|
|
406
406
|
};
|
|
407
|
-
function
|
|
407
|
+
function $(t, e) {
|
|
408
408
|
if (!t) return !1;
|
|
409
409
|
const s = typeof t;
|
|
410
410
|
return (s === "object" || s === "function") && !!((t[F] ?? 0) & e);
|
|
411
411
|
}
|
|
412
|
-
function At(t) {
|
|
413
|
-
return q(t, p.Atom);
|
|
414
|
-
}
|
|
415
412
|
function yt(t) {
|
|
416
|
-
return
|
|
413
|
+
return $(t, p.Atom);
|
|
417
414
|
}
|
|
418
415
|
function Rt(t) {
|
|
419
|
-
return
|
|
416
|
+
return $(t, p.Computed);
|
|
417
|
+
}
|
|
418
|
+
function wt(t) {
|
|
419
|
+
return $(t, p.Effect);
|
|
420
420
|
}
|
|
421
|
-
function
|
|
421
|
+
function q(t) {
|
|
422
422
|
if (t instanceof Promise) return !0;
|
|
423
423
|
if (!t) return !1;
|
|
424
424
|
const e = typeof t;
|
|
425
425
|
return (e === "object" || e === "function") && typeof t.then == "function";
|
|
426
426
|
}
|
|
427
|
-
var
|
|
427
|
+
var W = class {
|
|
428
428
|
constructor(t, e, s = void 0) {
|
|
429
429
|
this.node = t, this.version = e, this.unsub = s;
|
|
430
430
|
}
|
|
431
|
-
},
|
|
431
|
+
}, Dt = class {
|
|
432
432
|
constructor(t = void 0, e = void 0) {
|
|
433
433
|
this.fn = t, this.sub = e;
|
|
434
434
|
}
|
|
@@ -440,7 +440,7 @@ var j = class {
|
|
|
440
440
|
i !== void 0 && i.execute();
|
|
441
441
|
});
|
|
442
442
|
}
|
|
443
|
-
},
|
|
443
|
+
}, St = class {
|
|
444
444
|
constructor() {
|
|
445
445
|
this.current = null;
|
|
446
446
|
}
|
|
@@ -450,12 +450,12 @@ var j = class {
|
|
|
450
450
|
this.current = t;
|
|
451
451
|
try {
|
|
452
452
|
const i = e();
|
|
453
|
-
return _ && d.warn(
|
|
453
|
+
return _ && d.warn(q(i), 'Detected Promise returned within tracking context. Dependencies accessed after "await" will NOT be tracked. Consider using synchronous tracking before the async boundary.'), i;
|
|
454
454
|
} finally {
|
|
455
455
|
this.current = s;
|
|
456
456
|
}
|
|
457
457
|
}
|
|
458
|
-
}, l = new
|
|
458
|
+
}, l = new St();
|
|
459
459
|
function M(t) {
|
|
460
460
|
const e = l, s = e.current;
|
|
461
461
|
if (s === null) return t();
|
|
@@ -468,7 +468,7 @@ function M(t) {
|
|
|
468
468
|
}
|
|
469
469
|
var K = class {
|
|
470
470
|
constructor() {
|
|
471
|
-
this.flags = 0, this.version = 0, this._lastSeenEpoch = w.UNINITIALIZED, this._nextEpoch = void 0, this._notifying = 0, this._hotIndex = -1, this._slots = null, this._deps = null, this.id =
|
|
471
|
+
this.flags = 0, this.version = 0, this._lastSeenEpoch = w.UNINITIALIZED, this._nextEpoch = void 0, this._notifying = 0, this._hotIndex = -1, this._slots = null, this._deps = null, this.id = gt() & k;
|
|
472
472
|
}
|
|
473
473
|
get isDisposed() {
|
|
474
474
|
return (this.flags & Q.DISPOSED) !== 0;
|
|
@@ -481,7 +481,7 @@ var K = class {
|
|
|
481
481
|
}
|
|
482
482
|
subscribe(t) {
|
|
483
483
|
const e = typeof t == "function";
|
|
484
|
-
if (!e && (!t || typeof t.execute != "function")) throw
|
|
484
|
+
if (!e && (!t || typeof t.execute != "function")) throw N(/* @__PURE__ */ new TypeError("Invalid subscriber"), g, h.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
|
|
485
485
|
let s = this._slots;
|
|
486
486
|
s || (s = new ut(), this._slots = s);
|
|
487
487
|
let i = !1;
|
|
@@ -502,7 +502,7 @@ var K = class {
|
|
|
502
502
|
if (i)
|
|
503
503
|
return _ && console.warn(`[atom-effect] Duplicate subscription ignored on node ${this.id}`), () => {
|
|
504
504
|
};
|
|
505
|
-
const n = new
|
|
505
|
+
const n = new Dt(e ? t : void 0, e ? void 0 : t);
|
|
506
506
|
return s.add(n), () => this._unsubscribe(n);
|
|
507
507
|
}
|
|
508
508
|
_unsubscribe(t) {
|
|
@@ -554,7 +554,7 @@ var K = class {
|
|
|
554
554
|
}
|
|
555
555
|
}
|
|
556
556
|
_logNotifyError(t) {
|
|
557
|
-
console.error(
|
|
557
|
+
console.error(N(t, g, h.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED));
|
|
558
558
|
}
|
|
559
559
|
_isDirty() {
|
|
560
560
|
const t = this._deps;
|
|
@@ -571,12 +571,12 @@ function J() {
|
|
|
571
571
|
const t = H + 1 & k;
|
|
572
572
|
return H = t === 0 ? 1 : t, H;
|
|
573
573
|
}
|
|
574
|
-
function
|
|
574
|
+
function j(t) {
|
|
575
575
|
const e = t + 1 & k;
|
|
576
576
|
return e === 0 ? 1 : e;
|
|
577
577
|
}
|
|
578
578
|
var Z = 0, z = !1, ct = 0;
|
|
579
|
-
function
|
|
579
|
+
function Tt() {
|
|
580
580
|
return ct;
|
|
581
581
|
}
|
|
582
582
|
function nt() {
|
|
@@ -585,13 +585,13 @@ function nt() {
|
|
|
585
585
|
function rt() {
|
|
586
586
|
z = !1;
|
|
587
587
|
}
|
|
588
|
-
function
|
|
588
|
+
function mt() {
|
|
589
589
|
if (!z) return 0;
|
|
590
590
|
const t = ++Z;
|
|
591
591
|
if (t <= C.MAX_EXECUTIONS_PER_FLUSH) return t;
|
|
592
592
|
throw new Error(`[atom-effect] Infinite loop detected: flush execution count exceeded ${C.MAX_EXECUTIONS_PER_FLUSH}`);
|
|
593
593
|
}
|
|
594
|
-
var
|
|
594
|
+
var vt = class {
|
|
595
595
|
constructor() {
|
|
596
596
|
this._queueBuffer = [[], []], this._bufferIndex = 0, this._size = 0, this._epoch = 0, this._isProcessing = !1, this._isFlushingSync = !1, this._batchDepth = 0, this._batchQueue = [], this._batchQueueSize = 0, this._maxFlushIterations = C.MAX_FLUSH_ITERATIONS, this.onOverflow = null, this._boundRunLoop = this._runLoop.bind(this);
|
|
597
597
|
}
|
|
@@ -694,17 +694,17 @@ var mt = class {
|
|
|
694
694
|
if (t < C.MIN_FLUSH_ITERATIONS) throw new L(`Max iterations must be at least ${C.MIN_FLUSH_ITERATIONS}`);
|
|
695
695
|
this._maxFlushIterations = t;
|
|
696
696
|
}
|
|
697
|
-
},
|
|
698
|
-
function
|
|
697
|
+
}, b = new vt();
|
|
698
|
+
function Ft(t) {
|
|
699
699
|
if (_ && typeof t != "function") throw new TypeError(h.BATCH_CALLBACK_MUST_BE_FUNCTION);
|
|
700
|
-
|
|
700
|
+
b.startBatch();
|
|
701
701
|
try {
|
|
702
702
|
return t();
|
|
703
703
|
} finally {
|
|
704
|
-
|
|
704
|
+
b.endBatch();
|
|
705
705
|
}
|
|
706
706
|
}
|
|
707
|
-
var
|
|
707
|
+
var Ot = class extends K {
|
|
708
708
|
constructor(t, e) {
|
|
709
709
|
super(), this[F] = p.Atom | p.Writable, this._value = t, this._equal = e.equal ?? Object.is, e.sync && (this.flags |= f.SYNC), d.attachDebugInfo(this, "atom", this.id, e.name);
|
|
710
710
|
}
|
|
@@ -720,9 +720,9 @@ var vt = class extends K {
|
|
|
720
720
|
}
|
|
721
721
|
set value(t) {
|
|
722
722
|
const e = this._value;
|
|
723
|
-
if (this._equal(e, t) || (this._value = t, this.version =
|
|
723
|
+
if (this._equal(e, t) || (this._value = t, this.version = j(this.version), d.trackUpdate(this.id, d.getDebugName(this)), (this.flags & f.NOTIFICATION_SCHEDULED) !== 0)) return;
|
|
724
724
|
const s = this._slots;
|
|
725
|
-
s == null || s.size === 0 || (this._pendingOldValue = e, this.flags |= f.NOTIFICATION_SCHEDULED, (this.flags & f.SYNC) !== 0 && !
|
|
725
|
+
s == null || s.size === 0 || (this._pendingOldValue = e, this.flags |= f.NOTIFICATION_SCHEDULED, (this.flags & f.SYNC) !== 0 && !b.isBatching ? this._notifying === 0 && this._flushNotifications() : b.schedule(this));
|
|
726
726
|
}
|
|
727
727
|
execute() {
|
|
728
728
|
this._flushNotifications();
|
|
@@ -731,7 +731,7 @@ var vt = class extends K {
|
|
|
731
731
|
const t = f.NOTIFICATION_SCHEDULED, e = f.DISPOSED, s = f.SYNC;
|
|
732
732
|
for (; (this.flags & (t | e)) === t; ) {
|
|
733
733
|
const i = this._pendingOldValue;
|
|
734
|
-
if (this._pendingOldValue = void 0, this.flags &= ~t, this._equal(this._value, i) || this._notifySubscribers(this._value, i), (this.flags & s) === 0 ||
|
|
734
|
+
if (this._pendingOldValue = void 0, this.flags &= ~t, this._equal(this._value, i) || this._notifySubscribers(this._value, i), (this.flags & s) === 0 || b.isBatching) break;
|
|
735
735
|
}
|
|
736
736
|
}
|
|
737
737
|
peek() {
|
|
@@ -748,10 +748,10 @@ var vt = class extends K {
|
|
|
748
748
|
this.dispose();
|
|
749
749
|
}
|
|
750
750
|
};
|
|
751
|
-
function
|
|
752
|
-
return new
|
|
751
|
+
function Ut(t, e = {}) {
|
|
752
|
+
return new Ot(t, e);
|
|
753
753
|
}
|
|
754
|
-
var { IDLE: D, DIRTY: E, PENDING:
|
|
754
|
+
var { IDLE: D, DIRTY: E, PENDING: O, RESOLVED: I, REJECTED: T, HAS_ERROR: P, RECOMPUTING: y, DISPOSED: G, IS_COMPUTED: R, FORCE_COMPUTE: X } = Q, Nt = class extends K {
|
|
755
755
|
constructor(t, e = {}) {
|
|
756
756
|
if (typeof t != "function") throw new A(h.COMPUTED_MUST_BE_FUNCTION);
|
|
757
757
|
if (super(), this[F] = p.Atom | p.Computed, this._error = null, this._promiseId = 0, this._deps = new ht(), this._trackEpoch = w.UNINITIALIZED, this._trackCount = 0, this._value = void 0, this.flags = R | E | D, this._equal = e.equal ?? Object.is, this._fn = t, this._defaultValue = "defaultValue" in e ? e.defaultValue : B, this._onError = e.onError ?? null, d.attachDebugInfo(this, "computed", this.id, e.name), e.lazy === !1) try {
|
|
@@ -790,7 +790,7 @@ var { IDLE: D, DIRTY: E, PENDING: v, RESOLVED: I, REJECTED: T, HAS_ERROR: P, REC
|
|
|
790
790
|
if ((e & D) === 0 && (e & X) === 0 && n.size > 0 && !this._isDirty() ? e = this.flags &= ~E : (this._recompute(), e = this.flags), (e & I) !== 0) return this._value;
|
|
791
791
|
}
|
|
792
792
|
const s = this._defaultValue, i = s !== B;
|
|
793
|
-
if ((e &
|
|
793
|
+
if ((e & O) !== 0) {
|
|
794
794
|
if (i) return s;
|
|
795
795
|
throw new A(h.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
|
|
796
796
|
}
|
|
@@ -807,7 +807,7 @@ var { IDLE: D, DIRTY: E, PENDING: v, RESOLVED: I, REJECTED: T, HAS_ERROR: P, REC
|
|
|
807
807
|
const t = l.current;
|
|
808
808
|
t?.addDependency(this);
|
|
809
809
|
const e = this.flags;
|
|
810
|
-
return (e & I) !== 0 ? U.RESOLVED : (e &
|
|
810
|
+
return (e & I) !== 0 ? U.RESOLVED : (e & O) !== 0 ? U.PENDING : (e & T) !== 0 ? U.REJECTED : U.IDLE;
|
|
811
811
|
}
|
|
812
812
|
get hasError() {
|
|
813
813
|
const t = l.current;
|
|
@@ -854,7 +854,7 @@ var { IDLE: D, DIRTY: E, PENDING: v, RESOLVED: I, REJECTED: T, HAS_ERROR: P, REC
|
|
|
854
854
|
}
|
|
855
855
|
get isPending() {
|
|
856
856
|
const t = l.current;
|
|
857
|
-
return t?.addDependency(this), (this.flags &
|
|
857
|
+
return t?.addDependency(this), (this.flags & O) !== 0;
|
|
858
858
|
}
|
|
859
859
|
get isResolved() {
|
|
860
860
|
const t = l.current;
|
|
@@ -876,7 +876,7 @@ var { IDLE: D, DIRTY: E, PENDING: v, RESOLVED: I, REJECTED: T, HAS_ERROR: P, REC
|
|
|
876
876
|
const s = this._trackCount++, i = this._deps, n = i.getAt(s);
|
|
877
877
|
if (n != null && n.node === t) n.version = t.version;
|
|
878
878
|
else if (!i.claimExisting(t, s)) {
|
|
879
|
-
const r = new
|
|
879
|
+
const r = new W(t, t.version, t.subscribe(this));
|
|
880
880
|
i.insertNew(s, r);
|
|
881
881
|
}
|
|
882
882
|
(t.flags & R) !== 0 && (i.hasComputeds = !0);
|
|
@@ -887,7 +887,7 @@ var { IDLE: D, DIRTY: E, PENDING: v, RESOLVED: I, REJECTED: T, HAS_ERROR: P, REC
|
|
|
887
887
|
let t = !1;
|
|
888
888
|
try {
|
|
889
889
|
const e = l.run(this, this._fn);
|
|
890
|
-
this._deps.truncateFrom(this._trackCount), t = !0,
|
|
890
|
+
this._deps.truncateFrom(this._trackCount), t = !0, q(e) ? this._handleAsyncComputation(e) : this._finalizeResolution(e);
|
|
891
891
|
} catch (e) {
|
|
892
892
|
if (!t) try {
|
|
893
893
|
this._deps.truncateFrom(this._trackCount);
|
|
@@ -900,7 +900,7 @@ var { IDLE: D, DIRTY: E, PENDING: v, RESOLVED: I, REJECTED: T, HAS_ERROR: P, REC
|
|
|
900
900
|
}
|
|
901
901
|
}
|
|
902
902
|
_handleAsyncComputation(t) {
|
|
903
|
-
this.flags = (this.flags |
|
|
903
|
+
this.flags = (this.flags | O) & ~(D | E | I | T), this._notifySubscribers(void 0, void 0), this._promiseId = (this._promiseId + 1) % ft.MAX_PROMISE_ID;
|
|
904
904
|
const e = this._promiseId;
|
|
905
905
|
t.then((s) => {
|
|
906
906
|
if (e === this._promiseId) {
|
|
@@ -910,8 +910,8 @@ var { IDLE: D, DIRTY: E, PENDING: v, RESOLVED: I, REJECTED: T, HAS_ERROR: P, REC
|
|
|
910
910
|
}, (s) => e === this._promiseId && this._handleError(s, h.COMPUTED_ASYNC_COMPUTATION_FAILED));
|
|
911
911
|
}
|
|
912
912
|
_handleError(t, e, s = !1) {
|
|
913
|
-
const i =
|
|
914
|
-
if ((!this.isRejected || this._error !== i) && (this.version =
|
|
913
|
+
const i = N(t, A, e);
|
|
914
|
+
if ((!this.isRejected || this._error !== i) && (this.version = j(this.version)), this._error = i, this.flags = this.flags & ~(D | E | O | I) | T | P, this._onError) try {
|
|
915
915
|
this._onError(i);
|
|
916
916
|
} catch (n) {
|
|
917
917
|
console.error(h.CALLBACK_ERROR_IN_ERROR_HANDLER, n);
|
|
@@ -920,7 +920,7 @@ var { IDLE: D, DIRTY: E, PENDING: v, RESOLVED: I, REJECTED: T, HAS_ERROR: P, REC
|
|
|
920
920
|
}
|
|
921
921
|
_finalizeResolution(t) {
|
|
922
922
|
const e = this.flags;
|
|
923
|
-
((e & I) === 0 || !this._equal(this._value, t)) && (this.version =
|
|
923
|
+
((e & I) === 0 || !this._equal(this._value, t)) && (this.version = j(this.version)), this._value = t, this._error = null, this.flags = (e | I) & ~(D | E | O | T | P);
|
|
924
924
|
}
|
|
925
925
|
execute() {
|
|
926
926
|
this._markDirty();
|
|
@@ -949,12 +949,12 @@ var { IDLE: D, DIRTY: E, PENDING: v, RESOLVED: I, REJECTED: T, HAS_ERROR: P, REC
|
|
|
949
949
|
});
|
|
950
950
|
}
|
|
951
951
|
};
|
|
952
|
-
function
|
|
953
|
-
return new
|
|
952
|
+
function Lt(t, e = {}) {
|
|
953
|
+
return new Nt(t, e);
|
|
954
954
|
}
|
|
955
|
-
var
|
|
955
|
+
var bt = class extends K {
|
|
956
956
|
constructor(t, e = {}) {
|
|
957
|
-
super(), this[F] = p.Effect, this._cleanup = null, this._deps = new ht(), this._currentEpoch = w.UNINITIALIZED, this._lastFlushEpoch = w.UNINITIALIZED, this._fn = t, this._onError = e.onError ?? null, this._sync = e.sync ?? !1, this._maxExecutions = e.maxExecutionsPerSecond ?? C.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = e.maxExecutionsPerFlush ?? C.MAX_EXECUTIONS_PER_EFFECT, this._executionsInEpoch = 0, this._executionCount = 0, this._windowStart = 0, this._windowCount = 0, this._execId = 0, this._trackCount = 0, this._sync ? this._notifyCallback = () => this.execute() : this._notifyCallback = () =>
|
|
957
|
+
super(), this[F] = p.Effect, this._cleanup = null, this._deps = new ht(), this._currentEpoch = w.UNINITIALIZED, this._lastFlushEpoch = w.UNINITIALIZED, this._fn = t, this._onError = e.onError ?? null, this._sync = e.sync ?? !1, this._maxExecutions = e.maxExecutionsPerSecond ?? C.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = e.maxExecutionsPerFlush ?? C.MAX_EXECUTIONS_PER_EFFECT, this._executionsInEpoch = 0, this._executionCount = 0, this._windowStart = 0, this._windowCount = 0, this._execId = 0, this._trackCount = 0, this._sync ? this._notifyCallback = () => this.execute() : this._notifyCallback = () => b.schedule(this), d.attachDebugInfo(this, "effect", this.id, e.name);
|
|
958
958
|
}
|
|
959
959
|
run() {
|
|
960
960
|
if (this.isDisposed) throw new m(h.EFFECT_DISPOSED);
|
|
@@ -995,14 +995,14 @@ var Nt = class extends K {
|
|
|
995
995
|
let s;
|
|
996
996
|
try {
|
|
997
997
|
const i = t.subscribe(this._notifyCallback);
|
|
998
|
-
s = new
|
|
998
|
+
s = new W(t, t.version, i);
|
|
999
999
|
} catch (i) {
|
|
1000
|
-
const n =
|
|
1000
|
+
const n = N(i, m, h.EFFECT_EXECUTION_FAILED);
|
|
1001
1001
|
if (console.error(n), this._onError) try {
|
|
1002
1002
|
this._onError(n);
|
|
1003
1003
|
} catch {
|
|
1004
1004
|
}
|
|
1005
|
-
s = new
|
|
1005
|
+
s = new W(t, t.version, void 0);
|
|
1006
1006
|
}
|
|
1007
1007
|
this._deps.insertNew(e, s);
|
|
1008
1008
|
}
|
|
@@ -1015,7 +1015,7 @@ var Nt = class extends K {
|
|
|
1015
1015
|
let i = !1;
|
|
1016
1016
|
try {
|
|
1017
1017
|
const n = l.run(this, this._fn);
|
|
1018
|
-
s.truncateFrom(this._trackCount), i = !0,
|
|
1018
|
+
s.truncateFrom(this._trackCount), i = !0, q(n) ? this._handleAsyncResult(n) : this._cleanup = typeof n == "function" ? n : null;
|
|
1019
1019
|
} catch (n) {
|
|
1020
1020
|
if (!i) try {
|
|
1021
1021
|
s.truncateFrom(this._trackCount);
|
|
@@ -1078,8 +1078,8 @@ var Nt = class extends K {
|
|
|
1078
1078
|
}
|
|
1079
1079
|
}
|
|
1080
1080
|
_checkInfiniteLoops() {
|
|
1081
|
-
const t =
|
|
1082
|
-
this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"),
|
|
1081
|
+
const t = Tt();
|
|
1082
|
+
this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), mt() > C.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++, _ && this._checkFrequencyLimit();
|
|
1083
1083
|
}
|
|
1084
1084
|
_checkFrequencyLimit() {
|
|
1085
1085
|
if (!Number.isFinite(this._maxExecutions)) return;
|
|
@@ -1104,26 +1104,29 @@ var Nt = class extends K {
|
|
|
1104
1104
|
throw this.dispose(), console.error(e), e;
|
|
1105
1105
|
}
|
|
1106
1106
|
_handleExecutionError(t, e = h.EFFECT_EXECUTION_FAILED) {
|
|
1107
|
-
const s =
|
|
1107
|
+
const s = N(t, m, e);
|
|
1108
1108
|
if (console.error(s), this._onError) try {
|
|
1109
1109
|
this._onError(s);
|
|
1110
1110
|
} catch (i) {
|
|
1111
|
-
console.error(
|
|
1111
|
+
console.error(N(i, m, h.CALLBACK_ERROR_IN_ERROR_HANDLER));
|
|
1112
1112
|
}
|
|
1113
1113
|
}
|
|
1114
1114
|
};
|
|
1115
|
-
function
|
|
1115
|
+
function Pt(t, e = {}) {
|
|
1116
1116
|
if (typeof t != "function") throw new m(h.EFFECT_MUST_BE_FUNCTION);
|
|
1117
|
-
const s = new
|
|
1117
|
+
const s = new bt(t, e);
|
|
1118
1118
|
return s.execute(), s;
|
|
1119
1119
|
}
|
|
1120
|
-
|
|
1120
|
+
var lt = /^(?:__proto__|constructor|prototype)$/;
|
|
1121
|
+
function _t(t, e, s, i) {
|
|
1121
1122
|
if (s === e.length) return i;
|
|
1122
|
-
const n = e[s]
|
|
1123
|
+
const n = e[s];
|
|
1124
|
+
if (lt.test(n)) return t;
|
|
1125
|
+
const r = t != null && typeof t == "object" ? t : {}, o = r[n], c = _t(o, e, s + 1, i);
|
|
1123
1126
|
if (Object.is(o, c)) return t;
|
|
1124
1127
|
if (Array.isArray(r)) {
|
|
1125
|
-
const a = r.slice(),
|
|
1126
|
-
return Number.
|
|
1128
|
+
const a = r.slice(), v = Number(n);
|
|
1129
|
+
return n.trim() !== "" && Number.isInteger(v) && v >= 0 ? a[v] = c : a[n] = c, a;
|
|
1127
1130
|
}
|
|
1128
1131
|
return {
|
|
1129
1132
|
...r,
|
|
@@ -1135,11 +1138,13 @@ function x(t, e) {
|
|
|
1135
1138
|
const i = e.length;
|
|
1136
1139
|
for (let n = 0; n < i; n++) {
|
|
1137
1140
|
if (s == null) return;
|
|
1138
|
-
|
|
1141
|
+
const r = e[n];
|
|
1142
|
+
if (lt.test(r)) return;
|
|
1143
|
+
s = s[r];
|
|
1139
1144
|
}
|
|
1140
1145
|
return s;
|
|
1141
1146
|
}
|
|
1142
|
-
function
|
|
1147
|
+
function at(t, e) {
|
|
1143
1148
|
const s = e.includes(".") ? e.split(".") : [e], i = /* @__PURE__ */ new Set(), n = () => {
|
|
1144
1149
|
i.forEach((r) => r()), i.clear();
|
|
1145
1150
|
};
|
|
@@ -1148,14 +1153,14 @@ function _t(t, e) {
|
|
|
1148
1153
|
return x(t.value, s);
|
|
1149
1154
|
},
|
|
1150
1155
|
set value(r) {
|
|
1151
|
-
const o = t.peek(), c =
|
|
1156
|
+
const o = t.peek(), c = _t(o, s, 0, r);
|
|
1152
1157
|
c !== o && (t.value = c);
|
|
1153
1158
|
},
|
|
1154
1159
|
peek: () => x(t.peek(), s),
|
|
1155
1160
|
subscribe(r) {
|
|
1156
1161
|
const o = t.subscribe((c, a) => {
|
|
1157
|
-
const
|
|
1158
|
-
Object.is(
|
|
1162
|
+
const v = x(c, s), tt = x(a, s);
|
|
1163
|
+
Object.is(v, tt) || r(v, tt);
|
|
1159
1164
|
});
|
|
1160
1165
|
return i.add(o), () => {
|
|
1161
1166
|
o(), i.delete(o);
|
|
@@ -1167,7 +1172,7 @@ function _t(t, e) {
|
|
|
1167
1172
|
[F]: p.Atom | p.Writable
|
|
1168
1173
|
};
|
|
1169
1174
|
}
|
|
1170
|
-
var
|
|
1175
|
+
var xt = (t, e) => at(t, e), Mt = (t) => (e) => at(t, e);
|
|
1171
1176
|
export {
|
|
1172
1177
|
U as AsyncState,
|
|
1173
1178
|
g as AtomError,
|
|
@@ -1176,20 +1181,20 @@ export {
|
|
|
1176
1181
|
m as EffectError,
|
|
1177
1182
|
C as SCHEDULER_CONFIG,
|
|
1178
1183
|
L as SchedulerError,
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1184
|
+
Ut as atom,
|
|
1185
|
+
at as atomLens,
|
|
1186
|
+
Ft as batch,
|
|
1187
|
+
xt as composeLens,
|
|
1188
|
+
Lt as computed,
|
|
1189
|
+
Pt as effect,
|
|
1185
1190
|
x as getPathValue,
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
+
b as globalScheduler,
|
|
1192
|
+
yt as isAtom,
|
|
1193
|
+
Rt as isComputed,
|
|
1194
|
+
wt as isEffect,
|
|
1195
|
+
Mt as lensFor,
|
|
1191
1196
|
d as runtimeDebug,
|
|
1192
|
-
|
|
1197
|
+
_t as setDeepValue,
|
|
1193
1198
|
M as untracked
|
|
1194
1199
|
};
|
|
1195
1200
|
|