@but212/atom-effect 0.24.1 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/atom-effect.min.js +1 -1
- package/dist/atom-effect.min.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +264 -287
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var
|
|
1
|
+
var y = {
|
|
2
2
|
IDLE: "idle",
|
|
3
3
|
PENDING: "pending",
|
|
4
4
|
RESOLVED: "resolved",
|
|
5
5
|
REJECTED: "rejected"
|
|
6
|
-
},
|
|
6
|
+
}, c = {
|
|
7
7
|
DISPOSED: 1,
|
|
8
8
|
EXECUTING: 8
|
|
9
|
-
},
|
|
9
|
+
}, B = {
|
|
10
10
|
DISPOSED: 1,
|
|
11
11
|
IS_COMPUTED: 2,
|
|
12
12
|
DIRTY: 8,
|
|
@@ -17,27 +17,27 @@ var b = {
|
|
|
17
17
|
RECOMPUTING: 256,
|
|
18
18
|
HAS_ERROR: 512,
|
|
19
19
|
FORCE_COMPUTE: 1024
|
|
20
|
-
},
|
|
20
|
+
}, a = {
|
|
21
21
|
DISPOSED: 1,
|
|
22
22
|
SYNC: 8,
|
|
23
23
|
NOTIFICATION_SCHEDULED: 16
|
|
24
|
-
},
|
|
24
|
+
}, I = {
|
|
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
|
+
}, tt = {
|
|
32
32
|
WARN_INFINITE_LOOP: !0,
|
|
33
33
|
EFFECT_FREQUENCY_WINDOW: 1e3
|
|
34
|
-
},
|
|
34
|
+
}, $ = {
|
|
35
35
|
MAX_ASYNC_RETRIES: 3,
|
|
36
36
|
MAX_PROMISE_ID: Number.MAX_SAFE_INTEGER - 1
|
|
37
|
-
},
|
|
37
|
+
}, p = {
|
|
38
38
|
UNINITIALIZED: -1,
|
|
39
39
|
MIN: 1
|
|
40
|
-
},
|
|
40
|
+
}, st = 1073741823, j = { VERSION_BITS: 16 }, Ct = (typeof process < "u" && process.env, !1), q = Object.freeze([]), x = class {
|
|
41
41
|
constructor(t, s, e = void 0) {
|
|
42
42
|
this.node = t, this.version = s, this.unsub = e;
|
|
43
43
|
}
|
|
@@ -48,23 +48,23 @@ var b = {
|
|
|
48
48
|
notify(t, s) {
|
|
49
49
|
this.fn ? this.fn(t, s) : this.sub && this.sub.execute();
|
|
50
50
|
}
|
|
51
|
-
},
|
|
51
|
+
}, T = class extends Error {
|
|
52
52
|
constructor(t, s = null, e = !0) {
|
|
53
53
|
super(t), this.cause = s, this.recoverable = e, this.name = "AtomError";
|
|
54
54
|
}
|
|
55
|
-
},
|
|
55
|
+
}, v = class extends T {
|
|
56
56
|
constructor(t, s = null) {
|
|
57
57
|
super(t, s, !0), this.name = "ComputedError";
|
|
58
58
|
}
|
|
59
|
-
}, D = class extends
|
|
59
|
+
}, D = class extends T {
|
|
60
60
|
constructor(t, s = null) {
|
|
61
61
|
super(t, s, !1), this.name = "EffectError";
|
|
62
62
|
}
|
|
63
|
-
}, R = class extends
|
|
63
|
+
}, R = class extends T {
|
|
64
64
|
constructor(t, s = null) {
|
|
65
65
|
super(t, s, !1), this.name = "SchedulerError";
|
|
66
66
|
}
|
|
67
|
-
},
|
|
67
|
+
}, h = {
|
|
68
68
|
COMPUTED_MUST_BE_FUNCTION: "Computed target must be a function",
|
|
69
69
|
COMPUTED_ASYNC_PENDING_NO_DEFAULT: "Async computation pending with no default value",
|
|
70
70
|
COMPUTED_COMPUTATION_FAILED: "Computation execution failed",
|
|
@@ -85,7 +85,7 @@ var b = {
|
|
|
85
85
|
BATCH_CALLBACK_MUST_BE_FUNCTION: "Batch callback must be a function"
|
|
86
86
|
}, et = class {
|
|
87
87
|
constructor() {
|
|
88
|
-
this._s0 = null, this._s1 = null, this._s2 = null, this._s3 = null, this._count = 0, this.
|
|
88
|
+
this._s0 = null, this._s1 = null, this._s2 = null, this._s3 = null, this._count = 0, this._overflow = null, this._freeIndices = null;
|
|
89
89
|
}
|
|
90
90
|
get size() {
|
|
91
91
|
return this._count;
|
|
@@ -156,13 +156,13 @@ var b = {
|
|
|
156
156
|
const e = this._overflow;
|
|
157
157
|
if (e !== null && s > 4) {
|
|
158
158
|
const i = t > 4 ? t - 4 : 0, n = e.length;
|
|
159
|
-
for (let
|
|
160
|
-
const
|
|
161
|
-
|
|
159
|
+
for (let o = i; o < n; o++) {
|
|
160
|
+
const r = e[o];
|
|
161
|
+
r != null && (this._onItemRemoved(r), e[o] = null);
|
|
162
162
|
}
|
|
163
163
|
t <= 4 ? (e.length = 0, this._overflow = null) : e.length = t - 4;
|
|
164
164
|
}
|
|
165
|
-
this._count = t;
|
|
165
|
+
this._freeIndices !== null && (this._freeIndices = null), this._count = t;
|
|
166
166
|
}
|
|
167
167
|
_onItemRemoved(t) {
|
|
168
168
|
}
|
|
@@ -183,14 +183,13 @@ var b = {
|
|
|
183
183
|
this._s3 = t, this._count++;
|
|
184
184
|
return;
|
|
185
185
|
}
|
|
186
|
+
this._addToOverflow(t);
|
|
187
|
+
}
|
|
188
|
+
_addToOverflow(t) {
|
|
186
189
|
if (this._overflow === null) this._overflow = [t];
|
|
187
190
|
else {
|
|
188
|
-
const s = this.
|
|
189
|
-
|
|
190
|
-
s[e] = t, this._count++;
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
s.push(t);
|
|
191
|
+
const s = this._freeIndices;
|
|
192
|
+
s !== null && s.length > 0 ? this._overflow[s.pop()] = t : this._overflow.push(t);
|
|
194
193
|
}
|
|
195
194
|
this._count++;
|
|
196
195
|
}
|
|
@@ -206,48 +205,32 @@ var b = {
|
|
|
206
205
|
const s = this._overflow;
|
|
207
206
|
if (s == null) return !1;
|
|
208
207
|
for (let e = 0, i = s.length; e < i; e++) if (s[e] === t)
|
|
209
|
-
return s[e] = null, this._count--, !0;
|
|
208
|
+
return s[e] = null, this._count--, this._freeIndices === null && (this._freeIndices = []), this._freeIndices.push(e), !0;
|
|
210
209
|
return !1;
|
|
211
210
|
}
|
|
212
211
|
has(t) {
|
|
213
|
-
|
|
214
|
-
if (s === 0) return !1;
|
|
212
|
+
if (this._count === 0) return !1;
|
|
215
213
|
if (this._s0 === t || this._s1 === t || this._s2 === t || this._s3 === t) return !0;
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
let i = 0;
|
|
220
|
-
this._s0 != null && i++, this._s1 != null && i++, this._s2 != null && i++, this._s3 != null && i++;
|
|
221
|
-
for (let n = 0, r = e.length; n < r; n++) {
|
|
222
|
-
const o = e[n];
|
|
223
|
-
if (o != null) {
|
|
224
|
-
if (o === t) return !0;
|
|
225
|
-
if (++i === s) break;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
214
|
+
const s = this._overflow;
|
|
215
|
+
if (s != null) {
|
|
216
|
+
for (let e = 0, i = s.length; e < i; e++) if (s[e] === t) return !0;
|
|
228
217
|
}
|
|
229
218
|
return !1;
|
|
230
219
|
}
|
|
231
220
|
forEach(t) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
221
|
+
if (this._count === 0) return;
|
|
222
|
+
const s = this._s0;
|
|
223
|
+
s != null && t(s);
|
|
224
|
+
const e = this._s1;
|
|
235
225
|
e != null && t(e);
|
|
236
|
-
const i = this.
|
|
226
|
+
const i = this._s2;
|
|
237
227
|
i != null && t(i);
|
|
238
|
-
const n = this.
|
|
228
|
+
const n = this._s3;
|
|
239
229
|
n != null && t(n);
|
|
240
|
-
const r = this._s3;
|
|
241
|
-
if (r != null && t(r), s <= 4) return;
|
|
242
230
|
const o = this._overflow;
|
|
243
|
-
if (o != null) {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
for (let u = 0, a = o.length; u < a; u++) {
|
|
247
|
-
const c = o[u];
|
|
248
|
-
if (c != null && (t(c), ++h === s))
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
231
|
+
if (o != null) for (let r = 0, u = o.length; r < u; r++) {
|
|
232
|
+
const l = o[r];
|
|
233
|
+
l != null && t(l);
|
|
251
234
|
}
|
|
252
235
|
}
|
|
253
236
|
forEachIndexed(t) {
|
|
@@ -258,15 +241,14 @@ var b = {
|
|
|
258
241
|
i != null && (t(i), e++);
|
|
259
242
|
const n = this._s1;
|
|
260
243
|
n != null && (t(n), e++);
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
const
|
|
264
|
-
if (
|
|
265
|
-
const
|
|
266
|
-
if (
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
break;
|
|
244
|
+
const o = this._s2;
|
|
245
|
+
o != null && (t(o), e++);
|
|
246
|
+
const r = this._s3;
|
|
247
|
+
if (r != null && (t(r), e++), e === s) return e;
|
|
248
|
+
const u = this._overflow;
|
|
249
|
+
if (u != null) for (let l = 0, O = u.length; l < O; l++) {
|
|
250
|
+
const Y = u[l];
|
|
251
|
+
Y != null && (t(Y), e++);
|
|
270
252
|
}
|
|
271
253
|
return e;
|
|
272
254
|
}
|
|
@@ -275,44 +257,44 @@ var b = {
|
|
|
275
257
|
if (t === null || t.length === 0) return;
|
|
276
258
|
let s = 0;
|
|
277
259
|
for (; s < t.length; ) if (t[s] === null) {
|
|
278
|
-
|
|
279
|
-
|
|
260
|
+
for (; t.length > s && t[t.length - 1] === null; ) t.pop();
|
|
261
|
+
t.length > s && (t[s] = t.pop(), s++);
|
|
280
262
|
} else s++;
|
|
281
|
-
t.length === 0 && (this._overflow = null);
|
|
263
|
+
this._freeIndices = null, t.length === 0 && (this._overflow = null);
|
|
282
264
|
}
|
|
283
265
|
clear() {
|
|
284
|
-
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);
|
|
266
|
+
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;
|
|
285
267
|
}
|
|
286
268
|
dispose() {
|
|
287
269
|
this.clear();
|
|
288
270
|
}
|
|
289
|
-
},
|
|
271
|
+
}, W = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), lt = /* @__PURE__ */ Symbol("AtomEffect.Id"), K = /* @__PURE__ */ Symbol("AtomEffect.Type"), b = /* @__PURE__ */ Symbol("AtomEffect.NoDefaultValue"), G = {
|
|
290
272
|
enabled: !1,
|
|
291
|
-
warnInfiniteLoop:
|
|
273
|
+
warnInfiniteLoop: tt.WARN_INFINITE_LOOP,
|
|
292
274
|
warn(t, s) {
|
|
293
275
|
},
|
|
294
276
|
attachDebugInfo(t, s, e) {
|
|
295
277
|
},
|
|
296
|
-
getDebugName: (t) => t?.[
|
|
278
|
+
getDebugName: (t) => t?.[W],
|
|
297
279
|
getDebugType: (t) => t?.[K]
|
|
298
280
|
}, _t = 1, ct = () => _t++;
|
|
299
|
-
function
|
|
300
|
-
if (t instanceof
|
|
301
|
-
const i = t instanceof Error, n = i ? t.message : String(t),
|
|
302
|
-
return new s(`${i ? t.constructor.name : "Unexpected error"} (${e}): ${n}`,
|
|
281
|
+
function g(t, s, e) {
|
|
282
|
+
if (t instanceof T) return t;
|
|
283
|
+
const i = t instanceof Error, n = i ? t.message : String(t), o = i ? t : void 0;
|
|
284
|
+
return new s(`${i ? t.constructor.name : "Unexpected error"} (${e}): ${n}`, o);
|
|
303
285
|
}
|
|
304
|
-
var
|
|
286
|
+
var X = class {
|
|
305
287
|
constructor() {
|
|
306
|
-
this.flags = 0, this.version = 0, this._lastSeenEpoch =
|
|
288
|
+
this.flags = 0, this.version = 0, this._lastSeenEpoch = p.UNINITIALIZED, this._notifying = 0, this._hotIndex = -1, this._slots = null, this._deps = null, this.id = ct() & st;
|
|
307
289
|
}
|
|
308
290
|
subscribe(t) {
|
|
309
291
|
const s = typeof t == "function";
|
|
310
|
-
if (!s && (!t || typeof t.execute != "function")) throw
|
|
292
|
+
if (!s && (!t || typeof t.execute != "function")) throw g(/* @__PURE__ */ new TypeError("Invalid subscriber"), T, h.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
|
|
311
293
|
let e = this._slots;
|
|
312
294
|
e || (e = new et(), this._slots = e);
|
|
313
295
|
let i = !1;
|
|
314
|
-
if (e.forEach((
|
|
315
|
-
(s ?
|
|
296
|
+
if (e.forEach((o) => {
|
|
297
|
+
(s ? o.fn === t : o.sub === t) && (i = !0);
|
|
316
298
|
}), i)
|
|
317
299
|
return () => {
|
|
318
300
|
};
|
|
@@ -340,7 +322,7 @@ var V = class {
|
|
|
340
322
|
try {
|
|
341
323
|
i.notify(t, s);
|
|
342
324
|
} catch (n) {
|
|
343
|
-
console.error(
|
|
325
|
+
console.error(g(n, T, h.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED));
|
|
344
326
|
}
|
|
345
327
|
});
|
|
346
328
|
} finally {
|
|
@@ -357,20 +339,25 @@ var V = class {
|
|
|
357
339
|
}
|
|
358
340
|
return !t.hasComputeds && !t.isDirtyFast() ? !1 : this._deepDirtyCheck();
|
|
359
341
|
}
|
|
360
|
-
},
|
|
361
|
-
function
|
|
362
|
-
return F ? !1 : (F = !0, it =
|
|
342
|
+
}, U = 0, k = () => (U = U + 1 & 1073741823 || 1, U), H = (t) => t + 1 & 1073741823 || 1, V = 0, F = !1, it = 0, nt = () => it;
|
|
343
|
+
function Z() {
|
|
344
|
+
return F ? !1 : (F = !0, it = k(), V = 0, !0);
|
|
363
345
|
}
|
|
364
|
-
var
|
|
346
|
+
var J = () => {
|
|
365
347
|
F = !1;
|
|
366
|
-
}, ft = () =>
|
|
348
|
+
}, ft = () => {
|
|
349
|
+
if (!F) return 0;
|
|
350
|
+
const t = ++V;
|
|
351
|
+
if (t > I.MAX_EXECUTIONS_PER_FLUSH) throw new Error(`[atom-effect] Infinite loop detected: flush execution count exceeded ${I.MAX_EXECUTIONS_PER_FLUSH}`);
|
|
352
|
+
return t;
|
|
353
|
+
}, w = /* @__PURE__ */ (function(t) {
|
|
367
354
|
return t[t.IDLE = 0] = "IDLE", t[t.BATCHING = 1] = "BATCHING", t[t.FLUSHING = 2] = "FLUSHING", t;
|
|
368
355
|
})({}), at = class {
|
|
369
356
|
constructor() {
|
|
370
|
-
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 =
|
|
357
|
+
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 = I.MAX_FLUSH_ITERATIONS, this.onOverflow = null, this._boundRunLoop = this._runLoop.bind(this);
|
|
371
358
|
}
|
|
372
359
|
get phase() {
|
|
373
|
-
return this._isProcessing || this._isFlushingSync ?
|
|
360
|
+
return this._isProcessing || this._isFlushingSync ? w.FLUSHING : this._isBatching ? w.BATCHING : w.IDLE;
|
|
374
361
|
}
|
|
375
362
|
get queueSize() {
|
|
376
363
|
return this._size;
|
|
@@ -393,19 +380,19 @@ var tt = () => {
|
|
|
393
380
|
_runLoop() {
|
|
394
381
|
try {
|
|
395
382
|
if (this._size === 0) return;
|
|
396
|
-
const t =
|
|
397
|
-
this._drainQueue(), t &&
|
|
383
|
+
const t = Z();
|
|
384
|
+
this._drainQueue(), t && J();
|
|
398
385
|
} finally {
|
|
399
386
|
this._isProcessing = !1, this._size > 0 && !this._isBatching && this._flush();
|
|
400
387
|
}
|
|
401
388
|
}
|
|
402
389
|
_flushSync() {
|
|
403
390
|
this._isFlushingSync = !0;
|
|
404
|
-
const t =
|
|
391
|
+
const t = Z();
|
|
405
392
|
try {
|
|
406
393
|
this._mergeBatchQueue(), this._drainQueue();
|
|
407
394
|
} finally {
|
|
408
|
-
this._isFlushingSync = !1, t &&
|
|
395
|
+
this._isFlushingSync = !1, t && J();
|
|
409
396
|
}
|
|
410
397
|
}
|
|
411
398
|
_mergeBatchQueue() {
|
|
@@ -413,8 +400,8 @@ var tt = () => {
|
|
|
413
400
|
const t = ++this._epoch, s = this._batchQueue, e = this._queueBuffer[this._bufferIndex];
|
|
414
401
|
let i = this._size;
|
|
415
402
|
for (let n = 0; n < this._batchQueueSize; n++) {
|
|
416
|
-
const
|
|
417
|
-
|
|
403
|
+
const o = s[n];
|
|
404
|
+
o._nextEpoch !== t && (o._nextEpoch = t, e[i++] = o);
|
|
418
405
|
}
|
|
419
406
|
this._size = i, this._batchQueueSize = 0, s.length = 0;
|
|
420
407
|
}
|
|
@@ -441,7 +428,7 @@ var tt = () => {
|
|
|
441
428
|
}
|
|
442
429
|
_handleFlushOverflow() {
|
|
443
430
|
const t = this._size + this._batchQueueSize;
|
|
444
|
-
if (console.error(new R(
|
|
431
|
+
if (console.error(new R(h.SCHEDULER_FLUSH_OVERFLOW(this._maxFlushIterations, t))), this._size = 0, this._queueBuffer[this._bufferIndex].length = 0, this._batchQueueSize = 0, this.onOverflow) try {
|
|
445
432
|
this.onOverflow(t);
|
|
446
433
|
} catch {
|
|
447
434
|
}
|
|
@@ -453,10 +440,10 @@ var tt = () => {
|
|
|
453
440
|
this._batchDepth !== 0 && --this._batchDepth === 0 && (this._flushSync(), this._isBatching = !1);
|
|
454
441
|
}
|
|
455
442
|
setMaxFlushIterations(t) {
|
|
456
|
-
if (t <
|
|
443
|
+
if (t < I.MIN_FLUSH_ITERATIONS) throw new R(`Max flush iterations must be at least ${I.MIN_FLUSH_ITERATIONS}`);
|
|
457
444
|
this._maxFlushIterations = t;
|
|
458
445
|
}
|
|
459
|
-
},
|
|
446
|
+
}, A = new at(), Q = /* @__PURE__ */ Symbol.for("atom-effect/atom"), rt = /* @__PURE__ */ Symbol.for("atom-effect/computed"), ot = /* @__PURE__ */ Symbol.for("atom-effect/effect"), Et = /* @__PURE__ */ Symbol.for("atom-effect/writable"), _ = {
|
|
460
447
|
current: null,
|
|
461
448
|
run(t, s) {
|
|
462
449
|
const e = this.current;
|
|
@@ -468,7 +455,7 @@ var tt = () => {
|
|
|
468
455
|
}
|
|
469
456
|
}
|
|
470
457
|
};
|
|
471
|
-
function
|
|
458
|
+
function Dt(t) {
|
|
472
459
|
const s = _.current;
|
|
473
460
|
if (s === null) return t();
|
|
474
461
|
_.current = null;
|
|
@@ -478,9 +465,9 @@ function vt(t) {
|
|
|
478
465
|
_.current = s;
|
|
479
466
|
}
|
|
480
467
|
}
|
|
481
|
-
var dt = class extends
|
|
468
|
+
var dt = class extends X {
|
|
482
469
|
constructor(t, s) {
|
|
483
|
-
super(), this[
|
|
470
|
+
super(), this[Q] = !0, this[Et] = !0, this._value = t, this._pendingOldValue = void 0, s && (this.flags |= a.SYNC), G.attachDebugInfo(this, "atom", this.id);
|
|
484
471
|
}
|
|
485
472
|
get value() {
|
|
486
473
|
const t = _.current;
|
|
@@ -489,31 +476,31 @@ var dt = class extends V {
|
|
|
489
476
|
set value(t) {
|
|
490
477
|
const s = this._value;
|
|
491
478
|
if (Object.is(s, t)) return;
|
|
492
|
-
this._value = t, this.version =
|
|
479
|
+
this._value = t, this.version = H(this.version);
|
|
493
480
|
const e = this._slots, i = this.flags;
|
|
494
|
-
if (e == null || e.size === 0 || i &
|
|
481
|
+
if (e == null || e.size === 0 || i & a.NOTIFICATION_SCHEDULED) return;
|
|
495
482
|
this._pendingOldValue = s;
|
|
496
|
-
const n = i |
|
|
497
|
-
if (this.flags = n, (n &
|
|
483
|
+
const n = i | a.NOTIFICATION_SCHEDULED;
|
|
484
|
+
if (this.flags = n, (n & a.SYNC) !== 0 && !A.isBatching) {
|
|
498
485
|
this._flushNotifications();
|
|
499
486
|
return;
|
|
500
487
|
}
|
|
501
|
-
|
|
488
|
+
A.schedule(this);
|
|
502
489
|
}
|
|
503
490
|
execute() {
|
|
504
491
|
this._flushNotifications();
|
|
505
492
|
}
|
|
506
493
|
_flushNotifications() {
|
|
507
494
|
const t = this.flags;
|
|
508
|
-
if (!(t &
|
|
495
|
+
if (!(t & a.NOTIFICATION_SCHEDULED) || t & a.DISPOSED) return;
|
|
509
496
|
const s = this._pendingOldValue;
|
|
510
|
-
this._pendingOldValue = void 0, this.flags &= ~
|
|
497
|
+
this._pendingOldValue = void 0, this.flags &= ~a.NOTIFICATION_SCHEDULED, this._notifySubscribers(this._value, s);
|
|
511
498
|
}
|
|
512
499
|
peek() {
|
|
513
500
|
return this._value;
|
|
514
501
|
}
|
|
515
502
|
dispose() {
|
|
516
|
-
this.flags &
|
|
503
|
+
this.flags & a.DISPOSED || (this._slots?.clear(), this.flags |= a.DISPOSED, this._value = void 0, this._pendingOldValue = void 0);
|
|
517
504
|
}
|
|
518
505
|
_deepDirtyCheck() {
|
|
519
506
|
return !1;
|
|
@@ -522,10 +509,10 @@ var dt = class extends V {
|
|
|
522
509
|
this.dispose();
|
|
523
510
|
}
|
|
524
511
|
};
|
|
525
|
-
function
|
|
512
|
+
function vt(t, s = {}) {
|
|
526
513
|
return new dt(t, s.sync ?? !1);
|
|
527
514
|
}
|
|
528
|
-
var
|
|
515
|
+
var z = class extends et {
|
|
529
516
|
constructor() {
|
|
530
517
|
super(), this._map = null, this._SCAN_THRESHOLD = 32, this.hasComputeds = !1, this._depsHash = 0, this._map = null, this.hasComputeds = !1, this._depsHash = 0;
|
|
531
518
|
}
|
|
@@ -543,44 +530,44 @@ var k = class extends et {
|
|
|
543
530
|
if (this._map !== null || i > this._SCAN_THRESHOLD) return this._claimViaMap(t, s);
|
|
544
531
|
if (s < 4) switch (s) {
|
|
545
532
|
case 0: {
|
|
546
|
-
const
|
|
547
|
-
if (
|
|
548
|
-
return
|
|
533
|
+
const r = this._s0;
|
|
534
|
+
if (r && r.node === t && r.unsub)
|
|
535
|
+
return r.version = t.version, !0;
|
|
549
536
|
}
|
|
550
537
|
case 1:
|
|
551
538
|
if (e > 1) {
|
|
552
|
-
const
|
|
553
|
-
if (
|
|
554
|
-
return
|
|
539
|
+
const r = this._s1;
|
|
540
|
+
if (r && r.node === t && r.unsub)
|
|
541
|
+
return r.version = t.version, s !== 1 && (this._s1 = this._s0, this._s0 = r), !0;
|
|
555
542
|
}
|
|
556
543
|
case 2:
|
|
557
544
|
if (e > 2) {
|
|
558
|
-
const
|
|
559
|
-
if (
|
|
560
|
-
if (
|
|
561
|
-
const
|
|
562
|
-
s === 0 ? this._s0 =
|
|
545
|
+
const r = this._s2;
|
|
546
|
+
if (r && r.node === t && r.unsub) {
|
|
547
|
+
if (r.version = t.version, s !== 2) {
|
|
548
|
+
const u = s === 0 ? this._s0 : this._s1;
|
|
549
|
+
s === 0 ? this._s0 = r : this._s1 = r, this._s2 = u;
|
|
563
550
|
}
|
|
564
551
|
return !0;
|
|
565
552
|
}
|
|
566
553
|
}
|
|
567
554
|
case 3:
|
|
568
555
|
if (e > 3) {
|
|
569
|
-
const
|
|
570
|
-
if (
|
|
571
|
-
if (
|
|
572
|
-
let
|
|
573
|
-
s === 0 ? (
|
|
556
|
+
const r = this._s3;
|
|
557
|
+
if (r && r.node === t && r.unsub) {
|
|
558
|
+
if (r.version = t.version, s !== 3) {
|
|
559
|
+
let u;
|
|
560
|
+
s === 0 ? (u = this._s0, this._s0 = r) : s === 1 ? (u = this._s1, this._s1 = r) : (u = this._s2, this._s2 = r), this._s3 = u;
|
|
574
561
|
}
|
|
575
562
|
return !0;
|
|
576
563
|
}
|
|
577
564
|
}
|
|
578
565
|
}
|
|
579
|
-
const n = s > 4 ? s : 4,
|
|
580
|
-
if (
|
|
581
|
-
const
|
|
582
|
-
if (
|
|
583
|
-
return
|
|
566
|
+
const n = s > 4 ? s : 4, o = this._overflow;
|
|
567
|
+
if (o) for (let r = n - 4, u = o.length; r < u; r++) {
|
|
568
|
+
const l = o[r];
|
|
569
|
+
if (l && l.node === t && l.unsub)
|
|
570
|
+
return l.version = t.version, this._swapGeneral(r + 4, s, l), !0;
|
|
584
571
|
}
|
|
585
572
|
return !1;
|
|
586
573
|
}
|
|
@@ -589,12 +576,12 @@ var k = class extends et {
|
|
|
589
576
|
this._map = /* @__PURE__ */ new Map();
|
|
590
577
|
const n = this._count;
|
|
591
578
|
s < 4 && (s <= 0 && this._s0?.unsub && this._map.set(this._s0.node, 0), s <= 1 && this._s1?.unsub && this._map.set(this._s1.node, 1), s <= 2 && this._s2?.unsub && this._map.set(this._s2.node, 2), s <= 3 && this._s3?.unsub && this._map.set(this._s3.node, 3));
|
|
592
|
-
const
|
|
593
|
-
if (
|
|
594
|
-
const
|
|
595
|
-
for (let
|
|
596
|
-
const
|
|
597
|
-
|
|
579
|
+
const o = this._overflow;
|
|
580
|
+
if (o && n > 4) {
|
|
581
|
+
const r = s > 4 ? s : 4;
|
|
582
|
+
for (let u = r - 4, l = o.length; u < l; u++) {
|
|
583
|
+
const O = o[u];
|
|
584
|
+
O?.unsub && this._map.set(O.node, u + 4);
|
|
598
585
|
}
|
|
599
586
|
}
|
|
600
587
|
}
|
|
@@ -608,10 +595,6 @@ var k = class extends et {
|
|
|
608
595
|
}
|
|
609
596
|
return !0;
|
|
610
597
|
}
|
|
611
|
-
_swapInline(t, s, e) {
|
|
612
|
-
const i = this.getAt(s);
|
|
613
|
-
this.setAt(s, e), this.setAt(t, i);
|
|
614
|
-
}
|
|
615
598
|
_swapGeneral(t, s, e) {
|
|
616
599
|
if (t === s) return;
|
|
617
600
|
const i = this.getAt(s);
|
|
@@ -628,7 +611,7 @@ var k = class extends et {
|
|
|
628
611
|
const e = this._count;
|
|
629
612
|
if (t < e) {
|
|
630
613
|
const i = this.getAt(t);
|
|
631
|
-
i != null && (this.
|
|
614
|
+
i != null && (this._addToOverflow(i), this._map !== null && i.unsub && this._map.set(i.node, this._count - 1));
|
|
632
615
|
}
|
|
633
616
|
if (t === 0) this._s0 = s;
|
|
634
617
|
else if (t === 1) this._s1 = s;
|
|
@@ -644,70 +627,64 @@ var k = class extends et {
|
|
|
644
627
|
t >= this._count || (super.truncateFrom(t), this._map !== null && (this._map.clear(), this._map = null));
|
|
645
628
|
}
|
|
646
629
|
seal() {
|
|
647
|
-
const t = this._count
|
|
630
|
+
const t = this._count;
|
|
631
|
+
if (t === 0) {
|
|
632
|
+
this._depsHash = 0;
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
const s = j.VERSION_BITS;
|
|
648
636
|
let e = 0;
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
if (e = e + (i.version << s) + i.node.id | 0, e = e + (n.version << s) + n.node.id | 0, e = e + (r.version << s) + r.node.id | 0, e = e + (o.version << s) + o.node.id | 0, t > 4) {
|
|
671
|
-
const h = this._overflow;
|
|
672
|
-
for (let u = 0, a = h.length; u < a; u++) {
|
|
673
|
-
const c = h[u];
|
|
674
|
-
e = e + (c.version << s) + c.node.id | 0;
|
|
675
|
-
}
|
|
676
|
-
}
|
|
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;
|
|
677
658
|
}
|
|
678
659
|
}
|
|
679
660
|
this._depsHash = e;
|
|
680
661
|
}
|
|
681
662
|
isDirtyFast() {
|
|
682
|
-
const t = this._count
|
|
663
|
+
const t = this._count;
|
|
664
|
+
if (t === 0) return !1;
|
|
665
|
+
const s = j.VERSION_BITS;
|
|
683
666
|
let e = 0;
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
const
|
|
704
|
-
|
|
705
|
-
const h = this._overflow;
|
|
706
|
-
for (let u = 0, a = h.length; u < a; u++) {
|
|
707
|
-
const c = h[u].node;
|
|
708
|
-
e = e + (c.version << s) + c.id | 0;
|
|
709
|
-
}
|
|
710
|
-
}
|
|
667
|
+
if (t >= 1) {
|
|
668
|
+
const i = this._s0.node;
|
|
669
|
+
e = e + (i.version << s) + i.id | 0;
|
|
670
|
+
}
|
|
671
|
+
if (t >= 2) {
|
|
672
|
+
const i = this._s1.node;
|
|
673
|
+
e = e + (i.version << s) + i.id | 0;
|
|
674
|
+
}
|
|
675
|
+
if (t >= 3) {
|
|
676
|
+
const i = this._s2.node;
|
|
677
|
+
e = e + (i.version << s) + i.id | 0;
|
|
678
|
+
}
|
|
679
|
+
if (t >= 4) {
|
|
680
|
+
const i = this._s3.node;
|
|
681
|
+
e = e + (i.version << s) + i.id | 0;
|
|
682
|
+
}
|
|
683
|
+
if (t > 4) {
|
|
684
|
+
const i = this._overflow;
|
|
685
|
+
for (let n = 0, o = i.length; n < o; n++) {
|
|
686
|
+
const r = i[n].node;
|
|
687
|
+
e = e + (r.version << s) + r.id | 0;
|
|
711
688
|
}
|
|
712
689
|
}
|
|
713
690
|
return e !== this._depsHash;
|
|
@@ -722,21 +699,21 @@ var k = class extends et {
|
|
|
722
699
|
}
|
|
723
700
|
};
|
|
724
701
|
function St(t) {
|
|
725
|
-
return t !== null && typeof t == "object" &&
|
|
702
|
+
return t !== null && typeof t == "object" && Q in t;
|
|
726
703
|
}
|
|
727
704
|
function gt(t) {
|
|
728
705
|
return t !== null && typeof t == "object" && rt in t;
|
|
729
706
|
}
|
|
730
|
-
function
|
|
707
|
+
function Tt(t) {
|
|
731
708
|
return t !== null && typeof t == "object" && ot in t;
|
|
732
709
|
}
|
|
733
710
|
function ht(t) {
|
|
734
711
|
return t !== null && typeof t == "object" && typeof t.then == "function";
|
|
735
712
|
}
|
|
736
|
-
var { IDLE:
|
|
713
|
+
var { IDLE: d, DIRTY: f, PENDING: S, RESOLVED: E, REJECTED: C, HAS_ERROR: m, RECOMPUTING: N, DISPOSED: L, IS_COMPUTED: M, FORCE_COMPUTE: P } = B, pt = class extends X {
|
|
737
714
|
constructor(t, s = {}) {
|
|
738
|
-
if (typeof t != "function") throw new
|
|
739
|
-
if (super(), this[
|
|
715
|
+
if (typeof t != "function") throw new v(h.COMPUTED_MUST_BE_FUNCTION);
|
|
716
|
+
if (super(), this[Q] = !0, this[rt] = !0, this._error = null, this._promiseId = 0, this._deps = new z(), this._asyncRetryCount = 0, this._lastDriftEpoch = p.UNINITIALIZED, this._trackEpoch = p.UNINITIALIZED, this._trackCount = 0, this._value = void 0, this.flags = M | f | d, this._equal = s.equal ?? Object.is, this._fn = t, this._defaultValue = "defaultValue" in s ? s.defaultValue : b, this._onError = s.onError ?? null, this._maxAsyncRetries = (s.maxAsyncRetries ?? $.MAX_ASYNC_RETRIES) & st, G.attachDebugInfo(this, "computed", this.id), s.lazy === !1) try {
|
|
740
717
|
this._recompute();
|
|
741
718
|
} catch {
|
|
742
719
|
}
|
|
@@ -747,20 +724,20 @@ var { IDLE: C, DIRTY: E, PENDING: g, RESOLVED: p, REJECTED: v, HAS_ERROR: A, REC
|
|
|
747
724
|
get value() {
|
|
748
725
|
this._track();
|
|
749
726
|
const t = this.flags;
|
|
750
|
-
if ((t & (
|
|
751
|
-
if (t &
|
|
752
|
-
if (t &
|
|
753
|
-
if (this._defaultValue !==
|
|
754
|
-
throw new
|
|
727
|
+
if ((t & (E | f | d)) === E) return this._value;
|
|
728
|
+
if (t & L) throw new v(h.COMPUTED_DISPOSED);
|
|
729
|
+
if (t & N) {
|
|
730
|
+
if (this._defaultValue !== b) return this._defaultValue;
|
|
731
|
+
throw new v(h.COMPUTED_CIRCULAR_DEPENDENCY);
|
|
755
732
|
}
|
|
756
|
-
if (t & (
|
|
733
|
+
if (t & (f | d) && ((t & d) === 0 && (t & P) === 0 && this._deps.size > 0 && !this._isDirty() ? this.flags &= ~f : this._recompute(), this.flags & E))
|
|
757
734
|
return this._value;
|
|
758
|
-
const s = this._defaultValue, e = s !==
|
|
759
|
-
if (this.flags &
|
|
735
|
+
const s = this._defaultValue, e = s !== b;
|
|
736
|
+
if (this.flags & S) {
|
|
760
737
|
if (e) return s;
|
|
761
|
-
throw new
|
|
738
|
+
throw new v(h.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
|
|
762
739
|
}
|
|
763
|
-
if (this.flags &
|
|
740
|
+
if (this.flags & C) {
|
|
764
741
|
if (e) return s;
|
|
765
742
|
throw this._error;
|
|
766
743
|
}
|
|
@@ -772,16 +749,16 @@ var { IDLE: C, DIRTY: E, PENDING: g, RESOLVED: p, REJECTED: v, HAS_ERROR: A, REC
|
|
|
772
749
|
get state() {
|
|
773
750
|
this._track();
|
|
774
751
|
const t = this.flags;
|
|
775
|
-
return t &
|
|
752
|
+
return t & E ? y.RESOLVED : t & S ? y.PENDING : t & C ? y.REJECTED : y.IDLE;
|
|
776
753
|
}
|
|
777
754
|
get hasError() {
|
|
778
|
-
if (this._track(), this.flags & (
|
|
755
|
+
if (this._track(), this.flags & (C | m)) return !0;
|
|
779
756
|
const t = this._deps;
|
|
780
757
|
if (!t.hasComputeds) return !1;
|
|
781
758
|
const s = t.size;
|
|
782
759
|
for (let e = 0; e < s; e++) {
|
|
783
760
|
const i = t.getAt(e);
|
|
784
|
-
if (i != null && i.node.flags &
|
|
761
|
+
if (i != null && i.node.flags & m) return !0;
|
|
785
762
|
}
|
|
786
763
|
return !1;
|
|
787
764
|
}
|
|
@@ -793,37 +770,37 @@ var { IDLE: C, DIRTY: E, PENDING: g, RESOLVED: p, REJECTED: v, HAS_ERROR: A, REC
|
|
|
793
770
|
const t = [];
|
|
794
771
|
this._error && t.push(this._error);
|
|
795
772
|
const s = this._deps;
|
|
796
|
-
if (!s.hasComputeds) return t.length === 0 ?
|
|
773
|
+
if (!s.hasComputeds) return t.length === 0 ? q : Object.freeze(t);
|
|
797
774
|
const e = s.size;
|
|
798
775
|
for (let i = 0; i < e; i++) {
|
|
799
776
|
const n = s.getAt(i);
|
|
800
777
|
if (n == null) continue;
|
|
801
|
-
const
|
|
802
|
-
|
|
778
|
+
const o = n.node;
|
|
779
|
+
o.flags & m && this._collectErrorsFromDep(o, t);
|
|
803
780
|
}
|
|
804
|
-
return t.length === 0 ?
|
|
781
|
+
return t.length === 0 ? q : Object.freeze(t);
|
|
805
782
|
}
|
|
806
783
|
_collectErrorsFromDep(t, s) {
|
|
807
784
|
const e = t.errors, i = e.length;
|
|
808
785
|
for (let n = 0; n < i; n++) {
|
|
809
|
-
const
|
|
810
|
-
|
|
786
|
+
const o = e[n];
|
|
787
|
+
o != null && !s.includes(o) && s.push(o);
|
|
811
788
|
}
|
|
812
789
|
}
|
|
813
790
|
get lastError() {
|
|
814
791
|
return this._track(), this._error;
|
|
815
792
|
}
|
|
816
793
|
get isPending() {
|
|
817
|
-
return this._track(), (this.flags &
|
|
794
|
+
return this._track(), (this.flags & S) !== 0;
|
|
818
795
|
}
|
|
819
796
|
get isResolved() {
|
|
820
|
-
return this._track(), (this.flags &
|
|
797
|
+
return this._track(), (this.flags & E) !== 0;
|
|
821
798
|
}
|
|
822
799
|
invalidate() {
|
|
823
|
-
this.flags |=
|
|
800
|
+
this.flags |= P, this._markDirty();
|
|
824
801
|
}
|
|
825
802
|
dispose() {
|
|
826
|
-
this.flags &
|
|
803
|
+
this.flags & L || (this._deps.disposeAll(), this._slots?.clear(), this.flags = L | f | d, this._error = null, this._value = void 0, this._hotIndex = -1);
|
|
827
804
|
}
|
|
828
805
|
[Symbol.dispose]() {
|
|
829
806
|
this.dispose();
|
|
@@ -834,14 +811,14 @@ var { IDLE: C, DIRTY: E, PENDING: g, RESOLVED: p, REJECTED: v, HAS_ERROR: A, REC
|
|
|
834
811
|
const s = this._trackCount, e = this._deps.getAt(s);
|
|
835
812
|
if (e != null && e.node === t) e.version = t.version;
|
|
836
813
|
else if (!this._deps.claimExisting(t, s)) {
|
|
837
|
-
const i = new
|
|
814
|
+
const i = new x(t, t.version, t.subscribe(this));
|
|
838
815
|
this._deps.insertNew(s, i);
|
|
839
816
|
}
|
|
840
|
-
t.flags &
|
|
817
|
+
t.flags & M && (this._deps.hasComputeds = !0), this._trackCount = s + 1;
|
|
841
818
|
}
|
|
842
819
|
_recompute() {
|
|
843
|
-
if (this.flags &
|
|
844
|
-
this.flags = (this.flags |
|
|
820
|
+
if (this.flags & N) return;
|
|
821
|
+
this.flags = (this.flags | N) & ~P, this._trackEpoch = k(), this._trackCount = 0, this._deps.prepareTracking(), this._hotIndex = -1;
|
|
845
822
|
let t = !1;
|
|
846
823
|
try {
|
|
847
824
|
const s = _.run(this, this._fn);
|
|
@@ -851,42 +828,42 @@ var { IDLE: C, DIRTY: E, PENDING: g, RESOLVED: p, REJECTED: v, HAS_ERROR: A, REC
|
|
|
851
828
|
this._deps.truncateFrom(this._trackCount);
|
|
852
829
|
} catch {
|
|
853
830
|
}
|
|
854
|
-
this._handleError(s,
|
|
831
|
+
this._handleError(s, h.COMPUTED_COMPUTATION_FAILED, !0);
|
|
855
832
|
} finally {
|
|
856
|
-
this._trackEpoch =
|
|
833
|
+
this._trackEpoch = p.UNINITIALIZED, this._trackCount = 0, this.flags &= ~N;
|
|
857
834
|
}
|
|
858
835
|
}
|
|
859
836
|
_handleAsyncComputation(t) {
|
|
860
|
-
this.flags = (this.flags |
|
|
837
|
+
this.flags = (this.flags | S) & ~(d | f | E | C), this._notifySubscribers(void 0, void 0), this._asyncRetryCount = 0, this._promiseId = (this._promiseId + 1) % $.MAX_PROMISE_ID;
|
|
861
838
|
const s = this._promiseId;
|
|
862
839
|
t.then((e) => {
|
|
863
840
|
if (s === this._promiseId) {
|
|
864
841
|
if (this._isDirty()) {
|
|
865
842
|
const i = nt();
|
|
866
|
-
return this._lastDriftEpoch !== i && (this._lastDriftEpoch = i, this._asyncRetryCount = 0), this._asyncRetryCount++ < this._maxAsyncRetries ? this._markDirty() : this._handleError(new
|
|
843
|
+
return this._lastDriftEpoch !== i && (this._lastDriftEpoch = i, this._asyncRetryCount = 0), this._asyncRetryCount++ < this._maxAsyncRetries ? this._markDirty() : this._handleError(new v(`Async drift threshold exceeded after ${this._maxAsyncRetries} retries.`), h.COMPUTED_ASYNC_COMPUTATION_FAILED);
|
|
867
844
|
}
|
|
868
845
|
this._finalizeResolution(e), this._notifySubscribers(e, void 0);
|
|
869
846
|
}
|
|
870
|
-
}, (e) => s === this._promiseId && this._handleError(e,
|
|
847
|
+
}, (e) => s === this._promiseId && this._handleError(e, h.COMPUTED_ASYNC_COMPUTATION_FAILED));
|
|
871
848
|
}
|
|
872
849
|
_handleError(t, s, e = !1) {
|
|
873
|
-
const i =
|
|
874
|
-
if (!e && !(this.flags &
|
|
850
|
+
const i = g(t, v, s);
|
|
851
|
+
if (!e && !(this.flags & C) && (this.version = H(this.version)), this._error = i, this.flags = this.flags & ~(d | f | S | E) | C | m, this._onError) try {
|
|
875
852
|
this._onError(i);
|
|
876
853
|
} catch (n) {
|
|
877
|
-
console.error(
|
|
854
|
+
console.error(h.CALLBACK_ERROR_IN_ERROR_HANDLER, n);
|
|
878
855
|
}
|
|
879
856
|
if (e) throw i;
|
|
880
857
|
this._notifySubscribers(void 0, void 0);
|
|
881
858
|
}
|
|
882
859
|
_finalizeResolution(t) {
|
|
883
|
-
(!(this.flags &
|
|
860
|
+
(!(this.flags & E) || !this._equal(this._value, t)) && (this.version = H(this.version)), this._value = t, this._error = null, this.flags = (this.flags | E) & ~(d | f | S | C | m);
|
|
884
861
|
}
|
|
885
862
|
execute() {
|
|
886
863
|
this._markDirty();
|
|
887
864
|
}
|
|
888
865
|
_markDirty() {
|
|
889
|
-
this.flags & (
|
|
866
|
+
this.flags & (N | f) || (this.flags |= f, this._notifySubscribers(void 0, void 0));
|
|
890
867
|
}
|
|
891
868
|
_isDirty() {
|
|
892
869
|
const t = this._deps;
|
|
@@ -900,12 +877,12 @@ var { IDLE: C, DIRTY: E, PENDING: g, RESOLVED: p, REJECTED: v, HAS_ERROR: A, REC
|
|
|
900
877
|
for (let i = 0; i < e; i++) {
|
|
901
878
|
const n = t.getAt(i);
|
|
902
879
|
if (n == null) continue;
|
|
903
|
-
const
|
|
904
|
-
if (
|
|
905
|
-
|
|
880
|
+
const o = n.node;
|
|
881
|
+
if (o.flags & M) try {
|
|
882
|
+
o.value;
|
|
906
883
|
} catch {
|
|
907
884
|
}
|
|
908
|
-
if (
|
|
885
|
+
if (o.version !== n.version)
|
|
909
886
|
return this._hotIndex = i, !0;
|
|
910
887
|
}
|
|
911
888
|
return this._hotIndex = -1, !1;
|
|
@@ -914,52 +891,52 @@ var { IDLE: C, DIRTY: E, PENDING: g, RESOLVED: p, REJECTED: v, HAS_ERROR: A, REC
|
|
|
914
891
|
}
|
|
915
892
|
}
|
|
916
893
|
};
|
|
917
|
-
function
|
|
894
|
+
function mt(t, s = {}) {
|
|
918
895
|
return new pt(t, s);
|
|
919
896
|
}
|
|
920
|
-
var It = class extends
|
|
897
|
+
var It = class extends X {
|
|
921
898
|
constructor(t, s = {}) {
|
|
922
|
-
super(), this[ot] = !0, this._cleanup = null, this._deps = new
|
|
899
|
+
super(), this[ot] = !0, this._cleanup = null, this._deps = new z(), this._currentEpoch = p.UNINITIALIZED, this._lastFlushEpoch = p.UNINITIALIZED, this._fn = t, this._onError = s.onError ?? null, this._sync = s.sync ?? !1, this._maxExecutions = s.maxExecutionsPerSecond ?? I.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = s.maxExecutionsPerFlush ?? I.MAX_EXECUTIONS_PER_EFFECT, this._cleanup = null, this._deps = new z(), this._currentEpoch = p.UNINITIALIZED, this._lastFlushEpoch = p.UNINITIALIZED, this._executionsInEpoch = 0, this._executionCount = 0, this._windowStart = 0, this._windowCount = 0, this._execId = 0, this._trackCount = 0, this._sync ? this._notifyCallback = () => this.execute() : this._notifyCallback = () => A.schedule(this), G.attachDebugInfo(this, "effect", this.id);
|
|
923
900
|
}
|
|
924
901
|
run() {
|
|
925
|
-
if (this.flags &
|
|
902
|
+
if (this.flags & c.DISPOSED) throw new D(h.EFFECT_DISPOSED);
|
|
926
903
|
this.execute(!0);
|
|
927
904
|
}
|
|
928
905
|
dispose() {
|
|
929
|
-
this.flags &
|
|
906
|
+
this.flags & c.DISPOSED || (this.flags |= c.DISPOSED, this._execCleanup(), this._deps?.disposeAll());
|
|
930
907
|
}
|
|
931
908
|
[Symbol.dispose]() {
|
|
932
909
|
this.dispose();
|
|
933
910
|
}
|
|
934
911
|
addDependency(t) {
|
|
935
|
-
if (!(this.flags &
|
|
912
|
+
if (!(this.flags & c.EXECUTING)) return;
|
|
936
913
|
const s = this._currentEpoch;
|
|
937
914
|
if (t._lastSeenEpoch === s) return;
|
|
938
915
|
t._lastSeenEpoch = s;
|
|
939
916
|
const e = this._trackCount, i = this._deps;
|
|
940
917
|
let n;
|
|
941
|
-
e === 0 ? n = i._s0 : e === 1 ? n = i._s1 : e === 2 ? n = i._s2 : e === 3 ? n = i._s3 : n = i.getAt(e), n != null && n.node === t ? n.version = t.version : i.claimExisting(t, e) || this._insertNewDependency(t, e), t.flags &
|
|
918
|
+
e === 0 ? n = i._s0 : e === 1 ? n = i._s1 : e === 2 ? n = i._s2 : e === 3 ? n = i._s3 : n = i.getAt(e), n != null && n.node === t ? n.version = t.version : i.claimExisting(t, e) || this._insertNewDependency(t, e), t.flags & B.IS_COMPUTED && (i.hasComputeds = !0), this._trackCount = e + 1;
|
|
942
919
|
}
|
|
943
920
|
_insertNewDependency(t, s) {
|
|
944
921
|
let e;
|
|
945
922
|
try {
|
|
946
923
|
const i = t.subscribe(this._notifyCallback);
|
|
947
|
-
e = new
|
|
924
|
+
e = new x(t, t.version, i);
|
|
948
925
|
} catch (i) {
|
|
949
|
-
const n =
|
|
926
|
+
const n = g(i, D, h.EFFECT_EXECUTION_FAILED);
|
|
950
927
|
if (console.error(n), this._onError) try {
|
|
951
928
|
this._onError(n);
|
|
952
929
|
} catch {
|
|
953
930
|
}
|
|
954
|
-
e = new
|
|
931
|
+
e = new x(t, t.version, void 0);
|
|
955
932
|
}
|
|
956
933
|
this._deps.insertNew(s, e);
|
|
957
934
|
}
|
|
958
935
|
execute(t = !1) {
|
|
959
|
-
if (this.flags & (
|
|
936
|
+
if (this.flags & (c.DISPOSED | c.EXECUTING)) return;
|
|
960
937
|
const s = this._deps;
|
|
961
938
|
if (!t && s.size > 0 && !this._isDirty()) return;
|
|
962
|
-
this._checkInfiniteLoops(), this.flags |=
|
|
939
|
+
this._checkInfiniteLoops(), this.flags |= c.EXECUTING, this._execCleanup(), this._currentEpoch = k(), this._trackCount = 0, s.prepareTracking(), this._hotIndex = -1;
|
|
963
940
|
let e = !1;
|
|
964
941
|
try {
|
|
965
942
|
const i = _.run(this, this._fn);
|
|
@@ -971,7 +948,7 @@ var It = class extends V {
|
|
|
971
948
|
}
|
|
972
949
|
this._handleExecutionError(i), this._cleanup = null;
|
|
973
950
|
} finally {
|
|
974
|
-
this.flags &= ~
|
|
951
|
+
this.flags &= ~c.EXECUTING;
|
|
975
952
|
}
|
|
976
953
|
}
|
|
977
954
|
_isDirty() {
|
|
@@ -981,11 +958,11 @@ var It = class extends V {
|
|
|
981
958
|
_handleAsyncResult(t) {
|
|
982
959
|
const s = ++this._execId;
|
|
983
960
|
t.then((e) => {
|
|
984
|
-
if (s !== this._execId || this.flags &
|
|
961
|
+
if (s !== this._execId || this.flags & c.DISPOSED) {
|
|
985
962
|
if (typeof e == "function") try {
|
|
986
963
|
e();
|
|
987
964
|
} catch (i) {
|
|
988
|
-
this._handleExecutionError(i,
|
|
965
|
+
this._handleExecutionError(i, h.EFFECT_CLEANUP_FAILED);
|
|
989
966
|
}
|
|
990
967
|
return;
|
|
991
968
|
}
|
|
@@ -1001,8 +978,8 @@ var It = class extends V {
|
|
|
1001
978
|
for (let i = 0; i < e; i++) {
|
|
1002
979
|
const n = s.getAt(i);
|
|
1003
980
|
if (n == null) continue;
|
|
1004
|
-
const
|
|
1005
|
-
if (
|
|
981
|
+
const o = n.node;
|
|
982
|
+
if (o.flags & B.IS_COMPUTED && this._tryPullComputed(o), o.version !== n.version)
|
|
1006
983
|
return this._hotIndex = i, !0;
|
|
1007
984
|
}
|
|
1008
985
|
return !1;
|
|
@@ -1021,81 +998,81 @@ var It = class extends V {
|
|
|
1021
998
|
try {
|
|
1022
999
|
this._cleanup();
|
|
1023
1000
|
} catch (t) {
|
|
1024
|
-
this._handleExecutionError(t,
|
|
1001
|
+
this._handleExecutionError(t, h.EFFECT_CLEANUP_FAILED);
|
|
1025
1002
|
}
|
|
1026
1003
|
this._cleanup = null;
|
|
1027
1004
|
}
|
|
1028
1005
|
}
|
|
1029
1006
|
_checkInfiniteLoops() {
|
|
1030
1007
|
const t = nt();
|
|
1031
|
-
this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), ft() >
|
|
1008
|
+
this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), ft() > I.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++;
|
|
1032
1009
|
}
|
|
1033
1010
|
_checkFrequencyLimit() {
|
|
1034
1011
|
if (!Number.isFinite(this._maxExecutions)) return;
|
|
1035
1012
|
const t = Date.now();
|
|
1036
|
-
if (t - this._windowStart >=
|
|
1013
|
+
if (t - this._windowStart >= tt.EFFECT_FREQUENCY_WINDOW) {
|
|
1037
1014
|
this._windowStart = t, this._windowCount = 1;
|
|
1038
1015
|
return;
|
|
1039
1016
|
}
|
|
1040
1017
|
if (++this._windowCount > this._maxExecutions) {
|
|
1041
|
-
const s = new D(
|
|
1018
|
+
const s = new D(h.EFFECT_FREQUENCY_LIMIT_EXCEEDED);
|
|
1042
1019
|
throw this.dispose(), this._handleExecutionError(s), s;
|
|
1043
1020
|
}
|
|
1044
1021
|
}
|
|
1045
1022
|
get isDisposed() {
|
|
1046
|
-
return (this.flags &
|
|
1023
|
+
return (this.flags & c.DISPOSED) !== 0;
|
|
1047
1024
|
}
|
|
1048
1025
|
get executionCount() {
|
|
1049
1026
|
return this._executionCount;
|
|
1050
1027
|
}
|
|
1051
1028
|
get isExecuting() {
|
|
1052
|
-
return (this.flags &
|
|
1029
|
+
return (this.flags & c.EXECUTING) !== 0;
|
|
1053
1030
|
}
|
|
1054
1031
|
_throwInfiniteLoopError(t) {
|
|
1055
|
-
const s = new D(`Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${
|
|
1032
|
+
const s = new D(`Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${V}`);
|
|
1056
1033
|
throw this.dispose(), console.error(s), s;
|
|
1057
1034
|
}
|
|
1058
|
-
_handleExecutionError(t, s =
|
|
1059
|
-
const e =
|
|
1035
|
+
_handleExecutionError(t, s = h.EFFECT_EXECUTION_FAILED) {
|
|
1036
|
+
const e = g(t, D, s);
|
|
1060
1037
|
if (console.error(e), this._onError) try {
|
|
1061
1038
|
this._onError(e);
|
|
1062
1039
|
} catch (i) {
|
|
1063
|
-
console.error(
|
|
1040
|
+
console.error(g(i, D, h.CALLBACK_ERROR_IN_ERROR_HANDLER));
|
|
1064
1041
|
}
|
|
1065
1042
|
}
|
|
1066
1043
|
};
|
|
1067
1044
|
function Nt(t, s = {}) {
|
|
1068
|
-
if (typeof t != "function") throw new D(
|
|
1045
|
+
if (typeof t != "function") throw new D(h.EFFECT_MUST_BE_FUNCTION);
|
|
1069
1046
|
const e = new It(t, s);
|
|
1070
1047
|
return e.execute(), e;
|
|
1071
1048
|
}
|
|
1072
1049
|
function At(t) {
|
|
1073
|
-
if (typeof t != "function") throw new TypeError(
|
|
1074
|
-
|
|
1050
|
+
if (typeof t != "function") throw new TypeError(h.BATCH_CALLBACK_MUST_BE_FUNCTION);
|
|
1051
|
+
A.startBatch();
|
|
1075
1052
|
try {
|
|
1076
1053
|
return t();
|
|
1077
1054
|
} finally {
|
|
1078
|
-
|
|
1055
|
+
A.endBatch();
|
|
1079
1056
|
}
|
|
1080
1057
|
}
|
|
1081
1058
|
export {
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1059
|
+
y as AsyncState,
|
|
1060
|
+
T as AtomError,
|
|
1061
|
+
v as ComputedError,
|
|
1062
|
+
tt as DEBUG_CONFIG,
|
|
1063
|
+
G as DEBUG_RUNTIME,
|
|
1087
1064
|
D as EffectError,
|
|
1088
|
-
|
|
1065
|
+
I as SCHEDULER_CONFIG,
|
|
1089
1066
|
R as SchedulerError,
|
|
1090
|
-
|
|
1067
|
+
vt as atom,
|
|
1091
1068
|
At as batch,
|
|
1092
|
-
|
|
1069
|
+
mt as computed,
|
|
1093
1070
|
Nt as effect,
|
|
1094
1071
|
St as isAtom,
|
|
1095
1072
|
gt as isComputed,
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1073
|
+
Tt as isEffect,
|
|
1074
|
+
A as scheduler,
|
|
1075
|
+
Dt as untracked
|
|
1099
1076
|
};
|
|
1100
1077
|
|
|
1101
1078
|
//# sourceMappingURL=index.mjs.map
|