@but212/atom-effect 0.22.2 → 0.23.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.d.ts +20 -29
- package/dist/index.mjs +429 -340
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
const
|
|
1
|
+
const N = {
|
|
2
2
|
IDLE: "idle",
|
|
3
3
|
PENDING: "pending",
|
|
4
4
|
RESOLVED: "resolved",
|
|
5
5
|
REJECTED: "rejected"
|
|
6
|
-
},
|
|
6
|
+
}, _ = {
|
|
7
7
|
DISPOSED: 1,
|
|
8
8
|
EXECUTING: 8
|
|
9
|
-
},
|
|
9
|
+
}, W = {
|
|
10
10
|
DISPOSED: 1,
|
|
11
11
|
/** Marker bit: identifies this node as a computed. */
|
|
12
12
|
IS_COMPUTED: 2,
|
|
@@ -21,10 +21,6 @@ const b = {
|
|
|
21
21
|
DISPOSED: 1,
|
|
22
22
|
SYNC: 8,
|
|
23
23
|
NOTIFICATION_SCHEDULED: 16
|
|
24
|
-
}, Dt = {
|
|
25
|
-
MAX_SIZE: 1e3,
|
|
26
|
-
WARMUP_SIZE: 100,
|
|
27
|
-
ENABLE_STATS: !1
|
|
28
24
|
}, d = {
|
|
29
25
|
// Infinite loop protection
|
|
30
26
|
MAX_EXECUTIONS_PER_SECOND: 1e3,
|
|
@@ -35,85 +31,65 @@ const b = {
|
|
|
35
31
|
MIN_FLUSH_ITERATIONS: 10,
|
|
36
32
|
// Memory management
|
|
37
33
|
BATCH_QUEUE_SHRINK_THRESHOLD: 1e3
|
|
38
|
-
},
|
|
34
|
+
}, ht = {
|
|
39
35
|
WARN_INFINITE_LOOP: !0,
|
|
40
36
|
EFFECT_FREQUENCY_WINDOW: 1e3
|
|
41
|
-
},
|
|
37
|
+
}, V = {
|
|
42
38
|
MAX_ASYNC_RETRIES: 3,
|
|
43
39
|
MAX_PROMISE_ID: Number.MAX_SAFE_INTEGER - 1
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
}, g = {
|
|
41
|
+
/** Uninitialized epoch marker. Used as initial value before any flush has occurred. */
|
|
42
|
+
UNINITIALIZED: -1
|
|
43
|
+
}, F = 1073741823, Z = typeof process < "u" && process.env && !1 || !1, ot = Object.freeze([]);
|
|
44
|
+
function X(n, t, s) {
|
|
45
|
+
const e = /* @__PURE__ */ new Map();
|
|
46
|
+
for (let i = 0; i < t.length; i++) {
|
|
47
|
+
const r = t[i];
|
|
48
|
+
r?.unsub && e.set(r.node, r.unsub);
|
|
49
|
+
}
|
|
50
|
+
for (let i = 0; i < n.length; i++) {
|
|
51
|
+
const r = n[i];
|
|
52
|
+
if (!r) continue;
|
|
53
|
+
const h = r.node, o = e.get(h);
|
|
54
|
+
o !== void 0 ? (r.unsub = o, e.delete(h)) : r.unsub || (r.unsub = h.subscribe(s));
|
|
55
|
+
}
|
|
56
|
+
for (const i of e.values())
|
|
57
|
+
i();
|
|
49
58
|
}
|
|
50
|
-
class
|
|
51
|
-
constructor(t, e =
|
|
52
|
-
|
|
59
|
+
class y {
|
|
60
|
+
constructor(t, s, e = void 0) {
|
|
61
|
+
this.node = t, this.version = s, this.unsub = e;
|
|
53
62
|
}
|
|
54
63
|
}
|
|
55
|
-
class
|
|
56
|
-
constructor(t,
|
|
57
|
-
|
|
64
|
+
class ct {
|
|
65
|
+
constructor(t, s) {
|
|
66
|
+
this.fn = t, this.sub = s;
|
|
58
67
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
constructor(t, e = null) {
|
|
62
|
-
super(t, e, !1), this.name = "SchedulerError";
|
|
68
|
+
notify(t, s) {
|
|
69
|
+
this.fn ? this.fn(t, s) : this.sub && this.sub.execute();
|
|
63
70
|
}
|
|
64
71
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
warn(i, t) {
|
|
70
|
-
},
|
|
71
|
-
checkCircular(i, t) {
|
|
72
|
-
if (i === t)
|
|
73
|
-
throw new f("Direct circular dependency detected");
|
|
74
|
-
},
|
|
75
|
-
attachDebugInfo(i, t, e) {
|
|
76
|
-
},
|
|
77
|
-
getDebugName: (i) => i?.[ht],
|
|
78
|
-
getDebugType: (i) => i?.[ct]
|
|
79
|
-
};
|
|
80
|
-
let ut = 1;
|
|
81
|
-
const _t = () => ut++;
|
|
82
|
-
function K(i, t, e) {
|
|
83
|
-
if (typeof t == "function") {
|
|
84
|
-
const n = t;
|
|
85
|
-
if (e.some((r) => r && r.fn === n)) return;
|
|
86
|
-
e.push(new P(n, void 0));
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
if ("addDependency" in t) {
|
|
90
|
-
t.addDependency(i);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
const s = t;
|
|
94
|
-
e.some((n) => n && n.sub === s) || e.push(new P(void 0, s));
|
|
72
|
+
class k extends Error {
|
|
73
|
+
constructor(t, s = null, e = !0) {
|
|
74
|
+
super(t), this.cause = s, this.recoverable = e, this.name = "AtomError";
|
|
75
|
+
}
|
|
95
76
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}), i.forEach((n) => {
|
|
101
|
-
if (!n) return;
|
|
102
|
-
const r = n.node, o = s.get(r);
|
|
103
|
-
o !== void 0 ? (n.unsub = o, s.delete(r)) : (F.checkCircular(r, e), n.unsub = r.subscribe(e));
|
|
104
|
-
}), s.forEach((n) => n());
|
|
77
|
+
class I extends k {
|
|
78
|
+
constructor(t, s = null) {
|
|
79
|
+
super(t, s, !0), this.name = "ComputedError";
|
|
80
|
+
}
|
|
105
81
|
}
|
|
106
|
-
class
|
|
107
|
-
constructor(t,
|
|
108
|
-
|
|
82
|
+
class C extends k {
|
|
83
|
+
constructor(t, s = null) {
|
|
84
|
+
super(t, s, !1), this.name = "EffectError";
|
|
109
85
|
}
|
|
110
86
|
}
|
|
111
|
-
class
|
|
112
|
-
constructor(t,
|
|
113
|
-
|
|
87
|
+
class m extends k {
|
|
88
|
+
constructor(t, s = null) {
|
|
89
|
+
super(t, s, !1), this.name = "SchedulerError";
|
|
114
90
|
}
|
|
115
91
|
}
|
|
116
|
-
const
|
|
92
|
+
const c = {
|
|
117
93
|
// Computed Errors
|
|
118
94
|
COMPUTED_MUST_BE_FUNCTION: "Computed target must be a function",
|
|
119
95
|
COMPUTED_ASYNC_PENDING_NO_DEFAULT: "Async computation pending with no default value",
|
|
@@ -130,81 +106,138 @@ const h = {
|
|
|
130
106
|
EFFECT_CLEANUP_FAILED: "Effect cleanup failed",
|
|
131
107
|
EFFECT_DISPOSED: "Attempted to run disposed effect",
|
|
132
108
|
// Scheduler Errors
|
|
133
|
-
SCHEDULER_FLUSH_OVERFLOW: (
|
|
109
|
+
SCHEDULER_FLUSH_OVERFLOW: (n, t) => `Maximum flush iterations (${n}) exceeded. ${t} jobs dropped. Possible infinite loop.`,
|
|
134
110
|
// System / Debug
|
|
135
111
|
CALLBACK_ERROR_IN_ERROR_HANDLER: "Exception encountered in onError handler",
|
|
136
112
|
// Effect frequency
|
|
137
113
|
EFFECT_FREQUENCY_LIMIT_EXCEEDED: "Effect executed too frequently within 1 second. Suspected infinite loop.",
|
|
138
114
|
SCHEDULER_CALLBACK_MUST_BE_FUNCTION: "Scheduler callback must be a function",
|
|
139
|
-
SCHEDULER_END_BATCH_WITHOUT_START: "endBatch() called without matching startBatch(). Ignoring."
|
|
115
|
+
SCHEDULER_END_BATCH_WITHOUT_START: "endBatch() called without matching startBatch(). Ignoring.",
|
|
116
|
+
BATCH_CALLBACK_MUST_BE_FUNCTION: "Batch callback must be a function"
|
|
117
|
+
}, ut = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), _t = /* @__PURE__ */ Symbol("AtomEffect.Type"), x = /* @__PURE__ */ Symbol("AtomEffect.NoDefaultValue"), B = {
|
|
118
|
+
// Dev mode flag
|
|
119
|
+
enabled: Z,
|
|
120
|
+
warnInfiniteLoop: ht.WARN_INFINITE_LOOP,
|
|
121
|
+
warn(n, t) {
|
|
122
|
+
},
|
|
123
|
+
attachDebugInfo(n, t, s) {
|
|
124
|
+
},
|
|
125
|
+
getDebugName: (n) => n?.[ut],
|
|
126
|
+
getDebugType: (n) => n?.[_t]
|
|
140
127
|
};
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
128
|
+
let lt = 1;
|
|
129
|
+
const at = () => lt++;
|
|
130
|
+
function S(n, t, s) {
|
|
131
|
+
if (n instanceof k)
|
|
132
|
+
return n;
|
|
133
|
+
const e = n instanceof Error, i = e ? n.message : String(n), r = e ? n : void 0, o = `${e ? n.constructor.name : "Unexpected error"} (${s}): ${i}`;
|
|
134
|
+
return new t(o, r);
|
|
146
135
|
}
|
|
147
136
|
class J {
|
|
148
137
|
constructor() {
|
|
149
|
-
this.flags = 0, this.version = 0, this._lastSeenEpoch =
|
|
138
|
+
this.flags = 0, this.version = 0, this._lastSeenEpoch = g.UNINITIALIZED, this.id = at() & F;
|
|
150
139
|
}
|
|
151
140
|
}
|
|
152
|
-
class
|
|
141
|
+
class tt extends J {
|
|
142
|
+
constructor() {
|
|
143
|
+
super(...arguments), this._notifying = 0;
|
|
144
|
+
}
|
|
153
145
|
/**
|
|
154
146
|
* Adds subscriber.
|
|
155
147
|
*/
|
|
156
148
|
subscribe(t) {
|
|
157
|
-
const
|
|
158
|
-
if (!
|
|
149
|
+
const s = typeof t == "function";
|
|
150
|
+
if (!s && (!t || typeof t.execute != "function"))
|
|
159
151
|
throw S(
|
|
160
152
|
new TypeError("Invalid subscriber"),
|
|
161
|
-
|
|
162
|
-
|
|
153
|
+
k,
|
|
154
|
+
c.ATOM_SUBSCRIBER_MUST_BE_FUNCTION
|
|
163
155
|
);
|
|
164
|
-
|
|
156
|
+
const e = this._subscribers, i = e.length;
|
|
157
|
+
let r = !1;
|
|
158
|
+
for (let o = 0; o < i; o++) {
|
|
159
|
+
const U = e[o];
|
|
160
|
+
if (U != null && (s ? U.fn === t : U.sub === t)) {
|
|
161
|
+
r = !0;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (r)
|
|
165
166
|
return () => {
|
|
166
167
|
};
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
const h = new ct(
|
|
169
|
+
s ? t : void 0,
|
|
170
|
+
s ? void 0 : t
|
|
170
171
|
);
|
|
171
|
-
return
|
|
172
|
+
return e.push(h), () => this._unsubscribe(h);
|
|
172
173
|
}
|
|
173
174
|
_unsubscribe(t) {
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
const s = this._subscribers;
|
|
176
|
+
let e = -1;
|
|
177
|
+
for (let r = 0; r < s.length; r++)
|
|
178
|
+
if (s[r] === t) {
|
|
179
|
+
e = r;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
if (e === -1) return;
|
|
183
|
+
if (this._notifying > 0) {
|
|
184
|
+
s[e] = null;
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const i = s.pop();
|
|
188
|
+
e < s.length && i !== void 0 && (s[e] = i);
|
|
178
189
|
}
|
|
179
190
|
subscriberCount() {
|
|
180
|
-
|
|
191
|
+
let t = 0;
|
|
192
|
+
const s = this._subscribers;
|
|
193
|
+
for (let e = 0; e < s.length; e++)
|
|
194
|
+
s[e] != null && t++;
|
|
195
|
+
return t;
|
|
181
196
|
}
|
|
182
|
-
_notifySubscribers(t,
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
197
|
+
_notifySubscribers(t, s) {
|
|
198
|
+
const e = this._subscribers, i = e.length;
|
|
199
|
+
if (i !== 0) {
|
|
200
|
+
this._notifying++;
|
|
201
|
+
try {
|
|
202
|
+
for (let r = 0; r < i; r++) {
|
|
203
|
+
const h = e[r];
|
|
204
|
+
if (h != null)
|
|
205
|
+
try {
|
|
206
|
+
h.notify(t, s);
|
|
207
|
+
} catch (o) {
|
|
208
|
+
this._handleNotifyError(o);
|
|
209
|
+
}
|
|
190
210
|
}
|
|
191
|
-
|
|
211
|
+
} finally {
|
|
212
|
+
this._notifying--, this._notifying === 0 && this._cleanupTombstones();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
_cleanupTombstones() {
|
|
217
|
+
const t = this._subscribers;
|
|
218
|
+
let s = 0;
|
|
219
|
+
for (; s < t.length; )
|
|
220
|
+
if (t[s] === null) {
|
|
221
|
+
const e = t.pop();
|
|
222
|
+
s < t.length && e !== void 0 && (t[s] = e);
|
|
223
|
+
} else
|
|
224
|
+
s++;
|
|
192
225
|
}
|
|
193
226
|
_handleNotifyError(t) {
|
|
194
|
-
console.error(S(t,
|
|
227
|
+
console.error(S(t, k, c.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED));
|
|
195
228
|
}
|
|
196
229
|
}
|
|
197
|
-
let
|
|
198
|
-
const w = () => (
|
|
199
|
-
let
|
|
200
|
-
const et = () =>
|
|
201
|
-
function
|
|
202
|
-
return R ? !1 : (R = !0,
|
|
230
|
+
let v = 0;
|
|
231
|
+
const w = () => (v = v + 1 & F || 1, v), M = (n) => n + 1 & F;
|
|
232
|
+
let z = 0, R = !1, st = 0;
|
|
233
|
+
const et = () => st;
|
|
234
|
+
function G() {
|
|
235
|
+
return R ? !1 : (R = !0, st = w(), z = 0, !0);
|
|
203
236
|
}
|
|
204
|
-
const
|
|
237
|
+
const Q = () => {
|
|
205
238
|
R = !1;
|
|
206
|
-
},
|
|
207
|
-
class
|
|
239
|
+
}, ft = () => R ? ++z : 0;
|
|
240
|
+
class Et {
|
|
208
241
|
constructor() {
|
|
209
242
|
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);
|
|
210
243
|
}
|
|
@@ -241,28 +274,28 @@ class lt {
|
|
|
241
274
|
_runLoop() {
|
|
242
275
|
try {
|
|
243
276
|
if (this._size === 0) return;
|
|
244
|
-
const t =
|
|
245
|
-
this._drainQueue(), t &&
|
|
277
|
+
const t = G();
|
|
278
|
+
this._drainQueue(), t && Q();
|
|
246
279
|
} finally {
|
|
247
280
|
this._isProcessing = !1, this._size > 0 && !this._isBatching && this._flush();
|
|
248
281
|
}
|
|
249
282
|
}
|
|
250
283
|
_flushSync() {
|
|
251
284
|
this._isFlushingSync = !0;
|
|
252
|
-
const t =
|
|
285
|
+
const t = G();
|
|
253
286
|
try {
|
|
254
287
|
this._mergeBatchQueue(), this._drainQueue();
|
|
255
288
|
} finally {
|
|
256
|
-
this._isFlushingSync = !1, t &&
|
|
289
|
+
this._isFlushingSync = !1, t && Q();
|
|
257
290
|
}
|
|
258
291
|
}
|
|
259
292
|
_mergeBatchQueue() {
|
|
260
293
|
if (this._batchQueueSize === 0) return;
|
|
261
|
-
const t = ++this._epoch,
|
|
262
|
-
let
|
|
263
|
-
|
|
264
|
-
r._nextEpoch !== t && (r._nextEpoch = t,
|
|
265
|
-
}), this._size =
|
|
294
|
+
const t = ++this._epoch, s = this._batchQueue, e = this._queueBuffer[this._bufferIndex];
|
|
295
|
+
let i = this._size;
|
|
296
|
+
s.slice(0, this._batchQueueSize).forEach((r) => {
|
|
297
|
+
r._nextEpoch !== t && (r._nextEpoch = t, e[i++] = r);
|
|
298
|
+
}), this._size = i, this._batchQueueSize = 0, s.length > d.BATCH_QUEUE_SHRINK_THRESHOLD && (s.length = 0);
|
|
266
299
|
}
|
|
267
300
|
_drainQueue() {
|
|
268
301
|
let t = 0;
|
|
@@ -275,21 +308,22 @@ class lt {
|
|
|
275
308
|
}
|
|
276
309
|
}
|
|
277
310
|
_processQueue() {
|
|
278
|
-
const t = this._bufferIndex,
|
|
311
|
+
const t = this._bufferIndex, s = this._queueBuffer[t], e = this._size;
|
|
279
312
|
this._bufferIndex = t ^ 1, this._size = 0, this._epoch++;
|
|
280
|
-
for (let
|
|
313
|
+
for (let i = 0; i < e; i++)
|
|
281
314
|
try {
|
|
282
|
-
|
|
315
|
+
const r = s[i];
|
|
316
|
+
typeof r == "function" ? r() : r.execute();
|
|
283
317
|
} catch (r) {
|
|
284
318
|
console.error(new m("Error occurred during scheduler execution", r));
|
|
285
319
|
}
|
|
286
|
-
|
|
320
|
+
s.length = 0;
|
|
287
321
|
}
|
|
288
322
|
_handleFlushOverflow() {
|
|
289
323
|
const t = this._size + this._batchQueueSize;
|
|
290
324
|
if (console.error(
|
|
291
325
|
new m(
|
|
292
|
-
|
|
326
|
+
c.SCHEDULER_FLUSH_OVERFLOW(this._maxFlushIterations, t)
|
|
293
327
|
)
|
|
294
328
|
), this._size = 0, this._queueBuffer[this._bufferIndex].length = 0, this._batchQueueSize = 0, this.onOverflow)
|
|
295
329
|
try {
|
|
@@ -311,7 +345,7 @@ class lt {
|
|
|
311
345
|
this._maxFlushIterations = t;
|
|
312
346
|
}
|
|
313
347
|
}
|
|
314
|
-
const T = new
|
|
348
|
+
const T = new Et(), H = /* @__PURE__ */ Symbol.for("atom-effect/atom"), it = /* @__PURE__ */ Symbol.for("atom-effect/computed"), nt = /* @__PURE__ */ Symbol.for("atom-effect/effect"), dt = /* @__PURE__ */ Symbol.for("atom-effect/writable"), l = {
|
|
315
349
|
/** Active listener. */
|
|
316
350
|
current: null,
|
|
317
351
|
/**
|
|
@@ -321,48 +355,54 @@ const T = new lt(), z = /* @__PURE__ */ Symbol.for("atom-effect/atom"), st = /*
|
|
|
321
355
|
* @param fn - The logic to execute.
|
|
322
356
|
* @returns The result of `fn`.
|
|
323
357
|
*/
|
|
324
|
-
run(
|
|
325
|
-
const
|
|
326
|
-
this.current =
|
|
358
|
+
run(n, t) {
|
|
359
|
+
const s = this.current;
|
|
360
|
+
this.current = n;
|
|
327
361
|
try {
|
|
328
362
|
return t();
|
|
329
363
|
} finally {
|
|
330
|
-
this.current =
|
|
364
|
+
this.current = s;
|
|
331
365
|
}
|
|
332
366
|
}
|
|
333
367
|
};
|
|
334
|
-
function
|
|
335
|
-
const t =
|
|
336
|
-
if (t === null) return
|
|
337
|
-
|
|
368
|
+
function Dt(n) {
|
|
369
|
+
const t = l.current;
|
|
370
|
+
if (t === null) return n();
|
|
371
|
+
l.current = null;
|
|
338
372
|
try {
|
|
339
|
-
return
|
|
373
|
+
return n();
|
|
340
374
|
} finally {
|
|
341
|
-
|
|
375
|
+
l.current = t;
|
|
342
376
|
}
|
|
343
377
|
}
|
|
344
|
-
var
|
|
345
|
-
class
|
|
346
|
-
constructor(t,
|
|
347
|
-
super(), this._pendingOldValue = void 0, this.
|
|
378
|
+
var Y, q;
|
|
379
|
+
class It extends tt {
|
|
380
|
+
constructor(t, s) {
|
|
381
|
+
super(), this._pendingOldValue = void 0, this._subscribers = [], this[q] = !0, this[Y] = !0, this._value = t, s && (this.flags |= a.SYNC), B.attachDebugInfo(this, "atom", this.id);
|
|
348
382
|
}
|
|
349
383
|
get value() {
|
|
350
|
-
|
|
351
|
-
return t && K(this, t, this._subscribers), this._value;
|
|
384
|
+
return l.current?.addDependency(this), this._value;
|
|
352
385
|
}
|
|
353
386
|
set value(t) {
|
|
354
|
-
const
|
|
355
|
-
if (Object.is(
|
|
387
|
+
const s = this._value;
|
|
388
|
+
if (Object.is(s, t)) return;
|
|
356
389
|
this._value = t, this.version = M(this.version);
|
|
357
|
-
const
|
|
358
|
-
if (!(this._subscribers.length === 0 ||
|
|
359
|
-
if (this._pendingOldValue =
|
|
390
|
+
const e = this.flags;
|
|
391
|
+
if (!(this._subscribers.length === 0 || e & a.NOTIFICATION_SCHEDULED)) {
|
|
392
|
+
if (this._pendingOldValue = s, this.flags = e | a.NOTIFICATION_SCHEDULED, e & a.SYNC && !T.isBatching) {
|
|
360
393
|
this._flushNotifications();
|
|
361
394
|
return;
|
|
362
395
|
}
|
|
363
|
-
T.schedule(this
|
|
396
|
+
T.schedule(this);
|
|
364
397
|
}
|
|
365
398
|
}
|
|
399
|
+
/**
|
|
400
|
+
* Executes scheduled notification.
|
|
401
|
+
* @internal
|
|
402
|
+
*/
|
|
403
|
+
execute() {
|
|
404
|
+
this._flushNotifications();
|
|
405
|
+
}
|
|
366
406
|
/**
|
|
367
407
|
* Triggers subscribers.
|
|
368
408
|
*/
|
|
@@ -370,8 +410,8 @@ class ft extends Z {
|
|
|
370
410
|
const t = this.flags;
|
|
371
411
|
if (!(t & a.NOTIFICATION_SCHEDULED) || t & a.DISPOSED)
|
|
372
412
|
return;
|
|
373
|
-
const
|
|
374
|
-
this._pendingOldValue = void 0, this.flags &= -17, this._notifySubscribers(this._value,
|
|
413
|
+
const s = this._pendingOldValue;
|
|
414
|
+
this._pendingOldValue = void 0, this.flags &= -17, this._notifySubscribers(this._value, s);
|
|
375
415
|
}
|
|
376
416
|
peek() {
|
|
377
417
|
return this._value;
|
|
@@ -379,21 +419,21 @@ class ft extends Z {
|
|
|
379
419
|
dispose() {
|
|
380
420
|
this.flags & a.DISPOSED || (this._subscribers.length = 0, this.flags |= a.DISPOSED, this._value = void 0, this._pendingOldValue = void 0);
|
|
381
421
|
}
|
|
382
|
-
[(
|
|
422
|
+
[(q = H, Y = dt, Symbol.dispose)]() {
|
|
383
423
|
this.dispose();
|
|
384
424
|
}
|
|
385
425
|
}
|
|
386
|
-
function
|
|
387
|
-
return new
|
|
426
|
+
function bt(n, t = {}) {
|
|
427
|
+
return new It(n, t.sync ?? !1);
|
|
388
428
|
}
|
|
389
|
-
class
|
|
429
|
+
class pt {
|
|
390
430
|
/**
|
|
391
431
|
* @param limit - Max unique arrays to hold (default: 50). Prevents the pool itself from consuming too much memory.
|
|
392
432
|
* @param capacity - Max length of an array to accept (default: 256).
|
|
393
433
|
* @param enableStats - Force-enable stats even in production (default: false).
|
|
394
434
|
*/
|
|
395
|
-
constructor(t = 50,
|
|
396
|
-
this.limit = t, this.capacity =
|
|
435
|
+
constructor(t = 50, s = 256, e = !1) {
|
|
436
|
+
this.limit = t, this.capacity = s, this.pool = [], this.stats = null, this.stats = e ? {
|
|
397
437
|
acquired: 0,
|
|
398
438
|
released: 0,
|
|
399
439
|
rejected: { frozen: 0, tooLarge: 0, poolFull: 0 }
|
|
@@ -411,8 +451,8 @@ class Et {
|
|
|
411
451
|
* @param arr - Array to release.
|
|
412
452
|
* @param emptyConst - Optional empty constant.
|
|
413
453
|
*/
|
|
414
|
-
release(t,
|
|
415
|
-
if (!(
|
|
454
|
+
release(t, s) {
|
|
455
|
+
if (!(s && t === s)) {
|
|
416
456
|
if (t.length > this.capacity) {
|
|
417
457
|
this.stats && this.stats.rejected.tooLarge++;
|
|
418
458
|
return;
|
|
@@ -433,12 +473,12 @@ class Et {
|
|
|
433
473
|
*/
|
|
434
474
|
getStats() {
|
|
435
475
|
if (!this.stats) return null;
|
|
436
|
-
const { acquired: t, released:
|
|
476
|
+
const { acquired: t, released: s, rejected: e } = this.stats, i = t - s - (e.frozen + e.tooLarge + e.poolFull);
|
|
437
477
|
return {
|
|
438
478
|
acquired: t,
|
|
439
|
-
released:
|
|
440
|
-
rejected: { ...
|
|
441
|
-
leaked:
|
|
479
|
+
released: s,
|
|
480
|
+
rejected: { ...e },
|
|
481
|
+
leaked: i,
|
|
442
482
|
poolSize: this.pool.length
|
|
443
483
|
};
|
|
444
484
|
}
|
|
@@ -453,61 +493,60 @@ class Et {
|
|
|
453
493
|
});
|
|
454
494
|
}
|
|
455
495
|
}
|
|
456
|
-
const
|
|
496
|
+
const u = Object.freeze(
|
|
457
497
|
[]
|
|
458
|
-
),
|
|
459
|
-
function Tt(
|
|
460
|
-
return
|
|
498
|
+
), f = new pt();
|
|
499
|
+
function Tt(n) {
|
|
500
|
+
return n !== null && typeof n == "object" && H in n;
|
|
461
501
|
}
|
|
462
|
-
function
|
|
463
|
-
return
|
|
502
|
+
function Nt(n) {
|
|
503
|
+
return n !== null && typeof n == "object" && it in n;
|
|
464
504
|
}
|
|
465
|
-
function
|
|
466
|
-
return
|
|
505
|
+
function Lt(n) {
|
|
506
|
+
return n !== null && typeof n == "object" && nt in n;
|
|
467
507
|
}
|
|
468
|
-
function
|
|
469
|
-
return
|
|
508
|
+
function rt(n) {
|
|
509
|
+
return n !== null && typeof n == "object" && typeof n.then == "function";
|
|
470
510
|
}
|
|
471
|
-
var
|
|
472
|
-
const { IDLE:
|
|
473
|
-
function
|
|
474
|
-
return
|
|
511
|
+
var j, $;
|
|
512
|
+
const { IDLE: L, DIRTY: p, PENDING: O, RESOLVED: E, REJECTED: b, HAS_ERROR: A, RECOMPUTING: D, DISPOSED: P, IS_COMPUTED: Ct } = W;
|
|
513
|
+
function gt(n) {
|
|
514
|
+
return n & E ? N.RESOLVED : n & O ? N.PENDING : n & b ? N.REJECTED : N.IDLE;
|
|
475
515
|
}
|
|
476
|
-
class
|
|
477
|
-
constructor(t,
|
|
478
|
-
if (typeof t != "function") throw new
|
|
479
|
-
super(), this[
|
|
480
|
-
const
|
|
481
|
-
if (this._maxAsyncRetries = (
|
|
516
|
+
class St extends tt {
|
|
517
|
+
constructor(t, s = {}) {
|
|
518
|
+
if (typeof t != "function") throw new I(c.COMPUTED_MUST_BE_FUNCTION);
|
|
519
|
+
super(), this[$] = !0, this[j] = !0, this._error = null, this._promiseId = 0, this._subscribers = [], this._links = u, this._asyncStartAggregateVersion = 0, this._asyncRetryCount = 0, this._lastDriftEpoch = g.UNINITIALIZED, this._trackEpoch = g.UNINITIALIZED, this._trackLinks = u, this._trackCount = 0, this._value = void 0, this.flags = Ct | p | L, this._equal = s.equal ?? Object.is, this._fn = t, this._defaultValue = "defaultValue" in s ? s.defaultValue : x, this._onError = s.onError ?? null;
|
|
520
|
+
const e = s.maxAsyncRetries;
|
|
521
|
+
if (this._maxAsyncRetries = (e ?? V.MAX_ASYNC_RETRIES) & F, B.attachDebugInfo(this, "computed", this.id), s.lazy === !1)
|
|
482
522
|
try {
|
|
483
523
|
this._recompute();
|
|
484
524
|
} catch {
|
|
485
525
|
}
|
|
486
526
|
}
|
|
487
527
|
_track() {
|
|
488
|
-
|
|
489
|
-
t && K(this, t, this._subscribers);
|
|
528
|
+
l.current?.addDependency(this);
|
|
490
529
|
}
|
|
491
530
|
get value() {
|
|
492
531
|
this._track();
|
|
493
532
|
const t = this.flags;
|
|
494
|
-
if ((t & (E | p |
|
|
533
|
+
if ((t & (E | p | L)) === E)
|
|
495
534
|
return this._value;
|
|
496
|
-
if (t &
|
|
497
|
-
throw new
|
|
498
|
-
if (t &
|
|
535
|
+
if (t & P)
|
|
536
|
+
throw new I(c.COMPUTED_DISPOSED);
|
|
537
|
+
if (t & D) {
|
|
499
538
|
if (this._defaultValue !== x) return this._defaultValue;
|
|
500
|
-
throw new
|
|
539
|
+
throw new I(c.COMPUTED_CIRCULAR_DEPENDENCY);
|
|
501
540
|
}
|
|
502
|
-
if (t & (p |
|
|
541
|
+
if (t & (p | L) && (this._recompute(), this.flags & E))
|
|
503
542
|
return this._value;
|
|
504
|
-
const
|
|
505
|
-
if (this.flags &
|
|
506
|
-
if (
|
|
507
|
-
throw new
|
|
543
|
+
const s = this._defaultValue, e = s !== x;
|
|
544
|
+
if (this.flags & O) {
|
|
545
|
+
if (e) return s;
|
|
546
|
+
throw new I(c.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
|
|
508
547
|
}
|
|
509
|
-
if (this.flags &
|
|
510
|
-
if (
|
|
548
|
+
if (this.flags & b) {
|
|
549
|
+
if (e) return s;
|
|
511
550
|
throw this._error;
|
|
512
551
|
}
|
|
513
552
|
return this._value;
|
|
@@ -516,10 +555,10 @@ class It extends Z {
|
|
|
516
555
|
return this._value;
|
|
517
556
|
}
|
|
518
557
|
get state() {
|
|
519
|
-
return this._track(),
|
|
558
|
+
return this._track(), gt(this.flags);
|
|
520
559
|
}
|
|
521
560
|
get hasError() {
|
|
522
|
-
return this._track(), this.flags & (
|
|
561
|
+
return this._track(), this.flags & (b | A) ? !0 : this._links.some((t) => t?.node?.flags & A);
|
|
523
562
|
}
|
|
524
563
|
get isValid() {
|
|
525
564
|
return !this.hasError;
|
|
@@ -527,10 +566,10 @@ class It extends Z {
|
|
|
527
566
|
get errors() {
|
|
528
567
|
if (this._track(), !this.hasError) return ot;
|
|
529
568
|
const t = [];
|
|
530
|
-
return this._error && t.push(this._error), this._links.forEach((
|
|
531
|
-
const
|
|
532
|
-
|
|
533
|
-
|
|
569
|
+
return this._error && t.push(this._error), this._links.forEach((e) => {
|
|
570
|
+
const i = e.node;
|
|
571
|
+
i.flags & A && i.errors.forEach((h) => {
|
|
572
|
+
h && !t.includes(h) && t.push(h);
|
|
534
573
|
});
|
|
535
574
|
}), Object.freeze(t);
|
|
536
575
|
}
|
|
@@ -538,7 +577,7 @@ class It extends Z {
|
|
|
538
577
|
return this._track(), this._error;
|
|
539
578
|
}
|
|
540
579
|
get isPending() {
|
|
541
|
-
return this._track(), (this.flags &
|
|
580
|
+
return this._track(), (this.flags & O) !== 0;
|
|
542
581
|
}
|
|
543
582
|
get isResolved() {
|
|
544
583
|
return this._track(), (this.flags & E) !== 0;
|
|
@@ -547,80 +586,100 @@ class It extends Z {
|
|
|
547
586
|
this._markDirty();
|
|
548
587
|
}
|
|
549
588
|
dispose() {
|
|
550
|
-
if (this.flags &
|
|
589
|
+
if (this.flags & P) return;
|
|
551
590
|
const t = this._links;
|
|
552
|
-
t !==
|
|
591
|
+
t !== u && (t.forEach((s) => s.unsub?.()), f.release(t), this._links = u), this._subscribers.length = 0, this.flags = P | p | L, this._error = null, this._value = void 0;
|
|
553
592
|
}
|
|
554
|
-
[(
|
|
593
|
+
[($ = H, j = it, Symbol.dispose)]() {
|
|
555
594
|
this.dispose();
|
|
556
595
|
}
|
|
557
596
|
addDependency(t) {
|
|
558
597
|
if (t._lastSeenEpoch !== this._trackEpoch) {
|
|
559
|
-
if (t._lastSeenEpoch = this._trackEpoch, this._trackCount < this.
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
|
|
598
|
+
if (t._lastSeenEpoch = this._trackEpoch, this._trackLinks === this._links && this._trackCount < this._links.length && this._links[this._trackCount].node === t) {
|
|
599
|
+
this._links[this._trackCount].version = t.version, this._trackCount++;
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
if (this._trackLinks === this._links) {
|
|
603
|
+
const s = f.acquire();
|
|
604
|
+
for (let e = 0; e < this._trackCount; e++)
|
|
605
|
+
s[e] = this._links[e];
|
|
606
|
+
this._trackLinks = s;
|
|
607
|
+
}
|
|
608
|
+
this._trackCount < this._trackLinks.length ? this._trackLinks[this._trackCount] = new y(t, t.version) : this._trackLinks.push(new y(t, t.version)), this._trackCount++;
|
|
565
609
|
}
|
|
566
610
|
}
|
|
567
611
|
_recompute() {
|
|
568
|
-
if (this.flags &
|
|
569
|
-
this.flags |=
|
|
612
|
+
if (this.flags & D) return;
|
|
613
|
+
this.flags |= D;
|
|
570
614
|
const t = this._links;
|
|
571
|
-
this._trackEpoch = w(), this._trackLinks =
|
|
572
|
-
let
|
|
615
|
+
this._trackEpoch = w(), this._trackLinks = t, this._trackCount = 0;
|
|
616
|
+
let s = !1;
|
|
573
617
|
try {
|
|
574
|
-
const
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
618
|
+
const e = l.run(this, this._fn);
|
|
619
|
+
if (this._trackLinks === t)
|
|
620
|
+
if (this._trackCount === t.length)
|
|
621
|
+
s = !0;
|
|
622
|
+
else {
|
|
623
|
+
for (let i = this._trackCount; i < t.length; i++)
|
|
624
|
+
t[i].unsub?.();
|
|
625
|
+
t.length = this._trackCount, s = !0;
|
|
626
|
+
}
|
|
627
|
+
else
|
|
628
|
+
this._trackLinks.length = this._trackCount, X(this._trackLinks, t, this), this._links = this._trackLinks, s = !0;
|
|
629
|
+
rt(e) ? this._handleAsyncComputation(e) : this._finalizeResolution(e);
|
|
630
|
+
} catch (e) {
|
|
631
|
+
if (!s)
|
|
578
632
|
try {
|
|
579
|
-
|
|
633
|
+
if (this._trackLinks === t) {
|
|
634
|
+
for (let i = this._trackCount; i < t.length; i++)
|
|
635
|
+
t[i].unsub?.();
|
|
636
|
+
t.length = this._trackCount, s = !0;
|
|
637
|
+
} else
|
|
638
|
+
this._trackLinks.length = this._trackCount, X(this._trackLinks, t, this), this._links = this._trackLinks, s = !0;
|
|
580
639
|
} catch {
|
|
581
640
|
}
|
|
582
|
-
this._handleError(
|
|
641
|
+
this._handleError(e, c.COMPUTED_COMPUTATION_FAILED, !0);
|
|
583
642
|
} finally {
|
|
584
|
-
|
|
643
|
+
s ? this._links !== t && t !== u && f.release(t) : this._trackLinks !== t && this._trackLinks !== u && f.release(this._trackLinks), this._trackEpoch = g.UNINITIALIZED, this._trackLinks = u, this._trackCount = 0, this.flags &= ~D;
|
|
585
644
|
}
|
|
586
645
|
}
|
|
587
646
|
_handleAsyncComputation(t) {
|
|
588
|
-
this.flags = (this.flags |
|
|
589
|
-
const
|
|
647
|
+
this.flags = (this.flags | O) & -217, this._notifySubscribers(void 0, void 0), this._asyncStartAggregateVersion = this._captureVersionSnapshot(), this._asyncRetryCount = 0, this._promiseId = (this._promiseId + 1) % V.MAX_PROMISE_ID;
|
|
648
|
+
const s = this._promiseId;
|
|
590
649
|
t.then(
|
|
591
|
-
(
|
|
592
|
-
if (
|
|
650
|
+
(e) => {
|
|
651
|
+
if (s === this._promiseId) {
|
|
593
652
|
if (this._captureVersionSnapshot() !== this._asyncStartAggregateVersion) {
|
|
594
|
-
const
|
|
595
|
-
return this._lastDriftEpoch !==
|
|
596
|
-
new
|
|
653
|
+
const i = et();
|
|
654
|
+
return this._lastDriftEpoch !== i && (this._lastDriftEpoch = i, this._asyncRetryCount = 0), this._asyncRetryCount++ < this._maxAsyncRetries ? this._markDirty() : this._handleError(
|
|
655
|
+
new I(
|
|
597
656
|
`Async drift threshold exceeded after ${this._maxAsyncRetries} retries.`
|
|
598
657
|
),
|
|
599
|
-
|
|
658
|
+
c.COMPUTED_ASYNC_COMPUTATION_FAILED
|
|
600
659
|
);
|
|
601
660
|
}
|
|
602
|
-
this._finalizeResolution(
|
|
661
|
+
this._finalizeResolution(e), this._notifySubscribers(e, void 0);
|
|
603
662
|
}
|
|
604
663
|
},
|
|
605
|
-
(
|
|
664
|
+
(e) => s === this._promiseId && this._handleError(e, c.COMPUTED_ASYNC_COMPUTATION_FAILED)
|
|
606
665
|
);
|
|
607
666
|
}
|
|
608
667
|
_captureVersionSnapshot() {
|
|
609
668
|
let t = 0;
|
|
610
|
-
const
|
|
611
|
-
for (let
|
|
612
|
-
t = (t << 5) - t + e
|
|
669
|
+
const s = this._links;
|
|
670
|
+
for (let e = 0, i = s.length; e < i; e++)
|
|
671
|
+
t = (t << 5) - t + s[e].node.version | 0;
|
|
613
672
|
return t;
|
|
614
673
|
}
|
|
615
|
-
_handleError(t,
|
|
616
|
-
const
|
|
617
|
-
if (!
|
|
674
|
+
_handleError(t, s, e = !1) {
|
|
675
|
+
const i = S(t, I, s);
|
|
676
|
+
if (!e && !(this.flags & b) && (this.version = M(this.version)), this._error = i, this.flags = this.flags & -121 | b | A, this._onError)
|
|
618
677
|
try {
|
|
619
|
-
this._onError(
|
|
678
|
+
this._onError(i);
|
|
620
679
|
} catch (r) {
|
|
621
|
-
console.error(
|
|
680
|
+
console.error(c.CALLBACK_ERROR_IN_ERROR_HANDLER, r);
|
|
622
681
|
}
|
|
623
|
-
if (
|
|
682
|
+
if (e) throw i;
|
|
624
683
|
this._notifySubscribers(void 0, void 0);
|
|
625
684
|
}
|
|
626
685
|
_finalizeResolution(t) {
|
|
@@ -631,110 +690,144 @@ class It extends Z {
|
|
|
631
690
|
}
|
|
632
691
|
/** @internal */
|
|
633
692
|
_markDirty() {
|
|
634
|
-
this.flags & (
|
|
693
|
+
this.flags & (D | p) || (this.flags |= p, this._notifySubscribers(void 0, void 0));
|
|
635
694
|
}
|
|
636
695
|
}
|
|
637
|
-
function At(
|
|
638
|
-
return new
|
|
696
|
+
function At(n, t = {}) {
|
|
697
|
+
return new St(n, t);
|
|
639
698
|
}
|
|
640
|
-
var
|
|
641
|
-
class
|
|
642
|
-
constructor(t,
|
|
643
|
-
super(), this[
|
|
699
|
+
var K;
|
|
700
|
+
class kt extends J {
|
|
701
|
+
constructor(t, s = {}) {
|
|
702
|
+
super(), this[K] = !0, this._cleanup = null, this._links = u, this._nextLinks = null, this._prevLinks = u, this._currentEpoch = g.UNINITIALIZED, this._lastFlushEpoch = g.UNINITIALIZED, this._executionsInEpoch = 0, this._executionCount = 0, this._windowStart = 0, this._windowCount = 0, this._execId = 0, this._trackCount = 0, this._fn = t, this._onError = s.onError ?? null, this._sync = s.sync ?? !1, this._maxExecutions = s.maxExecutionsPerSecond ?? d.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = s.maxExecutionsPerFlush ?? d.MAX_EXECUTIONS_PER_EFFECT, this._sync ? this._notifyCallback = () => this.execute() : this._notifyCallback = () => T.schedule(this), B.attachDebugInfo(this, "effect", this.id);
|
|
644
703
|
}
|
|
645
704
|
run() {
|
|
646
|
-
if (this.flags &
|
|
647
|
-
throw new
|
|
705
|
+
if (this.flags & _.DISPOSED)
|
|
706
|
+
throw new C(c.EFFECT_DISPOSED);
|
|
648
707
|
this.execute(!0);
|
|
649
708
|
}
|
|
650
709
|
dispose() {
|
|
651
|
-
this.flags &
|
|
710
|
+
this.flags & _.DISPOSED || (this.flags |= _.DISPOSED, this._execCleanup(), this._unsubLinks(this._links), this._links !== u && f.release(this._links), this._links = u, this._prevLinks = u);
|
|
652
711
|
}
|
|
653
|
-
[(
|
|
712
|
+
[(K = nt, Symbol.dispose)]() {
|
|
654
713
|
this.dispose();
|
|
655
714
|
}
|
|
656
715
|
addDependency(t) {
|
|
657
|
-
if (!(this.flags &
|
|
658
|
-
const
|
|
659
|
-
if (t._lastSeenEpoch ===
|
|
660
|
-
t._lastSeenEpoch =
|
|
661
|
-
const
|
|
662
|
-
if (
|
|
663
|
-
|
|
664
|
-
o.version = t.version, s.push(o), n[r] = null;
|
|
716
|
+
if (!(this.flags & _.EXECUTING)) return;
|
|
717
|
+
const s = this._currentEpoch;
|
|
718
|
+
if (t._lastSeenEpoch === s) return;
|
|
719
|
+
t._lastSeenEpoch = s;
|
|
720
|
+
const e = this._prevLinks;
|
|
721
|
+
if (this._nextLinks === e && this._trackCount < e.length && e[this._trackCount].node === t) {
|
|
722
|
+
e[this._trackCount].version = t.version, this._trackCount++;
|
|
665
723
|
return;
|
|
666
724
|
}
|
|
667
|
-
|
|
668
|
-
const
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
725
|
+
if (this._nextLinks === e) {
|
|
726
|
+
const h = f.acquire();
|
|
727
|
+
for (let o = 0; o < this._trackCount; o++)
|
|
728
|
+
h[o] = e[o];
|
|
729
|
+
this._nextLinks = h;
|
|
730
|
+
}
|
|
731
|
+
const i = this._nextLinks;
|
|
732
|
+
let r = -1;
|
|
733
|
+
for (let h = this._trackCount; h < e.length; h++) {
|
|
734
|
+
const o = e[h];
|
|
735
|
+
if (o && o.node === t && o.unsub) {
|
|
736
|
+
r = h;
|
|
737
|
+
break;
|
|
738
|
+
}
|
|
678
739
|
}
|
|
740
|
+
if (r !== -1) {
|
|
741
|
+
const h = e[r];
|
|
742
|
+
h.version = t.version, i[this._trackCount] = h, e[r] = null;
|
|
743
|
+
} else
|
|
744
|
+
try {
|
|
745
|
+
const h = t.subscribe(this._notifyCallback);
|
|
746
|
+
i[this._trackCount] = new y(t, t.version, h);
|
|
747
|
+
} catch (h) {
|
|
748
|
+
const o = S(h, C, c.EFFECT_EXECUTION_FAILED);
|
|
749
|
+
if (console.error(o), this._onError)
|
|
750
|
+
try {
|
|
751
|
+
this._onError(o);
|
|
752
|
+
} catch {
|
|
753
|
+
}
|
|
754
|
+
i[this._trackCount] = new y(t, t.version, void 0);
|
|
755
|
+
}
|
|
756
|
+
this._trackCount++;
|
|
679
757
|
}
|
|
680
758
|
/**
|
|
681
759
|
* Executes effect with tracking.
|
|
682
760
|
*/
|
|
683
761
|
execute(t = !1) {
|
|
684
|
-
if (this.flags & (
|
|
685
|
-
this._checkInfiniteLoops(), this.flags |=
|
|
686
|
-
const e = l.acquire();
|
|
687
|
-
this._nextLinks = e, this._currentEpoch = w();
|
|
762
|
+
if (this.flags & (_.DISPOSED | _.EXECUTING) || !t && this._links.length > 0 && !this._isDirty()) return;
|
|
763
|
+
this._checkInfiniteLoops(), this.flags |= _.EXECUTING, this._execCleanup(), this._prevLinks = this._links, this._nextLinks = this._links, this._currentEpoch = w(), this._trackCount = 0;
|
|
688
764
|
let s = !1;
|
|
689
765
|
try {
|
|
690
|
-
const
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
766
|
+
const e = l.run(this, this._fn);
|
|
767
|
+
if (this._nextLinks === this._prevLinks)
|
|
768
|
+
if (this._trackCount === this._prevLinks.length)
|
|
769
|
+
s = !0;
|
|
770
|
+
else {
|
|
771
|
+
for (let i = this._trackCount; i < this._prevLinks.length; i++)
|
|
772
|
+
this._prevLinks[i]?.unsub?.();
|
|
773
|
+
this._prevLinks.length = this._trackCount, s = !0;
|
|
774
|
+
}
|
|
775
|
+
else
|
|
776
|
+
this._nextLinks.length = this._trackCount, s = !0;
|
|
777
|
+
this._links = this._nextLinks, rt(e) ? this._handleAsyncResult(e) : this._cleanup = typeof e == "function" ? e : null;
|
|
778
|
+
} catch (e) {
|
|
779
|
+
if (!s)
|
|
780
|
+
if (this._nextLinks === this._prevLinks) {
|
|
781
|
+
for (let i = this._trackCount; i < this._prevLinks.length; i++)
|
|
782
|
+
this._prevLinks[i]?.unsub?.();
|
|
783
|
+
this._prevLinks.length = this._trackCount, s = !0;
|
|
784
|
+
} else
|
|
785
|
+
this._nextLinks.length = this._trackCount, s = !0;
|
|
786
|
+
this._links = this._nextLinks, this._handleExecutionError(e), this._cleanup = null;
|
|
694
787
|
} finally {
|
|
695
|
-
this._finalizeDependencies(s, this._prevLinks,
|
|
788
|
+
this._finalizeDependencies(s, this._prevLinks, this._nextLinks), this.flags &= -9;
|
|
696
789
|
}
|
|
697
790
|
}
|
|
698
791
|
_handleAsyncResult(t) {
|
|
699
|
-
const
|
|
792
|
+
const s = ++this._execId;
|
|
700
793
|
t.then(
|
|
701
|
-
(
|
|
702
|
-
if (
|
|
703
|
-
if (typeof
|
|
794
|
+
(e) => {
|
|
795
|
+
if (s !== this._execId || this.flags & _.DISPOSED) {
|
|
796
|
+
if (typeof e == "function")
|
|
704
797
|
try {
|
|
705
|
-
|
|
706
|
-
} catch (
|
|
707
|
-
this._handleExecutionError(
|
|
798
|
+
e();
|
|
799
|
+
} catch (i) {
|
|
800
|
+
this._handleExecutionError(i, c.EFFECT_CLEANUP_FAILED);
|
|
708
801
|
}
|
|
709
802
|
return;
|
|
710
803
|
}
|
|
711
|
-
typeof
|
|
804
|
+
typeof e == "function" && (this._cleanup = e);
|
|
712
805
|
},
|
|
713
|
-
(
|
|
806
|
+
(e) => s === this._execId && this._handleExecutionError(e)
|
|
714
807
|
);
|
|
715
808
|
}
|
|
716
|
-
_finalizeDependencies(t,
|
|
717
|
-
this._nextLinks = null, this._prevLinks =
|
|
809
|
+
_finalizeDependencies(t, s, e) {
|
|
810
|
+
this._nextLinks = null, this._prevLinks = u, t ? e !== s && s !== u && (s.forEach((i) => i?.unsub?.()), f.release(s)) : e !== s && e !== u && e && (this._unsubLinks(e), f.release(e));
|
|
718
811
|
}
|
|
719
812
|
_unsubLinks(t) {
|
|
720
|
-
t.forEach((
|
|
813
|
+
t.forEach((s) => s?.unsub?.());
|
|
721
814
|
}
|
|
722
815
|
_isDirty() {
|
|
723
|
-
const t = this._links,
|
|
724
|
-
|
|
816
|
+
const t = this._links, s = l.current;
|
|
817
|
+
l.current = null;
|
|
725
818
|
try {
|
|
726
|
-
return t.some((
|
|
727
|
-
const
|
|
728
|
-
if (
|
|
819
|
+
return t.some((e) => {
|
|
820
|
+
const i = e.node;
|
|
821
|
+
if (i.flags & W.IS_COMPUTED)
|
|
729
822
|
try {
|
|
730
|
-
|
|
823
|
+
i.value;
|
|
731
824
|
} catch {
|
|
732
825
|
return !0;
|
|
733
826
|
}
|
|
734
|
-
return
|
|
827
|
+
return i.version !== e.version;
|
|
735
828
|
});
|
|
736
829
|
} finally {
|
|
737
|
-
|
|
830
|
+
l.current = s;
|
|
738
831
|
}
|
|
739
832
|
}
|
|
740
833
|
_execCleanup() {
|
|
@@ -742,77 +835,73 @@ class St extends J {
|
|
|
742
835
|
try {
|
|
743
836
|
this._cleanup();
|
|
744
837
|
} catch (t) {
|
|
745
|
-
this._handleExecutionError(t,
|
|
838
|
+
this._handleExecutionError(t, c.EFFECT_CLEANUP_FAILED);
|
|
746
839
|
}
|
|
747
840
|
this._cleanup = null;
|
|
748
841
|
}
|
|
749
842
|
}
|
|
750
843
|
_checkInfiniteLoops() {
|
|
751
844
|
const t = et();
|
|
752
|
-
this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"),
|
|
845
|
+
this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), ft() > d.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++;
|
|
753
846
|
}
|
|
754
847
|
get isDisposed() {
|
|
755
|
-
return (this.flags &
|
|
848
|
+
return (this.flags & _.DISPOSED) !== 0;
|
|
756
849
|
}
|
|
757
850
|
get executionCount() {
|
|
758
851
|
return this._executionCount;
|
|
759
852
|
}
|
|
760
853
|
get isExecuting() {
|
|
761
|
-
return (this.flags &
|
|
854
|
+
return (this.flags & _.EXECUTING) !== 0;
|
|
762
855
|
}
|
|
763
856
|
_throwInfiniteLoopError(t) {
|
|
764
|
-
const
|
|
765
|
-
`Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${
|
|
857
|
+
const s = new C(
|
|
858
|
+
`Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${z}`
|
|
766
859
|
);
|
|
767
|
-
throw this.dispose(), console.error(
|
|
860
|
+
throw this.dispose(), console.error(s), s;
|
|
768
861
|
}
|
|
769
|
-
_handleExecutionError(t,
|
|
770
|
-
const
|
|
771
|
-
if (console.error(
|
|
862
|
+
_handleExecutionError(t, s = c.EFFECT_EXECUTION_FAILED) {
|
|
863
|
+
const e = S(t, C, s);
|
|
864
|
+
if (console.error(e), this._onError)
|
|
772
865
|
try {
|
|
773
|
-
this._onError(
|
|
774
|
-
} catch (
|
|
775
|
-
console.error(S(
|
|
866
|
+
this._onError(e);
|
|
867
|
+
} catch (i) {
|
|
868
|
+
console.error(S(i, C, c.CALLBACK_ERROR_IN_ERROR_HANDLER));
|
|
776
869
|
}
|
|
777
870
|
}
|
|
778
871
|
}
|
|
779
|
-
function
|
|
780
|
-
if (typeof
|
|
781
|
-
throw new
|
|
782
|
-
const
|
|
783
|
-
return
|
|
872
|
+
function Ot(n, t = {}) {
|
|
873
|
+
if (typeof n != "function")
|
|
874
|
+
throw new C(c.EFFECT_MUST_BE_FUNCTION);
|
|
875
|
+
const s = new kt(n, t);
|
|
876
|
+
return s.execute(), s;
|
|
784
877
|
}
|
|
785
|
-
function
|
|
786
|
-
if (typeof
|
|
787
|
-
throw new TypeError(
|
|
878
|
+
function yt(n) {
|
|
879
|
+
if (typeof n != "function")
|
|
880
|
+
throw new TypeError(c.BATCH_CALLBACK_MUST_BE_FUNCTION);
|
|
788
881
|
T.startBatch();
|
|
789
882
|
try {
|
|
790
|
-
return
|
|
883
|
+
return n();
|
|
791
884
|
} finally {
|
|
792
885
|
T.endBatch();
|
|
793
886
|
}
|
|
794
887
|
}
|
|
795
888
|
export {
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
F as DEBUG_RUNTIME,
|
|
803
|
-
it as EFFECT_BRAND,
|
|
804
|
-
I as EffectError,
|
|
805
|
-
Dt as POOL_CONFIG,
|
|
889
|
+
N as AsyncState,
|
|
890
|
+
k as AtomError,
|
|
891
|
+
I as ComputedError,
|
|
892
|
+
ht as DEBUG_CONFIG,
|
|
893
|
+
B as DEBUG_RUNTIME,
|
|
894
|
+
C as EffectError,
|
|
806
895
|
d as SCHEDULER_CONFIG,
|
|
807
896
|
m as SchedulerError,
|
|
808
|
-
|
|
809
|
-
|
|
897
|
+
bt as atom,
|
|
898
|
+
yt as batch,
|
|
810
899
|
At as computed,
|
|
811
|
-
|
|
900
|
+
Ot as effect,
|
|
812
901
|
Tt as isAtom,
|
|
813
|
-
|
|
814
|
-
|
|
902
|
+
Nt as isComputed,
|
|
903
|
+
Lt as isEffect,
|
|
815
904
|
T as scheduler,
|
|
816
|
-
|
|
905
|
+
Dt as untracked
|
|
817
906
|
};
|
|
818
907
|
//# sourceMappingURL=index.mjs.map
|