@but212/atom-effect 0.26.0 → 0.27.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 +10 -11
- package/dist/index.mjs +561 -442
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var
|
|
1
|
+
var A = {
|
|
2
2
|
IDLE: "idle",
|
|
3
3
|
PENDING: "pending",
|
|
4
4
|
RESOLVED: "resolved",
|
|
5
5
|
REJECTED: "rejected"
|
|
6
|
-
},
|
|
6
|
+
}, I = {
|
|
7
7
|
DISPOSED: 1,
|
|
8
8
|
EXECUTING: 8
|
|
9
|
-
},
|
|
9
|
+
}, H = {
|
|
10
10
|
DISPOSED: 1,
|
|
11
11
|
IS_COMPUTED: 2,
|
|
12
12
|
DIRTY: 8,
|
|
@@ -21,50 +21,56 @@ var y = {
|
|
|
21
21
|
DISPOSED: 1,
|
|
22
22
|
SYNC: 8,
|
|
23
23
|
NOTIFICATION_SCHEDULED: 16
|
|
24
|
-
},
|
|
24
|
+
}, C = {
|
|
25
25
|
MAX_EXECUTIONS_PER_SECOND: 1e3,
|
|
26
26
|
MAX_EXECUTIONS_PER_EFFECT: 100,
|
|
27
27
|
MAX_EXECUTIONS_PER_FLUSH: 1e4,
|
|
28
28
|
MAX_FLUSH_ITERATIONS: 1e3,
|
|
29
29
|
MIN_FLUSH_ITERATIONS: 10,
|
|
30
30
|
BATCH_QUEUE_SHRINK_THRESHOLD: 1e3
|
|
31
|
-
},
|
|
31
|
+
}, st = {
|
|
32
32
|
WARN_INFINITE_LOOP: !0,
|
|
33
33
|
EFFECT_FREQUENCY_WINDOW: 1e3
|
|
34
|
-
},
|
|
34
|
+
}, j = {
|
|
35
35
|
MAX_ASYNC_RETRIES: 3,
|
|
36
36
|
MAX_PROMISE_ID: Number.MAX_SAFE_INTEGER - 1
|
|
37
|
-
},
|
|
37
|
+
}, T = {
|
|
38
38
|
UNINITIALIZED: -1,
|
|
39
39
|
MIN: 1
|
|
40
|
-
},
|
|
40
|
+
}, w = 1073741823, _t = { VERSION_BITS: 16 }, mt = (typeof process < "u" && process.env, !1), W = Object.freeze([]), z = class {
|
|
41
41
|
constructor(t, s, e = void 0) {
|
|
42
42
|
this.node = t, this.version = s, this.unsub = e;
|
|
43
43
|
}
|
|
44
|
-
},
|
|
44
|
+
}, ft = class {
|
|
45
45
|
constructor(t, s) {
|
|
46
46
|
this.fn = t, this.sub = s;
|
|
47
47
|
}
|
|
48
48
|
notify(t, s) {
|
|
49
|
-
|
|
49
|
+
const e = this.fn;
|
|
50
|
+
if (e !== void 0) {
|
|
51
|
+
e(t, s);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const i = this.sub;
|
|
55
|
+
i !== void 0 && i.execute();
|
|
50
56
|
}
|
|
51
|
-
},
|
|
57
|
+
}, N = class extends Error {
|
|
52
58
|
constructor(t, s = null, e = !0) {
|
|
53
59
|
super(t), this.cause = s, this.recoverable = e, this.name = "AtomError";
|
|
54
60
|
}
|
|
55
|
-
},
|
|
61
|
+
}, S = class extends N {
|
|
56
62
|
constructor(t, s = null) {
|
|
57
63
|
super(t, s, !0), this.name = "ComputedError";
|
|
58
64
|
}
|
|
59
|
-
},
|
|
65
|
+
}, v = class extends N {
|
|
60
66
|
constructor(t, s = null) {
|
|
61
67
|
super(t, s, !1), this.name = "EffectError";
|
|
62
68
|
}
|
|
63
|
-
},
|
|
69
|
+
}, L = class extends N {
|
|
64
70
|
constructor(t, s = null) {
|
|
65
71
|
super(t, s, !1), this.name = "SchedulerError";
|
|
66
72
|
}
|
|
67
|
-
},
|
|
73
|
+
}, c = {
|
|
68
74
|
COMPUTED_MUST_BE_FUNCTION: "Computed target must be a function",
|
|
69
75
|
COMPUTED_ASYNC_PENDING_NO_DEFAULT: "Async computation pending with no default value",
|
|
70
76
|
COMPUTED_COMPUTATION_FAILED: "Computation execution failed",
|
|
@@ -91,7 +97,7 @@ var y = {
|
|
|
91
97
|
return this._count;
|
|
92
98
|
}
|
|
93
99
|
getAt(t) {
|
|
94
|
-
switch (t) {
|
|
100
|
+
if (t < 4) switch (t) {
|
|
95
101
|
case 0:
|
|
96
102
|
return this._s0;
|
|
97
103
|
case 1:
|
|
@@ -100,15 +106,13 @@ var y = {
|
|
|
100
106
|
return this._s2;
|
|
101
107
|
case 3:
|
|
102
108
|
return this._s3;
|
|
103
|
-
default: {
|
|
104
|
-
const s = this._overflow;
|
|
105
|
-
if (s !== null && t >= 4) {
|
|
106
|
-
const e = t - 4;
|
|
107
|
-
if (e < s.length) return s[e] ?? null;
|
|
108
|
-
}
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
109
|
}
|
|
110
|
+
const s = this._overflow;
|
|
111
|
+
if (s !== null) {
|
|
112
|
+
const e = s[t - 4];
|
|
113
|
+
return e === void 0 ? null : e;
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
112
116
|
}
|
|
113
117
|
setAt(t, s) {
|
|
114
118
|
switch (t) {
|
|
@@ -124,41 +128,38 @@ var y = {
|
|
|
124
128
|
case 3:
|
|
125
129
|
this._s3 = s;
|
|
126
130
|
break;
|
|
127
|
-
default:
|
|
128
|
-
this._overflow ??= [];
|
|
129
|
-
const e = this._overflow;
|
|
130
|
-
e[t - 4] = s;
|
|
131
|
-
}
|
|
131
|
+
default:
|
|
132
|
+
this._overflow ??= [], this._overflow[t - 4] = s;
|
|
132
133
|
}
|
|
133
134
|
t >= this._count && (this._count = t + 1);
|
|
134
135
|
}
|
|
135
136
|
truncateFrom(t) {
|
|
136
137
|
const s = this._count;
|
|
137
138
|
if (t >= s) return;
|
|
138
|
-
if (t <= 3)
|
|
139
|
-
|
|
139
|
+
if (t <= 3) {
|
|
140
|
+
if (t <= 0) {
|
|
140
141
|
const i = this._s0;
|
|
141
142
|
i != null && (this._onItemRemoved(i), this._s0 = null);
|
|
142
143
|
}
|
|
143
|
-
|
|
144
|
+
if (t <= 1) {
|
|
144
145
|
const i = this._s1;
|
|
145
146
|
i != null && (this._onItemRemoved(i), this._s1 = null);
|
|
146
147
|
}
|
|
147
|
-
|
|
148
|
+
if (t <= 2) {
|
|
148
149
|
const i = this._s2;
|
|
149
150
|
i != null && (this._onItemRemoved(i), this._s2 = null);
|
|
150
151
|
}
|
|
151
|
-
|
|
152
|
+
if (t <= 3) {
|
|
152
153
|
const i = this._s3;
|
|
153
154
|
i != null && (this._onItemRemoved(i), this._s3 = null);
|
|
154
155
|
}
|
|
155
156
|
}
|
|
156
157
|
const e = this._overflow;
|
|
157
158
|
if (e !== null && s > 4) {
|
|
158
|
-
const i = t > 4 ? t - 4 : 0,
|
|
159
|
-
for (let
|
|
160
|
-
const
|
|
161
|
-
|
|
159
|
+
const i = t > 4 ? t - 4 : 0, r = e.length;
|
|
160
|
+
for (let n = i; n < r; n++) {
|
|
161
|
+
const o = e[n];
|
|
162
|
+
o != null && (this._onItemRemoved(o), e[n] = null);
|
|
162
163
|
}
|
|
163
164
|
t <= 4 ? (e.length = 0, this._overflow = null) : e.length = t - 4;
|
|
164
165
|
}
|
|
@@ -186,10 +187,11 @@ var y = {
|
|
|
186
187
|
this._addToOverflow(t);
|
|
187
188
|
}
|
|
188
189
|
_addToOverflow(t) {
|
|
189
|
-
|
|
190
|
+
const s = this._overflow;
|
|
191
|
+
if (s === null) this._overflow = [t];
|
|
190
192
|
else {
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
+
const e = this._freeIndices;
|
|
194
|
+
e !== null && e.length > 0 ? s[e.pop()] = t : s.push(t);
|
|
193
195
|
}
|
|
194
196
|
this._count++;
|
|
195
197
|
}
|
|
@@ -204,8 +206,11 @@ var y = {
|
|
|
204
206
|
return this._s3 = null, this._count--, !0;
|
|
205
207
|
const s = this._overflow;
|
|
206
208
|
if (s == null) return !1;
|
|
207
|
-
for (let e = 0, i = s.length; e < i; e++) if (s[e] === t)
|
|
208
|
-
|
|
209
|
+
for (let e = 0, i = s.length; e < i; e++) if (s[e] === t) {
|
|
210
|
+
s[e] = null, this._count--;
|
|
211
|
+
let r = this._freeIndices;
|
|
212
|
+
return r === null && (r = this._freeIndices = []), r.push(e), !0;
|
|
213
|
+
}
|
|
209
214
|
return !1;
|
|
210
215
|
}
|
|
211
216
|
has(t) {
|
|
@@ -218,19 +223,26 @@ var y = {
|
|
|
218
223
|
return !1;
|
|
219
224
|
}
|
|
220
225
|
forEach(t) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const
|
|
231
|
-
if (
|
|
232
|
-
|
|
233
|
-
|
|
226
|
+
const s = this._count;
|
|
227
|
+
if (s === 0) return;
|
|
228
|
+
let e = 0;
|
|
229
|
+
const i = this._s0;
|
|
230
|
+
if (i != null && (t(i), ++e === s))
|
|
231
|
+
return;
|
|
232
|
+
const r = this._s1;
|
|
233
|
+
if (r != null && (t(r), ++e === s))
|
|
234
|
+
return;
|
|
235
|
+
const n = this._s2;
|
|
236
|
+
if (n != null && (t(n), ++e === s))
|
|
237
|
+
return;
|
|
238
|
+
const o = this._s3;
|
|
239
|
+
if (o != null && (t(o), ++e === s))
|
|
240
|
+
return;
|
|
241
|
+
const u = this._overflow;
|
|
242
|
+
if (u != null) for (let h = 0, l = u.length; h < l; h++) {
|
|
243
|
+
const f = u[h];
|
|
244
|
+
if (f != null && (t(f), ++e === s))
|
|
245
|
+
return;
|
|
234
246
|
}
|
|
235
247
|
}
|
|
236
248
|
forEachIndexed(t) {
|
|
@@ -238,29 +250,37 @@ var y = {
|
|
|
238
250
|
if (s === 0) return 0;
|
|
239
251
|
let e = 0;
|
|
240
252
|
const i = this._s0;
|
|
241
|
-
i != null && (t(i), e
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const
|
|
247
|
-
if (
|
|
253
|
+
if (i != null && (t(i), ++e === s))
|
|
254
|
+
return e;
|
|
255
|
+
const r = this._s1;
|
|
256
|
+
if (r != null && (t(r), ++e === s))
|
|
257
|
+
return e;
|
|
258
|
+
const n = this._s2;
|
|
259
|
+
if (n != null && (t(n), ++e === s))
|
|
260
|
+
return e;
|
|
261
|
+
const o = this._s3;
|
|
262
|
+
if (o != null && (t(o), ++e === s))
|
|
263
|
+
return e;
|
|
248
264
|
const u = this._overflow;
|
|
249
|
-
if (u != null) for (let
|
|
250
|
-
const
|
|
251
|
-
|
|
265
|
+
if (u != null) for (let h = 0, l = u.length; h < l; h++) {
|
|
266
|
+
const f = u[h];
|
|
267
|
+
if (f != null && (t(f), ++e === s))
|
|
268
|
+
return e;
|
|
252
269
|
}
|
|
253
270
|
return e;
|
|
254
271
|
}
|
|
255
272
|
compact() {
|
|
256
273
|
const t = this._overflow;
|
|
257
|
-
if (t === null
|
|
258
|
-
let s =
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
274
|
+
if (t === null) return;
|
|
275
|
+
let s = t.length;
|
|
276
|
+
if (s === 0) return;
|
|
277
|
+
let e = 0;
|
|
278
|
+
for (; e < s; ) if (t[e] === null) {
|
|
279
|
+
for (; s > e && t[s - 1] === null; )
|
|
280
|
+
t.pop(), s--;
|
|
281
|
+
s > e && (t[e] = t.pop(), s--, e++);
|
|
282
|
+
} else e++;
|
|
283
|
+
this._freeIndices = null, s === 0 && (this._overflow = null);
|
|
264
284
|
}
|
|
265
285
|
clear() {
|
|
266
286
|
this._s0 = null, this._s1 = null, this._s2 = null, this._s3 = null, this._count = 0, this._overflow !== null && (this._overflow.length = 0, this._overflow = null), this._freeIndices = null;
|
|
@@ -268,111 +288,170 @@ var y = {
|
|
|
268
288
|
dispose() {
|
|
269
289
|
this.clear();
|
|
270
290
|
}
|
|
271
|
-
},
|
|
272
|
-
|
|
273
|
-
|
|
291
|
+
}, K = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), at = /* @__PURE__ */ Symbol("AtomEffect.Id"), Z = /* @__PURE__ */ Symbol("AtomEffect.Type"), P = /* @__PURE__ */ Symbol("AtomEffect.NoDefaultValue"), Et = class {
|
|
292
|
+
constructor() {
|
|
293
|
+
this.enabled = !1, this.warnInfiniteLoop = st.WARN_INFINITE_LOOP;
|
|
294
|
+
}
|
|
274
295
|
warn(t, s) {
|
|
275
|
-
}
|
|
296
|
+
}
|
|
276
297
|
attachDebugInfo(t, s, e) {
|
|
277
|
-
}
|
|
278
|
-
getDebugName
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
298
|
+
}
|
|
299
|
+
getDebugName(t) {
|
|
300
|
+
if (t != null)
|
|
301
|
+
return t[K];
|
|
302
|
+
}
|
|
303
|
+
getDebugType(t) {
|
|
304
|
+
if (t != null)
|
|
305
|
+
return t[Z];
|
|
306
|
+
}
|
|
307
|
+
}, G = new Et(), dt = 1, pt = () => dt++ | 0;
|
|
308
|
+
function m(t, s, e) {
|
|
309
|
+
return t instanceof N ? t : t instanceof Error ? new s(`${t.name || t.constructor.name || "Error"} (${e}): ${t.message}`, t) : new s(`Unexpected error (${e}): ${String(t)}`);
|
|
285
310
|
}
|
|
286
|
-
var
|
|
311
|
+
var Q = class {
|
|
287
312
|
constructor() {
|
|
288
|
-
this.flags = 0, this.version = 0, this._lastSeenEpoch =
|
|
313
|
+
this.flags = 0, this.version = 0, this._lastSeenEpoch = T.UNINITIALIZED, this._notifying = 0, this._hotIndex = -1, this._slots = null, this._deps = null, this.id = pt() & w;
|
|
314
|
+
}
|
|
315
|
+
get isDisposed() {
|
|
316
|
+
return (this.flags & H.DISPOSED) !== 0;
|
|
317
|
+
}
|
|
318
|
+
get isComputed() {
|
|
319
|
+
return (this.flags & H.IS_COMPUTED) !== 0;
|
|
320
|
+
}
|
|
321
|
+
get hasError() {
|
|
322
|
+
return !1;
|
|
289
323
|
}
|
|
290
324
|
subscribe(t) {
|
|
291
325
|
const s = typeof t == "function";
|
|
292
|
-
if (!s && (!t || typeof t.execute != "function")) throw
|
|
326
|
+
if (!s && (!t || typeof t.execute != "function")) throw m(/* @__PURE__ */ new TypeError("Invalid subscriber"), N, c.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
|
|
293
327
|
let e = this._slots;
|
|
294
328
|
e || (e = new et(), this._slots = e);
|
|
295
329
|
let i = !1;
|
|
296
|
-
if (e.
|
|
297
|
-
|
|
298
|
-
|
|
330
|
+
if (e._s0 != null && (s ? e._s0.fn === t : e._s0.sub === t)) i = !0;
|
|
331
|
+
else if (e._s1 != null && (s ? e._s1.fn === t : e._s1.sub === t)) i = !0;
|
|
332
|
+
else if (e._s2 != null && (s ? e._s2.fn === t : e._s2.sub === t)) i = !0;
|
|
333
|
+
else if (e._s3 != null && (s ? e._s3.fn === t : e._s3.sub === t)) i = !0;
|
|
334
|
+
else {
|
|
335
|
+
const n = e._overflow;
|
|
336
|
+
if (n != null) for (let o = 0, u = n.length; o < u; o++) {
|
|
337
|
+
const h = n[o];
|
|
338
|
+
if (h != null && (s ? h.fn === t : h.sub === t)) {
|
|
339
|
+
i = !0;
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (i)
|
|
299
345
|
return () => {
|
|
300
346
|
};
|
|
301
|
-
const
|
|
302
|
-
return e.add(
|
|
347
|
+
const r = new ft(s ? t : void 0, s ? void 0 : t);
|
|
348
|
+
return e.add(r), () => this._unsubscribe(r);
|
|
303
349
|
}
|
|
304
350
|
_unsubscribe(t) {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
this._slots.remove(t);
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
this._slots.remove(t), this._slots.compact();
|
|
311
|
-
}
|
|
351
|
+
const s = this._slots;
|
|
352
|
+
s && (s.remove(t), this._notifying === 0 && s.compact());
|
|
312
353
|
}
|
|
313
354
|
subscriberCount() {
|
|
314
|
-
|
|
355
|
+
const t = this._slots;
|
|
356
|
+
return t === null ? 0 : t.size;
|
|
315
357
|
}
|
|
316
358
|
_notifySubscribers(t, s) {
|
|
317
359
|
const e = this._slots;
|
|
318
|
-
if (!(
|
|
360
|
+
if (!(e === null || e.size === 0)) {
|
|
319
361
|
this._notifying++;
|
|
320
362
|
try {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
363
|
+
let i = e._s0;
|
|
364
|
+
if (i != null) try {
|
|
365
|
+
i.notify(t, s);
|
|
366
|
+
} catch (n) {
|
|
367
|
+
this._logNotifyError(n);
|
|
368
|
+
}
|
|
369
|
+
if (i = e._s1, i != null) try {
|
|
370
|
+
i.notify(t, s);
|
|
371
|
+
} catch (n) {
|
|
372
|
+
this._logNotifyError(n);
|
|
373
|
+
}
|
|
374
|
+
if (i = e._s2, i != null) try {
|
|
375
|
+
i.notify(t, s);
|
|
376
|
+
} catch (n) {
|
|
377
|
+
this._logNotifyError(n);
|
|
378
|
+
}
|
|
379
|
+
if (i = e._s3, i != null) try {
|
|
380
|
+
i.notify(t, s);
|
|
381
|
+
} catch (n) {
|
|
382
|
+
this._logNotifyError(n);
|
|
383
|
+
}
|
|
384
|
+
const r = e._overflow;
|
|
385
|
+
if (r != null) for (let n = 0, o = r.length; n < o; n++) {
|
|
386
|
+
const u = r[n];
|
|
387
|
+
if (u != null) try {
|
|
388
|
+
u.notify(t, s);
|
|
389
|
+
} catch (h) {
|
|
390
|
+
this._logNotifyError(h);
|
|
326
391
|
}
|
|
327
|
-
}
|
|
392
|
+
}
|
|
328
393
|
} finally {
|
|
329
|
-
this._notifying
|
|
394
|
+
--this._notifying === 0 && e.compact();
|
|
330
395
|
}
|
|
331
396
|
}
|
|
332
397
|
}
|
|
398
|
+
_logNotifyError(t) {
|
|
399
|
+
console.error(m(t, N, c.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED));
|
|
400
|
+
}
|
|
333
401
|
_isDirty() {
|
|
334
402
|
const t = this._deps;
|
|
335
|
-
if (
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
403
|
+
if (t === null || t.size === 0) return !1;
|
|
404
|
+
const s = this._hotIndex;
|
|
405
|
+
if (s !== -1) {
|
|
406
|
+
const e = t.getAt(s);
|
|
407
|
+
if (e != null && e.node.version !== e.version) return !0;
|
|
339
408
|
}
|
|
340
409
|
return !t.hasComputeds && !t.isDirtyFast() ? !1 : this._deepDirtyCheck();
|
|
341
410
|
}
|
|
342
|
-
},
|
|
343
|
-
function
|
|
344
|
-
|
|
411
|
+
}, M = 0;
|
|
412
|
+
function Y() {
|
|
413
|
+
const t = M + 1 & w;
|
|
414
|
+
return M = t === 0 ? 1 : t, M;
|
|
415
|
+
}
|
|
416
|
+
function X(t) {
|
|
417
|
+
const s = t + 1 & w;
|
|
418
|
+
return s === 0 ? 1 : s;
|
|
345
419
|
}
|
|
346
|
-
var
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}
|
|
420
|
+
var k = 0, R = !1, it = 0;
|
|
421
|
+
function nt() {
|
|
422
|
+
return it;
|
|
423
|
+
}
|
|
424
|
+
function J() {
|
|
425
|
+
return R ? !1 : (R = !0, it = Y(), k = 0, !0);
|
|
426
|
+
}
|
|
427
|
+
function tt() {
|
|
428
|
+
R = !1;
|
|
429
|
+
}
|
|
430
|
+
function Ct() {
|
|
431
|
+
if (!R) return 0;
|
|
432
|
+
const t = ++k;
|
|
433
|
+
if (t <= C.MAX_EXECUTIONS_PER_FLUSH) return t;
|
|
434
|
+
throw new Error(`[atom-effect] Infinite loop detected: flush execution count exceeded ${C.MAX_EXECUTIONS_PER_FLUSH}`);
|
|
435
|
+
}
|
|
436
|
+
var It = class {
|
|
356
437
|
constructor() {
|
|
357
|
-
this._queueBuffer = [[], []], this._bufferIndex = 0, this._size = 0, this._epoch = 0, this._isProcessing = !1, this.
|
|
358
|
-
}
|
|
359
|
-
get phase() {
|
|
360
|
-
return this._isProcessing || this._isFlushingSync ? w.FLUSHING : this._isBatching ? w.BATCHING : w.IDLE;
|
|
438
|
+
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);
|
|
361
439
|
}
|
|
362
440
|
get queueSize() {
|
|
363
441
|
return this._size;
|
|
364
442
|
}
|
|
365
443
|
get isBatching() {
|
|
366
|
-
return this.
|
|
444
|
+
return this._batchDepth > 0;
|
|
367
445
|
}
|
|
368
446
|
schedule(t) {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
this._queueBuffer[this._bufferIndex][this._size++] = t, this._isProcessing || this._flush();
|
|
447
|
+
const s = this._epoch;
|
|
448
|
+
if (t._nextEpoch === s) return;
|
|
449
|
+
if (t._nextEpoch = s, this._batchDepth > 0 || this._isFlushingSync) {
|
|
450
|
+
this._batchQueue[this._batchQueueSize++] = t;
|
|
451
|
+
return;
|
|
375
452
|
}
|
|
453
|
+
const e = this._bufferIndex, i = this._queueBuffer[e];
|
|
454
|
+
i[this._size++] = t, this._isProcessing || this._flush();
|
|
376
455
|
}
|
|
377
456
|
_flush() {
|
|
378
457
|
this._isProcessing || this._size === 0 || (this._isProcessing = !0, queueMicrotask(this._boundRunLoop));
|
|
@@ -380,30 +459,31 @@ var J = () => {
|
|
|
380
459
|
_runLoop() {
|
|
381
460
|
try {
|
|
382
461
|
if (this._size === 0) return;
|
|
383
|
-
const t =
|
|
384
|
-
this._drainQueue(), t &&
|
|
462
|
+
const t = J();
|
|
463
|
+
this._drainQueue(), t && tt();
|
|
385
464
|
} finally {
|
|
386
|
-
this._isProcessing = !1, this._size > 0 &&
|
|
465
|
+
this._isProcessing = !1, this._size > 0 && this._batchDepth === 0 && this._flush();
|
|
387
466
|
}
|
|
388
467
|
}
|
|
389
468
|
_flushSync() {
|
|
390
469
|
this._isFlushingSync = !0;
|
|
391
|
-
const t =
|
|
470
|
+
const t = J();
|
|
392
471
|
try {
|
|
393
472
|
this._mergeBatchQueue(), this._drainQueue();
|
|
394
473
|
} finally {
|
|
395
|
-
this._isFlushingSync = !1, t &&
|
|
474
|
+
this._isFlushingSync = !1, t && tt();
|
|
396
475
|
}
|
|
397
476
|
}
|
|
398
477
|
_mergeBatchQueue() {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
478
|
+
const t = this._batchQueueSize;
|
|
479
|
+
if (t === 0) return;
|
|
480
|
+
const s = ++this._epoch, e = this._batchQueue, i = this._bufferIndex, r = this._queueBuffer[i];
|
|
481
|
+
let n = this._size;
|
|
482
|
+
for (let o = 0; o < t; o++) {
|
|
483
|
+
const u = e[o];
|
|
484
|
+
u._nextEpoch !== s && (u._nextEpoch = s, r[n++] = u);
|
|
405
485
|
}
|
|
406
|
-
this._size =
|
|
486
|
+
this._size = n, this._batchQueueSize = 0, e.length = 0;
|
|
407
487
|
}
|
|
408
488
|
_drainQueue() {
|
|
409
489
|
let t = 0;
|
|
@@ -417,34 +497,42 @@ var J = () => {
|
|
|
417
497
|
}
|
|
418
498
|
_processQueue() {
|
|
419
499
|
const t = this._bufferIndex, s = this._queueBuffer[t], e = this._size;
|
|
420
|
-
this._bufferIndex = t ^ 1, this._size = 0, this._epoch
|
|
421
|
-
for (let i = 0; i < e; i++)
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
500
|
+
this._bufferIndex = t ^ 1, this._size = 0, this._epoch = this._epoch + 1 | 0;
|
|
501
|
+
for (let i = 0; i < e; i++) {
|
|
502
|
+
const r = s[i];
|
|
503
|
+
try {
|
|
504
|
+
typeof r == "function" ? r() : r.execute();
|
|
505
|
+
} catch (n) {
|
|
506
|
+
console.error(new L("Error occurred during scheduler execution", n));
|
|
507
|
+
}
|
|
426
508
|
}
|
|
427
509
|
s.length = 0;
|
|
428
510
|
}
|
|
429
511
|
_handleFlushOverflow() {
|
|
430
|
-
const t = this._size + this._batchQueueSize;
|
|
431
|
-
|
|
432
|
-
|
|
512
|
+
const t = this._size + this._batchQueueSize, s = this._maxFlushIterations;
|
|
513
|
+
console.error(new L(c.SCHEDULER_FLUSH_OVERFLOW(s, t))), this._size = 0;
|
|
514
|
+
const e = this._bufferIndex;
|
|
515
|
+
this._queueBuffer[e].length = 0, this._batchQueueSize = 0;
|
|
516
|
+
const i = this.onOverflow;
|
|
517
|
+
if (i) try {
|
|
518
|
+
i(t);
|
|
433
519
|
} catch {
|
|
434
520
|
}
|
|
435
521
|
}
|
|
436
522
|
startBatch() {
|
|
437
|
-
this._batchDepth
|
|
523
|
+
this._batchDepth++;
|
|
438
524
|
}
|
|
439
525
|
endBatch() {
|
|
440
|
-
this._batchDepth !== 0 && --this._batchDepth === 0 &&
|
|
526
|
+
this._batchDepth !== 0 && --this._batchDepth === 0 && this._flushSync();
|
|
441
527
|
}
|
|
442
528
|
setMaxFlushIterations(t) {
|
|
443
|
-
if (t <
|
|
529
|
+
if (t < C.MIN_FLUSH_ITERATIONS) throw new L(`Max flush iterations must be at least ${C.MIN_FLUSH_ITERATIONS}`);
|
|
444
530
|
this._maxFlushIterations = t;
|
|
445
531
|
}
|
|
446
|
-
},
|
|
447
|
-
|
|
532
|
+
}, F = new It(), V = /* @__PURE__ */ Symbol.for("atom-effect/atom"), rt = /* @__PURE__ */ Symbol.for("atom-effect/computed"), ot = /* @__PURE__ */ Symbol.for("atom-effect/effect"), Dt = /* @__PURE__ */ Symbol.for("atom-effect/writable"), vt = class {
|
|
533
|
+
constructor() {
|
|
534
|
+
this.current = null;
|
|
535
|
+
}
|
|
448
536
|
run(t, s) {
|
|
449
537
|
const e = this.current;
|
|
450
538
|
this.current = t;
|
|
@@ -454,20 +542,26 @@ var J = () => {
|
|
|
454
542
|
this.current = e;
|
|
455
543
|
}
|
|
456
544
|
}
|
|
457
|
-
};
|
|
458
|
-
function
|
|
459
|
-
const s = _.current;
|
|
460
|
-
if (
|
|
461
|
-
|
|
545
|
+
}, _ = new vt();
|
|
546
|
+
function Nt(t) {
|
|
547
|
+
const s = _, e = s.current;
|
|
548
|
+
if (e === null) return t();
|
|
549
|
+
s.current = null;
|
|
462
550
|
try {
|
|
463
551
|
return t();
|
|
464
552
|
} finally {
|
|
465
|
-
|
|
553
|
+
s.current = e;
|
|
466
554
|
}
|
|
467
555
|
}
|
|
468
|
-
var
|
|
556
|
+
var St = class extends Q {
|
|
469
557
|
constructor(t, s) {
|
|
470
|
-
super(), this[
|
|
558
|
+
super(), this[V] = !0, this[Dt] = !0, this._value = t, s && (this.flags |= a.SYNC), G.attachDebugInfo(this, "atom", this.id);
|
|
559
|
+
}
|
|
560
|
+
get isNotificationScheduled() {
|
|
561
|
+
return (this.flags & a.NOTIFICATION_SCHEDULED) !== 0;
|
|
562
|
+
}
|
|
563
|
+
get isSync() {
|
|
564
|
+
return (this.flags & a.SYNC) !== 0;
|
|
471
565
|
}
|
|
472
566
|
get value() {
|
|
473
567
|
const t = _.current;
|
|
@@ -476,31 +570,27 @@ var dt = class extends X {
|
|
|
476
570
|
set value(t) {
|
|
477
571
|
const s = this._value;
|
|
478
572
|
if (Object.is(s, t)) return;
|
|
479
|
-
this._value = t, this.version =
|
|
480
|
-
const e = this.
|
|
481
|
-
if (e
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
if (this.flags = n, (n & a.SYNC) !== 0 && !A.isBatching) {
|
|
485
|
-
this._flushNotifications();
|
|
486
|
-
return;
|
|
487
|
-
}
|
|
488
|
-
A.schedule(this);
|
|
573
|
+
this._value = t, this.version = X(this.version);
|
|
574
|
+
const e = this.flags;
|
|
575
|
+
if ((e & a.NOTIFICATION_SCHEDULED) !== 0) return;
|
|
576
|
+
const i = this._slots;
|
|
577
|
+
i == null || i.size === 0 || (this._pendingOldValue = s, this.flags = e | a.NOTIFICATION_SCHEDULED, (e & a.SYNC) !== 0 && !F.isBatching ? this._flushNotifications() : F.schedule(this));
|
|
489
578
|
}
|
|
490
579
|
execute() {
|
|
491
580
|
this._flushNotifications();
|
|
492
581
|
}
|
|
493
582
|
_flushNotifications() {
|
|
494
583
|
const t = this.flags;
|
|
495
|
-
if (
|
|
584
|
+
if ((t & (a.NOTIFICATION_SCHEDULED | a.DISPOSED)) !== a.NOTIFICATION_SCHEDULED) return;
|
|
496
585
|
const s = this._pendingOldValue;
|
|
497
|
-
this._pendingOldValue = void 0, this.flags
|
|
586
|
+
this._pendingOldValue = void 0, this.flags = t & ~a.NOTIFICATION_SCHEDULED, this._notifySubscribers(this._value, s);
|
|
498
587
|
}
|
|
499
588
|
peek() {
|
|
500
589
|
return this._value;
|
|
501
590
|
}
|
|
502
591
|
dispose() {
|
|
503
|
-
|
|
592
|
+
const t = this.flags;
|
|
593
|
+
(t & a.DISPOSED) === 0 && (this._slots?.clear(), this.flags = t | a.DISPOSED, this._value = void 0, this._pendingOldValue = void 0);
|
|
504
594
|
}
|
|
505
595
|
_deepDirtyCheck() {
|
|
506
596
|
return !1;
|
|
@@ -509,12 +599,12 @@ var dt = class extends X {
|
|
|
509
599
|
this.dispose();
|
|
510
600
|
}
|
|
511
601
|
};
|
|
512
|
-
function
|
|
513
|
-
return new
|
|
602
|
+
function yt(t, s = {}) {
|
|
603
|
+
return new St(t, s.sync ?? !1);
|
|
514
604
|
}
|
|
515
|
-
var
|
|
516
|
-
constructor() {
|
|
517
|
-
super(), this._map = null, this._SCAN_THRESHOLD = 32, this.hasComputeds = !1, this._depsHash = 0
|
|
605
|
+
var ut = class extends et {
|
|
606
|
+
constructor(...t) {
|
|
607
|
+
super(...t), this._map = null, this._SCAN_THRESHOLD = 32, this.hasComputeds = !1, this._depsHash = 0;
|
|
518
608
|
}
|
|
519
609
|
prepareTracking() {
|
|
520
610
|
this.hasComputeds = !1;
|
|
@@ -530,88 +620,101 @@ var z = class extends et {
|
|
|
530
620
|
if (this._map !== null || i > this._SCAN_THRESHOLD) return this._claimViaMap(t, s);
|
|
531
621
|
if (s < 4) switch (s) {
|
|
532
622
|
case 0: {
|
|
533
|
-
const
|
|
534
|
-
if (
|
|
535
|
-
return
|
|
623
|
+
const n = this._s0;
|
|
624
|
+
if (n && n.node === t && n.unsub)
|
|
625
|
+
return n.version = t.version, !0;
|
|
536
626
|
}
|
|
537
627
|
case 1:
|
|
538
628
|
if (e > 1) {
|
|
539
|
-
const
|
|
540
|
-
if (
|
|
541
|
-
return
|
|
629
|
+
const n = this._s1;
|
|
630
|
+
if (n && n.node === t && n.unsub)
|
|
631
|
+
return n.version = t.version, s !== 1 && (this._s1 = this._s0, this._s0 = n), !0;
|
|
542
632
|
}
|
|
543
633
|
case 2:
|
|
544
634
|
if (e > 2) {
|
|
545
|
-
const
|
|
546
|
-
if (
|
|
547
|
-
if (
|
|
548
|
-
const
|
|
549
|
-
s === 0 ? this._s0 =
|
|
635
|
+
const n = this._s2;
|
|
636
|
+
if (n && n.node === t && n.unsub) {
|
|
637
|
+
if (n.version = t.version, s !== 2) {
|
|
638
|
+
const o = s === 0 ? this._s0 : this._s1;
|
|
639
|
+
s === 0 ? this._s0 = n : this._s1 = n, this._s2 = o;
|
|
550
640
|
}
|
|
551
641
|
return !0;
|
|
552
642
|
}
|
|
553
643
|
}
|
|
554
644
|
case 3:
|
|
555
645
|
if (e > 3) {
|
|
556
|
-
const
|
|
557
|
-
if (
|
|
558
|
-
if (
|
|
559
|
-
let
|
|
560
|
-
s === 0 ? (
|
|
646
|
+
const n = this._s3;
|
|
647
|
+
if (n && n.node === t && n.unsub) {
|
|
648
|
+
if (n.version = t.version, s !== 3) {
|
|
649
|
+
let o;
|
|
650
|
+
s === 0 ? (o = this._s0, this._s0 = n) : s === 1 ? (o = this._s1, this._s1 = n) : (o = this._s2, this._s2 = n), this._s3 = o;
|
|
561
651
|
}
|
|
562
652
|
return !0;
|
|
563
653
|
}
|
|
564
654
|
}
|
|
565
655
|
}
|
|
566
|
-
const
|
|
567
|
-
if (
|
|
568
|
-
const
|
|
569
|
-
|
|
570
|
-
|
|
656
|
+
const r = this._overflow;
|
|
657
|
+
if (r) {
|
|
658
|
+
const n = t.version, o = s > 4 ? s : 4, u = r.length;
|
|
659
|
+
for (let h = o - 4; h < u; h++) {
|
|
660
|
+
const l = r[h];
|
|
661
|
+
if (l && l.node === t && l.unsub)
|
|
662
|
+
return l.version = n, this._swapGeneral(h + 4, s, l), !0;
|
|
663
|
+
}
|
|
571
664
|
}
|
|
572
665
|
return !1;
|
|
573
666
|
}
|
|
574
667
|
_claimViaMap(t, s) {
|
|
575
|
-
|
|
576
|
-
|
|
668
|
+
let e = this._map;
|
|
669
|
+
if (e === null) {
|
|
670
|
+
e = this._map = /* @__PURE__ */ new Map();
|
|
577
671
|
const n = this._count;
|
|
578
|
-
s < 4
|
|
672
|
+
if (s < 4) {
|
|
673
|
+
const u = this._s0;
|
|
674
|
+
s <= 0 && u?.unsub && e.set(u.node, 0);
|
|
675
|
+
const h = this._s1;
|
|
676
|
+
s <= 1 && h?.unsub && e.set(h.node, 1);
|
|
677
|
+
const l = this._s2;
|
|
678
|
+
s <= 2 && l?.unsub && e.set(l.node, 2);
|
|
679
|
+
const f = this._s3;
|
|
680
|
+
s <= 3 && f?.unsub && e.set(f.node, 3);
|
|
681
|
+
}
|
|
579
682
|
const o = this._overflow;
|
|
580
683
|
if (o && n > 4) {
|
|
581
|
-
const
|
|
582
|
-
for (let
|
|
583
|
-
const
|
|
584
|
-
|
|
684
|
+
const u = s > 4 ? s : 4, h = o.length;
|
|
685
|
+
for (let l = u - 4; l < h; l++) {
|
|
686
|
+
const f = o[l];
|
|
687
|
+
f?.unsub && e.set(f.node, l + 4);
|
|
585
688
|
}
|
|
586
689
|
}
|
|
587
690
|
}
|
|
588
|
-
const
|
|
589
|
-
if (
|
|
590
|
-
const
|
|
591
|
-
if (
|
|
592
|
-
if (
|
|
593
|
-
|
|
594
|
-
this.setAt(s,
|
|
691
|
+
const i = e.get(t);
|
|
692
|
+
if (i === void 0 || i < s) return !1;
|
|
693
|
+
const r = this.getAt(i);
|
|
694
|
+
if (r == null || !r.unsub) return !1;
|
|
695
|
+
if (r.version = t.version, i !== s) {
|
|
696
|
+
let n;
|
|
697
|
+
s === 0 ? n = this._s0 : s === 1 ? n = this._s1 : s === 2 ? n = this._s2 : s === 3 ? n = this._s3 : n = this._overflow[s - 4] ?? null, this.setAt(s, r), this.setAt(i, n), n?.unsub && e.set(n.node, i), e.set(t, s);
|
|
595
698
|
}
|
|
596
699
|
return !0;
|
|
597
700
|
}
|
|
598
701
|
_swapGeneral(t, s, e) {
|
|
599
702
|
if (t === s) return;
|
|
600
|
-
|
|
601
|
-
if (this.setAt(s, e), t === 0) this._s0 = i;
|
|
703
|
+
let i;
|
|
704
|
+
if (s === 0 ? i = this._s0 : s === 1 ? i = this._s1 : s === 2 ? i = this._s2 : s === 3 ? i = this._s3 : i = this._overflow[s - 4] ?? null, this.setAt(s, e), t === 0) this._s0 = i;
|
|
602
705
|
else if (t === 1) this._s1 = i;
|
|
603
706
|
else if (t === 2) this._s2 = i;
|
|
604
707
|
else if (t === 3) this._s3 = i;
|
|
605
708
|
else {
|
|
606
|
-
const
|
|
607
|
-
|
|
709
|
+
const r = this._overflow;
|
|
710
|
+
r[t - 4] = i;
|
|
608
711
|
}
|
|
609
712
|
}
|
|
610
713
|
insertNew(t, s) {
|
|
611
714
|
const e = this._count;
|
|
612
715
|
if (t < e) {
|
|
613
|
-
|
|
614
|
-
i != null && (this._addToOverflow(i), this._map !== null && i.unsub && this._map.set(i.node, this._count - 1));
|
|
716
|
+
let i;
|
|
717
|
+
t === 0 ? i = this._s0 : t === 1 ? i = this._s1 : t === 2 ? i = this._s2 : t === 3 ? i = this._s3 : i = this._overflow[t - 4] ?? null, i != null && (this._addToOverflow(i), this._map !== null && i.unsub && this._map.set(i.node, this._count - 1));
|
|
615
718
|
}
|
|
616
719
|
if (t === 0) this._s0 = s;
|
|
617
720
|
else if (t === 1) this._s1 = s;
|
|
@@ -627,70 +730,47 @@ var z = class extends et {
|
|
|
627
730
|
t >= this._count || (super.truncateFrom(t), this._map !== null && (this._map.clear(), this._map = null));
|
|
628
731
|
}
|
|
629
732
|
seal() {
|
|
630
|
-
|
|
631
|
-
if (t === 0) {
|
|
632
|
-
this._depsHash = 0;
|
|
633
|
-
return;
|
|
634
|
-
}
|
|
635
|
-
const s = j.VERSION_BITS;
|
|
636
|
-
let e = 0;
|
|
637
|
-
if (t >= 1) {
|
|
638
|
-
const i = this._s0;
|
|
639
|
-
e = e + (i.version << s) + i.node.id | 0;
|
|
640
|
-
}
|
|
641
|
-
if (t >= 2) {
|
|
642
|
-
const i = this._s1;
|
|
643
|
-
e = e + (i.version << s) + i.node.id | 0;
|
|
644
|
-
}
|
|
645
|
-
if (t >= 3) {
|
|
646
|
-
const i = this._s2;
|
|
647
|
-
e = e + (i.version << s) + i.node.id | 0;
|
|
648
|
-
}
|
|
649
|
-
if (t >= 4) {
|
|
650
|
-
const i = this._s3;
|
|
651
|
-
e = e + (i.version << s) + i.node.id | 0;
|
|
652
|
-
}
|
|
653
|
-
if (t > 4) {
|
|
654
|
-
const i = this._overflow;
|
|
655
|
-
for (let n = 0, o = i.length; n < o; n++) {
|
|
656
|
-
const r = i[n];
|
|
657
|
-
e = e + (r.version << s) + r.node.id | 0;
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
this._depsHash = e;
|
|
733
|
+
this._depsHash = this._calculateHash(!1);
|
|
661
734
|
}
|
|
662
735
|
isDirtyFast() {
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
if (
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
if (
|
|
672
|
-
const
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
736
|
+
return this._calculateHash(!0) !== this._depsHash;
|
|
737
|
+
}
|
|
738
|
+
_calculateHash(t) {
|
|
739
|
+
const s = this._count;
|
|
740
|
+
if (s === 0) return 0;
|
|
741
|
+
const e = _t.VERSION_BITS;
|
|
742
|
+
let i = 0;
|
|
743
|
+
const r = this._s0;
|
|
744
|
+
if (r != null) {
|
|
745
|
+
const n = r.node, o = t ? n.version : r.version;
|
|
746
|
+
i = i + (o << e) + n.id | 0;
|
|
747
|
+
const u = this._s1;
|
|
748
|
+
if (s > 1 && u != null) {
|
|
749
|
+
const h = u.node, l = t ? h.version : u.version;
|
|
750
|
+
i = i + (l << e) + h.id | 0;
|
|
751
|
+
const f = this._s2;
|
|
752
|
+
if (s > 2 && f != null) {
|
|
753
|
+
const $ = f.node, lt = t ? $.version : f.version;
|
|
754
|
+
i = i + (lt << e) + $.id | 0;
|
|
755
|
+
const U = this._s3;
|
|
756
|
+
if (s > 3 && U != null) {
|
|
757
|
+
const q = U.node, ct = t ? q.version : U.version;
|
|
758
|
+
i = i + (ct << e) + q.id | 0;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
}
|
|
682
762
|
}
|
|
683
|
-
if (
|
|
684
|
-
const
|
|
685
|
-
for (let
|
|
686
|
-
const
|
|
687
|
-
|
|
763
|
+
if (s > 4) {
|
|
764
|
+
const n = this._overflow;
|
|
765
|
+
for (let o = 0, u = n.length; o < u; o++) {
|
|
766
|
+
const h = n[o], l = h.node, f = t ? l.version : h.version;
|
|
767
|
+
i = i + (f << e) + l.id | 0;
|
|
688
768
|
}
|
|
689
769
|
}
|
|
690
|
-
return
|
|
770
|
+
return i;
|
|
691
771
|
}
|
|
692
772
|
disposeAll() {
|
|
693
|
-
this._count > 0 && this.truncateFrom(0), this.hasComputeds = !1
|
|
773
|
+
this._count > 0 && this.truncateFrom(0), this.hasComputeds = !1;
|
|
694
774
|
}
|
|
695
775
|
remove(t) {
|
|
696
776
|
throw new Error("remove() is strictly prohibited in DepSlotBuffer to preserve sequential cache paths.");
|
|
@@ -698,47 +778,63 @@ var z = class extends et {
|
|
|
698
778
|
compact() {
|
|
699
779
|
}
|
|
700
780
|
};
|
|
701
|
-
function
|
|
702
|
-
return
|
|
781
|
+
function At(t) {
|
|
782
|
+
return typeof t == "object" && t !== null && V in t;
|
|
703
783
|
}
|
|
704
|
-
function
|
|
705
|
-
return
|
|
784
|
+
function Ot(t) {
|
|
785
|
+
return typeof t == "object" && t !== null && rt in t;
|
|
706
786
|
}
|
|
707
|
-
function
|
|
708
|
-
return
|
|
787
|
+
function bt(t) {
|
|
788
|
+
return typeof t == "object" && t !== null && ot in t;
|
|
709
789
|
}
|
|
710
790
|
function ht(t) {
|
|
711
|
-
return
|
|
791
|
+
return typeof t == "object" && t !== null && typeof t.then == "function";
|
|
712
792
|
}
|
|
713
|
-
var { IDLE:
|
|
793
|
+
var { IDLE: p, DIRTY: E, PENDING: g, RESOLVED: d, REJECTED: D, HAS_ERROR: O, RECOMPUTING: y, DISPOSED: x, IS_COMPUTED: b, FORCE_COMPUTE: B } = H, gt = class extends Q {
|
|
714
794
|
constructor(t, s = {}) {
|
|
715
|
-
if (typeof t != "function") throw new
|
|
716
|
-
if (super(), this[
|
|
795
|
+
if (typeof t != "function") throw new S(c.COMPUTED_MUST_BE_FUNCTION);
|
|
796
|
+
if (super(), this[V] = !0, this[rt] = !0, this._error = null, this._promiseId = 0, this._deps = new ut(), this._asyncRetryCount = 0, this._lastDriftEpoch = T.UNINITIALIZED, this._trackEpoch = T.UNINITIALIZED, this._trackCount = 0, this._value = void 0, this.flags = b | E | p, this._equal = s.equal ?? Object.is, this._fn = t, this._defaultValue = "defaultValue" in s ? s.defaultValue : P, this._onError = s.onError ?? null, this._maxAsyncRetries = (s.maxAsyncRetries ?? j.MAX_ASYNC_RETRIES) & w, G.attachDebugInfo(this, "computed", this.id), s.lazy === !1) try {
|
|
717
797
|
this._recompute();
|
|
718
798
|
} catch {
|
|
719
799
|
}
|
|
720
800
|
}
|
|
801
|
+
get isDirty() {
|
|
802
|
+
return (this.flags & E) !== 0;
|
|
803
|
+
}
|
|
804
|
+
get isRejected() {
|
|
805
|
+
return (this.flags & D) !== 0;
|
|
806
|
+
}
|
|
807
|
+
get isRecomputing() {
|
|
808
|
+
return (this.flags & y) !== 0;
|
|
809
|
+
}
|
|
810
|
+
get _hasErrorInternal() {
|
|
811
|
+
return (this.flags & O) !== 0;
|
|
812
|
+
}
|
|
721
813
|
_track() {
|
|
722
814
|
_.current?.addDependency(this);
|
|
723
815
|
}
|
|
724
816
|
get value() {
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
if (
|
|
729
|
-
if (
|
|
730
|
-
|
|
731
|
-
|
|
817
|
+
const t = _.current;
|
|
818
|
+
t?.addDependency(this);
|
|
819
|
+
let s = this.flags;
|
|
820
|
+
if ((s & (d | E | p)) === d) return this._value;
|
|
821
|
+
if ((s & x) !== 0) throw new S(c.COMPUTED_DISPOSED);
|
|
822
|
+
if ((s & y) !== 0) {
|
|
823
|
+
const r = this._defaultValue;
|
|
824
|
+
if (r !== P) return r;
|
|
825
|
+
throw new S(c.COMPUTED_CIRCULAR_DEPENDENCY);
|
|
826
|
+
}
|
|
827
|
+
if ((s & (E | p)) !== 0) {
|
|
828
|
+
const r = this._deps;
|
|
829
|
+
if ((s & p) === 0 && (s & B) === 0 && r.size > 0 && !this._isDirty() ? s = this.flags &= ~E : (this._recompute(), s = this.flags), (s & d) !== 0) return this._value;
|
|
732
830
|
}
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
if (e) return s;
|
|
738
|
-
throw new v(h.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
|
|
831
|
+
const e = this._defaultValue, i = e !== P;
|
|
832
|
+
if ((s & g) !== 0) {
|
|
833
|
+
if (i) return e;
|
|
834
|
+
throw new S(c.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
|
|
739
835
|
}
|
|
740
|
-
if (
|
|
741
|
-
if (
|
|
836
|
+
if ((s & D) !== 0) {
|
|
837
|
+
if (i) return e;
|
|
742
838
|
throw this._error;
|
|
743
839
|
}
|
|
744
840
|
return this._value;
|
|
@@ -747,78 +843,83 @@ var { IDLE: d, DIRTY: f, PENDING: S, RESOLVED: E, REJECTED: C, HAS_ERROR: m, REC
|
|
|
747
843
|
return this._value;
|
|
748
844
|
}
|
|
749
845
|
get state() {
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
846
|
+
const t = _.current;
|
|
847
|
+
t?.addDependency(this);
|
|
848
|
+
const s = this.flags;
|
|
849
|
+
return (s & d) !== 0 ? A.RESOLVED : (s & g) !== 0 ? A.PENDING : (s & D) !== 0 ? A.REJECTED : A.IDLE;
|
|
753
850
|
}
|
|
754
851
|
get hasError() {
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
if (i != null && i.node.flags & m) return !0;
|
|
762
|
-
}
|
|
852
|
+
const t = _.current;
|
|
853
|
+
if (t?.addDependency(this), (this.flags & (D | O)) !== 0) return !0;
|
|
854
|
+
const s = this._deps;
|
|
855
|
+
if (!s.hasComputeds) return !1;
|
|
856
|
+
const e = s.size;
|
|
857
|
+
for (let i = 0; i < e; i++) if (s.getAt(i)?.node.hasError) return !0;
|
|
763
858
|
return !1;
|
|
764
859
|
}
|
|
765
860
|
get isValid() {
|
|
766
861
|
return !this.hasError;
|
|
767
862
|
}
|
|
768
863
|
get errors() {
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
this._error
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
const
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
const o = n
|
|
779
|
-
|
|
864
|
+
const t = _.current;
|
|
865
|
+
t?.addDependency(this);
|
|
866
|
+
const s = this._error, e = this._deps;
|
|
867
|
+
if (!e.hasComputeds)
|
|
868
|
+
return s == null ? W : Object.freeze([s]);
|
|
869
|
+
const i = [];
|
|
870
|
+
s != null && i.push(s);
|
|
871
|
+
const r = e.size;
|
|
872
|
+
for (let n = 0; n < r; n++) {
|
|
873
|
+
const o = e.getAt(n);
|
|
874
|
+
if (o == null) continue;
|
|
875
|
+
const u = o.node;
|
|
876
|
+
(u.flags & b) !== 0 && u.hasError && this._collectErrorsFromDep(u, i);
|
|
780
877
|
}
|
|
781
|
-
return
|
|
878
|
+
return i.length === 0 ? W : Object.freeze(i);
|
|
782
879
|
}
|
|
783
880
|
_collectErrorsFromDep(t, s) {
|
|
784
881
|
const e = t.errors, i = e.length;
|
|
785
|
-
for (let
|
|
786
|
-
const
|
|
787
|
-
|
|
882
|
+
for (let r = 0; r < i; r++) {
|
|
883
|
+
const n = e[r];
|
|
884
|
+
n != null && !s.includes(n) && s.push(n);
|
|
788
885
|
}
|
|
789
886
|
}
|
|
790
887
|
get lastError() {
|
|
791
|
-
|
|
888
|
+
const t = _.current;
|
|
889
|
+
return t?.addDependency(this), this._error;
|
|
792
890
|
}
|
|
793
891
|
get isPending() {
|
|
794
|
-
|
|
892
|
+
const t = _.current;
|
|
893
|
+
return t?.addDependency(this), (this.flags & g) !== 0;
|
|
795
894
|
}
|
|
796
895
|
get isResolved() {
|
|
797
|
-
|
|
896
|
+
const t = _.current;
|
|
897
|
+
return t?.addDependency(this), (this.flags & d) !== 0;
|
|
798
898
|
}
|
|
799
899
|
invalidate() {
|
|
800
|
-
this.flags |=
|
|
900
|
+
this.flags |= B, this._markDirty();
|
|
801
901
|
}
|
|
802
902
|
dispose() {
|
|
803
|
-
this.flags &
|
|
903
|
+
(this.flags & x) === 0 && (this._deps.disposeAll(), this._slots != null && this._slots.clear(), this.flags = x | E | p, this._error = null, this._value = void 0, this._hotIndex = -1);
|
|
804
904
|
}
|
|
805
905
|
[Symbol.dispose]() {
|
|
806
906
|
this.dispose();
|
|
807
907
|
}
|
|
808
908
|
addDependency(t) {
|
|
809
|
-
|
|
810
|
-
t._lastSeenEpoch
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
909
|
+
const s = this._trackEpoch;
|
|
910
|
+
if (t._lastSeenEpoch === s) return;
|
|
911
|
+
t._lastSeenEpoch = s;
|
|
912
|
+
const e = this._trackCount++, i = this._deps, r = i.getAt(e);
|
|
913
|
+
if (r != null && r.node === t) r.version = t.version;
|
|
914
|
+
else if (!i.claimExisting(t, e)) {
|
|
915
|
+
const n = new z(t, t.version, t.subscribe(this));
|
|
916
|
+
i.insertNew(e, n);
|
|
816
917
|
}
|
|
817
|
-
t.flags &
|
|
918
|
+
(t.flags & b) !== 0 && (i.hasComputeds = !0);
|
|
818
919
|
}
|
|
819
920
|
_recompute() {
|
|
820
|
-
if (this.
|
|
821
|
-
this.flags = (this.flags |
|
|
921
|
+
if (this.isRecomputing) return;
|
|
922
|
+
this.flags = (this.flags | y) & ~B, this._trackEpoch = Y(), this._trackCount = 0, this._deps.prepareTracking(), this._hotIndex = -1;
|
|
822
923
|
let t = !1;
|
|
823
924
|
try {
|
|
824
925
|
const s = _.run(this, this._fn);
|
|
@@ -828,42 +929,44 @@ var { IDLE: d, DIRTY: f, PENDING: S, RESOLVED: E, REJECTED: C, HAS_ERROR: m, REC
|
|
|
828
929
|
this._deps.truncateFrom(this._trackCount);
|
|
829
930
|
} catch {
|
|
830
931
|
}
|
|
831
|
-
this._handleError(s,
|
|
932
|
+
this._handleError(s, c.COMPUTED_COMPUTATION_FAILED, !0);
|
|
832
933
|
} finally {
|
|
833
|
-
this._trackEpoch =
|
|
934
|
+
this._trackEpoch = T.UNINITIALIZED, this._trackCount = 0, this.flags &= ~y;
|
|
834
935
|
}
|
|
835
936
|
}
|
|
836
937
|
_handleAsyncComputation(t) {
|
|
837
|
-
this.flags = (this.flags |
|
|
938
|
+
this.flags = (this.flags | g) & ~(p | E | d | D), this._notifySubscribers(void 0, void 0), this._asyncRetryCount = 0, this._promiseId = (this._promiseId + 1) % j.MAX_PROMISE_ID;
|
|
838
939
|
const s = this._promiseId;
|
|
839
940
|
t.then((e) => {
|
|
840
941
|
if (s === this._promiseId) {
|
|
841
942
|
if (this._isDirty()) {
|
|
842
943
|
const i = nt();
|
|
843
|
-
return this._lastDriftEpoch !== i && (this._lastDriftEpoch = i, this._asyncRetryCount = 0), this._asyncRetryCount++ < this._maxAsyncRetries ? this._markDirty() : this._handleError(new
|
|
944
|
+
return this._lastDriftEpoch !== i && (this._lastDriftEpoch = i, this._asyncRetryCount = 0), this._asyncRetryCount++ < this._maxAsyncRetries ? this._markDirty() : this._handleError(new S(`Async drift threshold exceeded after ${this._maxAsyncRetries} retries.`), c.COMPUTED_ASYNC_COMPUTATION_FAILED);
|
|
844
945
|
}
|
|
845
946
|
this._finalizeResolution(e), this._notifySubscribers(e, void 0);
|
|
846
947
|
}
|
|
847
|
-
}, (e) => s === this._promiseId && this._handleError(e,
|
|
948
|
+
}, (e) => s === this._promiseId && this._handleError(e, c.COMPUTED_ASYNC_COMPUTATION_FAILED));
|
|
848
949
|
}
|
|
849
950
|
_handleError(t, s, e = !1) {
|
|
850
|
-
const i =
|
|
851
|
-
if (!e && !
|
|
951
|
+
const i = m(t, S, s);
|
|
952
|
+
if (!e && !this.isRejected && (this.version = X(this.version)), this._error = i, this.flags = this.flags & ~(p | E | g | d) | D | O, this._onError) try {
|
|
852
953
|
this._onError(i);
|
|
853
|
-
} catch (
|
|
854
|
-
console.error(
|
|
954
|
+
} catch (r) {
|
|
955
|
+
console.error(c.CALLBACK_ERROR_IN_ERROR_HANDLER, r);
|
|
855
956
|
}
|
|
856
957
|
if (e) throw i;
|
|
857
958
|
this._notifySubscribers(void 0, void 0);
|
|
858
959
|
}
|
|
859
960
|
_finalizeResolution(t) {
|
|
860
|
-
|
|
961
|
+
const s = this.flags;
|
|
962
|
+
((s & d) === 0 || !this._equal(this._value, t)) && (this.version = X(this.version)), this._value = t, this._error = null, this.flags = (s | d) & ~(p | E | g | D | O);
|
|
861
963
|
}
|
|
862
964
|
execute() {
|
|
863
965
|
this._markDirty();
|
|
864
966
|
}
|
|
865
967
|
_markDirty() {
|
|
866
|
-
|
|
968
|
+
const t = this.flags;
|
|
969
|
+
(t & (y | E)) === 0 && (this.flags = t | E, this._notifySubscribers(void 0, void 0));
|
|
867
970
|
}
|
|
868
971
|
_isDirty() {
|
|
869
972
|
const t = this._deps;
|
|
@@ -875,14 +978,14 @@ var { IDLE: d, DIRTY: f, PENDING: S, RESOLVED: E, REJECTED: C, HAS_ERROR: m, REC
|
|
|
875
978
|
try {
|
|
876
979
|
const e = t.size;
|
|
877
980
|
for (let i = 0; i < e; i++) {
|
|
878
|
-
const
|
|
879
|
-
if (
|
|
880
|
-
const
|
|
881
|
-
if (
|
|
882
|
-
|
|
981
|
+
const r = t.getAt(i);
|
|
982
|
+
if (r == null) continue;
|
|
983
|
+
const n = r.node;
|
|
984
|
+
if ((n.flags & b) !== 0) try {
|
|
985
|
+
n.value;
|
|
883
986
|
} catch {
|
|
884
987
|
}
|
|
885
|
-
if (
|
|
988
|
+
if (n.version !== r.version)
|
|
886
989
|
return this._hotIndex = i, !0;
|
|
887
990
|
}
|
|
888
991
|
return this._hotIndex = -1, !1;
|
|
@@ -891,64 +994,81 @@ var { IDLE: d, DIRTY: f, PENDING: S, RESOLVED: E, REJECTED: C, HAS_ERROR: m, REC
|
|
|
891
994
|
}
|
|
892
995
|
}
|
|
893
996
|
};
|
|
894
|
-
function
|
|
895
|
-
return new
|
|
997
|
+
function Rt(t, s = {}) {
|
|
998
|
+
return new gt(t, s);
|
|
896
999
|
}
|
|
897
|
-
var
|
|
1000
|
+
var Tt = class extends Q {
|
|
898
1001
|
constructor(t, s = {}) {
|
|
899
|
-
super(), this[ot] = !0, this._cleanup = null, this._deps = new
|
|
1002
|
+
super(), this[ot] = !0, this._cleanup = null, this._deps = new ut(), this._currentEpoch = T.UNINITIALIZED, this._lastFlushEpoch = T.UNINITIALIZED, this._fn = t, this._onError = s.onError ?? null, this._sync = s.sync ?? !1, this._maxExecutions = s.maxExecutionsPerSecond ?? C.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = s.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 = () => F.schedule(this), G.attachDebugInfo(this, "effect", this.id);
|
|
900
1003
|
}
|
|
901
1004
|
run() {
|
|
902
|
-
if (this.
|
|
1005
|
+
if (this.isDisposed) throw new v(c.EFFECT_DISPOSED);
|
|
903
1006
|
this.execute(!0);
|
|
904
1007
|
}
|
|
905
1008
|
dispose() {
|
|
906
|
-
this.
|
|
1009
|
+
this.isDisposed || (this.flags |= I.DISPOSED, this._execCleanup(), this._deps?.disposeAll());
|
|
907
1010
|
}
|
|
908
1011
|
[Symbol.dispose]() {
|
|
909
1012
|
this.dispose();
|
|
910
1013
|
}
|
|
911
1014
|
addDependency(t) {
|
|
912
|
-
if (
|
|
1015
|
+
if ((this.flags & I.EXECUTING) === 0) return;
|
|
913
1016
|
const s = this._currentEpoch;
|
|
914
1017
|
if (t._lastSeenEpoch === s) return;
|
|
915
1018
|
t._lastSeenEpoch = s;
|
|
916
|
-
const e = this._trackCount
|
|
917
|
-
let
|
|
918
|
-
|
|
1019
|
+
const e = this._trackCount++, i = this._deps;
|
|
1020
|
+
let r;
|
|
1021
|
+
switch (e) {
|
|
1022
|
+
case 0:
|
|
1023
|
+
r = i._s0;
|
|
1024
|
+
break;
|
|
1025
|
+
case 1:
|
|
1026
|
+
r = i._s1;
|
|
1027
|
+
break;
|
|
1028
|
+
case 2:
|
|
1029
|
+
r = i._s2;
|
|
1030
|
+
break;
|
|
1031
|
+
case 3:
|
|
1032
|
+
r = i._s3;
|
|
1033
|
+
break;
|
|
1034
|
+
default:
|
|
1035
|
+
r = i.getAt(e);
|
|
1036
|
+
}
|
|
1037
|
+
r != null && r.node === t ? r.version = t.version : i.claimExisting(t, e) || this._insertNewDependency(t, e), t.isComputed && (i.hasComputeds = !0);
|
|
919
1038
|
}
|
|
920
1039
|
_insertNewDependency(t, s) {
|
|
921
1040
|
let e;
|
|
922
1041
|
try {
|
|
923
1042
|
const i = t.subscribe(this._notifyCallback);
|
|
924
|
-
e = new
|
|
1043
|
+
e = new z(t, t.version, i);
|
|
925
1044
|
} catch (i) {
|
|
926
|
-
const
|
|
927
|
-
if (console.error(
|
|
928
|
-
this._onError(
|
|
1045
|
+
const r = m(i, v, c.EFFECT_EXECUTION_FAILED);
|
|
1046
|
+
if (console.error(r), this._onError) try {
|
|
1047
|
+
this._onError(r);
|
|
929
1048
|
} catch {
|
|
930
1049
|
}
|
|
931
|
-
e = new
|
|
1050
|
+
e = new z(t, t.version, void 0);
|
|
932
1051
|
}
|
|
933
1052
|
this._deps.insertNew(s, e);
|
|
934
1053
|
}
|
|
935
1054
|
execute(t = !1) {
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
1055
|
+
const s = this.flags;
|
|
1056
|
+
if ((s & (I.DISPOSED | I.EXECUTING)) !== 0) return;
|
|
1057
|
+
const e = this._deps;
|
|
1058
|
+
if (!t && e.size > 0 && !this._isDirty()) return;
|
|
1059
|
+
this._checkInfiniteLoops(), this.flags = s | I.EXECUTING, this._execCleanup(), this._currentEpoch = Y(), this._trackCount = 0, e.prepareTracking(), this._hotIndex = -1;
|
|
1060
|
+
let i = !1;
|
|
941
1061
|
try {
|
|
942
|
-
const
|
|
943
|
-
|
|
944
|
-
} catch (
|
|
945
|
-
if (!
|
|
946
|
-
|
|
1062
|
+
const r = _.run(this, this._fn);
|
|
1063
|
+
e.truncateFrom(this._trackCount), e.seal(), i = !0, ht(r) ? this._handleAsyncResult(r) : this._cleanup = typeof r == "function" ? r : null;
|
|
1064
|
+
} catch (r) {
|
|
1065
|
+
if (!i) try {
|
|
1066
|
+
e.truncateFrom(this._trackCount);
|
|
947
1067
|
} catch {
|
|
948
1068
|
}
|
|
949
|
-
this._handleExecutionError(
|
|
1069
|
+
this._handleExecutionError(r), this._cleanup = null;
|
|
950
1070
|
} finally {
|
|
951
|
-
this.flags &= ~
|
|
1071
|
+
this.flags &= ~I.EXECUTING;
|
|
952
1072
|
}
|
|
953
1073
|
}
|
|
954
1074
|
_isDirty() {
|
|
@@ -958,11 +1078,11 @@ var It = class extends X {
|
|
|
958
1078
|
_handleAsyncResult(t) {
|
|
959
1079
|
const s = ++this._execId;
|
|
960
1080
|
t.then((e) => {
|
|
961
|
-
if (s !== this._execId || this.
|
|
1081
|
+
if (s !== this._execId || this.isDisposed) {
|
|
962
1082
|
if (typeof e == "function") try {
|
|
963
1083
|
e();
|
|
964
1084
|
} catch (i) {
|
|
965
|
-
this._handleExecutionError(i,
|
|
1085
|
+
this._handleExecutionError(i, c.EFFECT_CLEANUP_FAILED);
|
|
966
1086
|
}
|
|
967
1087
|
return;
|
|
968
1088
|
}
|
|
@@ -976,10 +1096,10 @@ var It = class extends X {
|
|
|
976
1096
|
try {
|
|
977
1097
|
const e = s.size;
|
|
978
1098
|
for (let i = 0; i < e; i++) {
|
|
979
|
-
const
|
|
980
|
-
if (
|
|
981
|
-
const
|
|
982
|
-
if (
|
|
1099
|
+
const r = s.getAt(i);
|
|
1100
|
+
if (r == null) continue;
|
|
1101
|
+
const n = r.node;
|
|
1102
|
+
if (n.isComputed && this._tryPullComputed(n), n.version !== r.version)
|
|
983
1103
|
return this._hotIndex = i, !0;
|
|
984
1104
|
}
|
|
985
1105
|
return !1;
|
|
@@ -994,85 +1114,84 @@ var It = class extends X {
|
|
|
994
1114
|
}
|
|
995
1115
|
}
|
|
996
1116
|
_execCleanup() {
|
|
997
|
-
|
|
1117
|
+
const t = this._cleanup;
|
|
1118
|
+
if (t != null) {
|
|
1119
|
+
this._cleanup = null;
|
|
998
1120
|
try {
|
|
999
|
-
|
|
1000
|
-
} catch (
|
|
1001
|
-
this._handleExecutionError(
|
|
1121
|
+
t();
|
|
1122
|
+
} catch (s) {
|
|
1123
|
+
this._handleExecutionError(s, c.EFFECT_CLEANUP_FAILED);
|
|
1002
1124
|
}
|
|
1003
|
-
this._cleanup = null;
|
|
1004
1125
|
}
|
|
1005
1126
|
}
|
|
1006
1127
|
_checkInfiniteLoops() {
|
|
1007
1128
|
const t = nt();
|
|
1008
|
-
this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"),
|
|
1129
|
+
this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), Ct() > C.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++;
|
|
1009
1130
|
}
|
|
1010
1131
|
_checkFrequencyLimit() {
|
|
1011
1132
|
if (!Number.isFinite(this._maxExecutions)) return;
|
|
1012
1133
|
const t = Date.now();
|
|
1013
|
-
if (t - this._windowStart >=
|
|
1134
|
+
if (t - this._windowStart >= st.EFFECT_FREQUENCY_WINDOW) {
|
|
1014
1135
|
this._windowStart = t, this._windowCount = 1;
|
|
1015
1136
|
return;
|
|
1016
1137
|
}
|
|
1017
1138
|
if (++this._windowCount > this._maxExecutions) {
|
|
1018
|
-
const s = new
|
|
1139
|
+
const s = new v(c.EFFECT_FREQUENCY_LIMIT_EXCEEDED);
|
|
1019
1140
|
throw this.dispose(), this._handleExecutionError(s), s;
|
|
1020
1141
|
}
|
|
1021
1142
|
}
|
|
1022
|
-
get isDisposed() {
|
|
1023
|
-
return (this.flags & c.DISPOSED) !== 0;
|
|
1024
|
-
}
|
|
1025
1143
|
get executionCount() {
|
|
1026
1144
|
return this._executionCount;
|
|
1027
1145
|
}
|
|
1028
1146
|
get isExecuting() {
|
|
1029
|
-
return (this.flags &
|
|
1147
|
+
return (this.flags & I.EXECUTING) !== 0;
|
|
1030
1148
|
}
|
|
1031
1149
|
_throwInfiniteLoopError(t) {
|
|
1032
|
-
const s = new
|
|
1150
|
+
const s = new v(`Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${k}`);
|
|
1033
1151
|
throw this.dispose(), console.error(s), s;
|
|
1034
1152
|
}
|
|
1035
|
-
_handleExecutionError(t, s =
|
|
1036
|
-
const e =
|
|
1153
|
+
_handleExecutionError(t, s = c.EFFECT_EXECUTION_FAILED) {
|
|
1154
|
+
const e = m(t, v, s);
|
|
1037
1155
|
if (console.error(e), this._onError) try {
|
|
1038
1156
|
this._onError(e);
|
|
1039
1157
|
} catch (i) {
|
|
1040
|
-
console.error(
|
|
1158
|
+
console.error(m(i, v, c.CALLBACK_ERROR_IN_ERROR_HANDLER));
|
|
1041
1159
|
}
|
|
1042
1160
|
}
|
|
1043
1161
|
};
|
|
1044
|
-
function
|
|
1045
|
-
if (typeof t != "function") throw new
|
|
1046
|
-
const e = new
|
|
1162
|
+
function Ft(t, s = {}) {
|
|
1163
|
+
if (typeof t != "function") throw new v(c.EFFECT_MUST_BE_FUNCTION);
|
|
1164
|
+
const e = new Tt(t, s);
|
|
1047
1165
|
return e.execute(), e;
|
|
1048
1166
|
}
|
|
1049
|
-
function
|
|
1050
|
-
if (typeof t != "function") throw new TypeError(
|
|
1051
|
-
|
|
1167
|
+
function wt(t) {
|
|
1168
|
+
if (typeof t != "function") throw new TypeError(c.BATCH_CALLBACK_MUST_BE_FUNCTION);
|
|
1169
|
+
const s = F;
|
|
1170
|
+
s.startBatch();
|
|
1052
1171
|
try {
|
|
1053
1172
|
return t();
|
|
1054
1173
|
} finally {
|
|
1055
|
-
|
|
1174
|
+
s.endBatch();
|
|
1056
1175
|
}
|
|
1057
1176
|
}
|
|
1058
1177
|
export {
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1178
|
+
A as AsyncState,
|
|
1179
|
+
N as AtomError,
|
|
1180
|
+
S as ComputedError,
|
|
1181
|
+
st as DEBUG_CONFIG,
|
|
1063
1182
|
G as DEBUG_RUNTIME,
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1183
|
+
v as EffectError,
|
|
1184
|
+
C as SCHEDULER_CONFIG,
|
|
1185
|
+
L as SchedulerError,
|
|
1186
|
+
yt as atom,
|
|
1187
|
+
wt as batch,
|
|
1188
|
+
Rt as computed,
|
|
1189
|
+
Ft as effect,
|
|
1190
|
+
At as isAtom,
|
|
1191
|
+
Ot as isComputed,
|
|
1192
|
+
bt as isEffect,
|
|
1193
|
+
F as scheduler,
|
|
1194
|
+
Nt as untracked
|
|
1076
1195
|
};
|
|
1077
1196
|
|
|
1078
1197
|
//# sourceMappingURL=index.mjs.map
|