@but212/atom-effect 0.3.3 → 0.4.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/README.md +13 -83
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +16 -12
- package/dist/index.mjs +280 -253
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
const
|
|
1
|
+
const ie = {
|
|
2
|
+
/** One second in milliseconds */
|
|
3
|
+
ONE_SECOND_MS: 1e3
|
|
4
|
+
}, F = {
|
|
2
5
|
IDLE: "idle",
|
|
3
6
|
PENDING: "pending",
|
|
4
7
|
RESOLVED: "resolved",
|
|
5
8
|
REJECTED: "rejected"
|
|
6
|
-
},
|
|
9
|
+
}, P = {
|
|
7
10
|
DISPOSED: 1,
|
|
8
11
|
// 0001 - Effect has been disposed
|
|
9
12
|
EXECUTING: 2
|
|
@@ -23,12 +26,12 @@ const O = {
|
|
|
23
26
|
// 100000 - Currently recomputing
|
|
24
27
|
HAS_ERROR: 64
|
|
25
28
|
// 1000000 - Has error state
|
|
26
|
-
},
|
|
29
|
+
}, Ee = {
|
|
27
30
|
/** Maximum number of pooled objects to prevent memory bloat */
|
|
28
31
|
MAX_SIZE: 1e3,
|
|
29
32
|
/** Number of objects to pre-allocate for performance-critical paths */
|
|
30
33
|
WARMUP_SIZE: 100
|
|
31
|
-
},
|
|
34
|
+
}, y = {
|
|
32
35
|
/** Maximum effect executions per second to detect infinite loops (Legacy/Fallback) */
|
|
33
36
|
MAX_EXECUTIONS_PER_SECOND: 100,
|
|
34
37
|
/** Threshold for cleaning up old execution timestamps */
|
|
@@ -42,13 +45,17 @@ const O = {
|
|
|
42
45
|
* Maximum total executions across all effects in a single flush cycle
|
|
43
46
|
* Increased from 1000 to 5000 based on evaluation report
|
|
44
47
|
*/
|
|
45
|
-
MAX_EXECUTIONS_PER_FLUSH: 5e3
|
|
46
|
-
|
|
48
|
+
MAX_EXECUTIONS_PER_FLUSH: 5e3,
|
|
49
|
+
/** Maximum iterations for synchronous flush loop to prevent infinite loops */
|
|
50
|
+
MAX_FLUSH_ITERATIONS: 1e3,
|
|
51
|
+
/** Minimum allowed value for max flush iterations */
|
|
52
|
+
MIN_FLUSH_ITERATIONS: 10
|
|
53
|
+
}, z = {
|
|
47
54
|
/** Maximum dependencies before warning about large dependency graphs */
|
|
48
55
|
MAX_DEPENDENCIES: 1e3,
|
|
49
56
|
/** Enable infinite loop detection warnings */
|
|
50
57
|
WARN_INFINITE_LOOP: !0
|
|
51
|
-
},
|
|
58
|
+
}, A = 1073741823, d = typeof process < "u" && process.env && process.env.NODE_ENV !== "production";
|
|
52
59
|
class E extends Error {
|
|
53
60
|
/**
|
|
54
61
|
* Creates a new AtomError
|
|
@@ -56,11 +63,11 @@ class E extends Error {
|
|
|
56
63
|
* @param cause - Original error that caused this error
|
|
57
64
|
* @param recoverable - Whether the operation can be retried
|
|
58
65
|
*/
|
|
59
|
-
constructor(e, t = null,
|
|
60
|
-
super(e), this.name = "AtomError", this.cause = t, this.recoverable =
|
|
66
|
+
constructor(e, t = null, i = !0) {
|
|
67
|
+
super(e), this.name = "AtomError", this.cause = t, this.recoverable = i, this.timestamp = /* @__PURE__ */ new Date();
|
|
61
68
|
}
|
|
62
69
|
}
|
|
63
|
-
class
|
|
70
|
+
class T extends E {
|
|
64
71
|
/**
|
|
65
72
|
* Creates a new ComputedError
|
|
66
73
|
* @param message - Error message
|
|
@@ -80,7 +87,7 @@ class g extends E {
|
|
|
80
87
|
super(e, t, !1), this.name = "EffectError";
|
|
81
88
|
}
|
|
82
89
|
}
|
|
83
|
-
class
|
|
90
|
+
class x extends E {
|
|
84
91
|
/**
|
|
85
92
|
* Creates a new SchedulerError
|
|
86
93
|
* @param message - Error message
|
|
@@ -90,18 +97,18 @@ class A extends E {
|
|
|
90
97
|
super(e, t, !1), this.name = "SchedulerError";
|
|
91
98
|
}
|
|
92
99
|
}
|
|
93
|
-
function
|
|
94
|
-
if (
|
|
95
|
-
return new e(`Type error (${t}): ${
|
|
96
|
-
if (
|
|
97
|
-
return new e(`Reference error (${t}): ${
|
|
98
|
-
if (
|
|
99
|
-
return
|
|
100
|
-
const
|
|
101
|
-
return new e(`Unexpected error (${t}): ${
|
|
100
|
+
function C(s, e, t) {
|
|
101
|
+
if (s instanceof TypeError)
|
|
102
|
+
return new e(`Type error (${t}): ${s.message}`, s);
|
|
103
|
+
if (s instanceof ReferenceError)
|
|
104
|
+
return new e(`Reference error (${t}): ${s.message}`, s);
|
|
105
|
+
if (s instanceof E)
|
|
106
|
+
return s;
|
|
107
|
+
const i = s instanceof Error ? s.message : String(s), n = s instanceof Error ? s : null;
|
|
108
|
+
return new e(`Unexpected error (${t}): ${i}`, n);
|
|
102
109
|
}
|
|
103
|
-
function
|
|
104
|
-
return
|
|
110
|
+
function Y(s) {
|
|
111
|
+
return s != null && typeof s.then == "function";
|
|
105
112
|
}
|
|
106
113
|
const l = {
|
|
107
114
|
// ─────────────────────────────────────────────────────────────────
|
|
@@ -177,7 +184,7 @@ const l = {
|
|
|
177
184
|
* // Output: "Large dependency graph detected: 150 dependencies"
|
|
178
185
|
* ```
|
|
179
186
|
*/
|
|
180
|
-
LARGE_DEPENDENCY_GRAPH: (
|
|
187
|
+
LARGE_DEPENDENCY_GRAPH: (s) => `Large dependency graph detected: ${s} dependencies`,
|
|
181
188
|
/**
|
|
182
189
|
* Warning logged when attempting to unsubscribe a non-existent listener.
|
|
183
190
|
*/
|
|
@@ -187,60 +194,61 @@ const l = {
|
|
|
187
194
|
* @remarks This prevents cascading failures from masking the original error.
|
|
188
195
|
*/
|
|
189
196
|
CALLBACK_ERROR_IN_ERROR_HANDLER: "Error occurred during onError callback execution"
|
|
190
|
-
}, w = /* @__PURE__ */ Symbol("debugName"),
|
|
191
|
-
function
|
|
192
|
-
return
|
|
197
|
+
}, w = /* @__PURE__ */ Symbol("debugName"), ne = /* @__PURE__ */ Symbol("id"), V = /* @__PURE__ */ Symbol("type"), X = /* @__PURE__ */ Symbol("noDefaultValue");
|
|
198
|
+
function re(s) {
|
|
199
|
+
return "dependencies" in s && Array.isArray(s.dependencies);
|
|
193
200
|
}
|
|
194
201
|
let G = 0;
|
|
195
|
-
function
|
|
196
|
-
const s = i;
|
|
202
|
+
function Q(s, e, t) {
|
|
197
203
|
if (s._visitedEpoch !== t) {
|
|
198
|
-
if (s._visitedEpoch = t,
|
|
199
|
-
throw new
|
|
200
|
-
if (
|
|
201
|
-
const
|
|
202
|
-
for (let
|
|
203
|
-
|
|
204
|
+
if (s._visitedEpoch = t, s === e)
|
|
205
|
+
throw new T("Indirect circular dependency detected");
|
|
206
|
+
if (re(s)) {
|
|
207
|
+
const i = s.dependencies;
|
|
208
|
+
for (let n = 0; n < i.length; n++) {
|
|
209
|
+
const r = i[n];
|
|
210
|
+
r && Q(r, e, t);
|
|
211
|
+
}
|
|
204
212
|
}
|
|
205
213
|
}
|
|
206
214
|
}
|
|
207
215
|
const S = {
|
|
208
216
|
enabled: typeof process < "u" && process.env?.NODE_ENV === "development",
|
|
209
|
-
maxDependencies:
|
|
210
|
-
warnInfiniteLoop:
|
|
211
|
-
warn(
|
|
212
|
-
this.enabled &&
|
|
217
|
+
maxDependencies: z.MAX_DEPENDENCIES,
|
|
218
|
+
warnInfiniteLoop: z.WARN_INFINITE_LOOP,
|
|
219
|
+
warn(s, e) {
|
|
220
|
+
this.enabled && s && console.warn(`[Atom Effect] ${e}`);
|
|
213
221
|
},
|
|
214
222
|
/**
|
|
215
223
|
* Checks for circular dependencies.
|
|
216
224
|
* Direct check runs always; indirect check only in dev mode.
|
|
217
225
|
* @throws {ComputedError} When circular dependency detected
|
|
218
226
|
*/
|
|
219
|
-
checkCircular(
|
|
220
|
-
if (
|
|
221
|
-
throw new
|
|
222
|
-
this.enabled && (G++,
|
|
227
|
+
checkCircular(s, e) {
|
|
228
|
+
if (s === e)
|
|
229
|
+
throw new T("Direct circular dependency detected");
|
|
230
|
+
this.enabled && (G++, Q(s, e, G));
|
|
223
231
|
},
|
|
224
|
-
attachDebugInfo(
|
|
232
|
+
attachDebugInfo(s, e, t) {
|
|
225
233
|
if (!this.enabled)
|
|
226
234
|
return;
|
|
227
|
-
const
|
|
228
|
-
|
|
235
|
+
const i = s;
|
|
236
|
+
i[w] = `${e}_${t}`, i[ne] = t, i[V] = e;
|
|
229
237
|
},
|
|
230
|
-
getDebugName(
|
|
231
|
-
if (
|
|
232
|
-
return
|
|
238
|
+
getDebugName(s) {
|
|
239
|
+
if (s != null && w in s)
|
|
240
|
+
return s[w];
|
|
233
241
|
},
|
|
234
|
-
getDebugType(
|
|
235
|
-
if (
|
|
236
|
-
return
|
|
242
|
+
getDebugType(s) {
|
|
243
|
+
if (s != null && V in s)
|
|
244
|
+
return s[V];
|
|
237
245
|
}
|
|
238
246
|
};
|
|
239
|
-
let
|
|
240
|
-
const
|
|
247
|
+
let ce = 1;
|
|
248
|
+
const ue = () => ce++;
|
|
241
249
|
class J {
|
|
242
250
|
constructor() {
|
|
243
|
-
this.id =
|
|
251
|
+
this.id = ue() & A, this.flags = 0;
|
|
244
252
|
}
|
|
245
253
|
}
|
|
246
254
|
class W extends J {
|
|
@@ -275,40 +283,40 @@ class W extends J {
|
|
|
275
283
|
*/
|
|
276
284
|
_notifySubscribers(e, t) {
|
|
277
285
|
this._functionSubscribers.forEachSafe(
|
|
278
|
-
(
|
|
279
|
-
(
|
|
286
|
+
(i) => i(e, t),
|
|
287
|
+
(i) => console.error(new E(l.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED, i))
|
|
280
288
|
), this._objectSubscribers.forEachSafe(
|
|
281
|
-
(
|
|
282
|
-
(
|
|
289
|
+
(i) => i.execute(),
|
|
290
|
+
(i) => console.error(new E(l.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED, i))
|
|
283
291
|
);
|
|
284
292
|
}
|
|
285
293
|
}
|
|
286
294
|
let B = 0;
|
|
287
295
|
function K() {
|
|
288
|
-
return B = (B + 1 | 0) &
|
|
296
|
+
return B = (B + 1 | 0) & A, B;
|
|
289
297
|
}
|
|
290
|
-
let
|
|
291
|
-
function
|
|
298
|
+
let M = 0, k = 0, L = !1;
|
|
299
|
+
function $() {
|
|
292
300
|
return L ? (d && console.warn(
|
|
293
301
|
"Warning: startFlush() called during flush - ignored to prevent infinite loop detection bypass"
|
|
294
|
-
), !1) : (L = !0,
|
|
302
|
+
), !1) : (L = !0, M = M + 1 & A, k = 0, !0);
|
|
295
303
|
}
|
|
296
|
-
function
|
|
304
|
+
function H() {
|
|
297
305
|
L = !1;
|
|
298
306
|
}
|
|
299
|
-
function
|
|
307
|
+
function oe() {
|
|
300
308
|
return L ? ++k : 0;
|
|
301
309
|
}
|
|
302
|
-
class
|
|
310
|
+
class he {
|
|
303
311
|
constructor() {
|
|
304
|
-
this.queueA = [], this.queueB = [], this.queue = this.queueA, this.queueSize = 0, this._epoch = 0, this.isProcessing = !1, this.isBatching = !1, this.batchDepth = 0, this.batchQueue = [], this.batchQueueSize = 0, this.isFlushingSync = !1, this.maxFlushIterations =
|
|
312
|
+
this.queueA = [], this.queueB = [], this.queue = this.queueA, this.queueSize = 0, this._epoch = 0, this.isProcessing = !1, this.isBatching = !1, this.batchDepth = 0, this.batchQueue = [], this.batchQueueSize = 0, this.isFlushingSync = !1, this.maxFlushIterations = y.MAX_FLUSH_ITERATIONS;
|
|
305
313
|
}
|
|
306
314
|
get phase() {
|
|
307
315
|
return this.isProcessing || this.isFlushingSync ? 2 : this.isBatching ? 1 : 0;
|
|
308
316
|
}
|
|
309
317
|
schedule(e) {
|
|
310
318
|
if (typeof e != "function")
|
|
311
|
-
throw new
|
|
319
|
+
throw new x("Scheduler callback must be a function");
|
|
312
320
|
e._nextEpoch !== this._epoch && (e._nextEpoch = this._epoch, this.isBatching || this.isFlushingSync ? this.batchQueue[this.batchQueueSize++] = e : (this.queue[this.queueSize++] = e, this.isProcessing || this.flush()));
|
|
313
321
|
}
|
|
314
322
|
flush() {
|
|
@@ -316,25 +324,25 @@ class re {
|
|
|
316
324
|
this.isProcessing = !0;
|
|
317
325
|
const e = this.queue, t = this.queueSize;
|
|
318
326
|
this.queue = this.queue === this.queueA ? this.queueB : this.queueA, this.queueSize = 0, this._epoch++, queueMicrotask(() => {
|
|
319
|
-
const
|
|
327
|
+
const i = $();
|
|
320
328
|
for (let n = 0; n < t; n++)
|
|
321
329
|
try {
|
|
322
330
|
e[n]?.();
|
|
323
331
|
} catch (r) {
|
|
324
332
|
console.error(
|
|
325
|
-
new
|
|
333
|
+
new x("Error occurred during scheduler execution", r)
|
|
326
334
|
);
|
|
327
335
|
}
|
|
328
|
-
e.length = 0, this.isProcessing = !1,
|
|
336
|
+
e.length = 0, this.isProcessing = !1, i && H(), this.queueSize > 0 && !this.isBatching && this.flush();
|
|
329
337
|
});
|
|
330
338
|
}
|
|
331
339
|
flushSync() {
|
|
332
340
|
this.isFlushingSync = !0;
|
|
333
|
-
const e =
|
|
341
|
+
const e = $();
|
|
334
342
|
try {
|
|
335
343
|
if (this._epoch++, this.batchQueueSize > 0) {
|
|
336
|
-
for (let
|
|
337
|
-
const n = this.batchQueue[
|
|
344
|
+
for (let i = 0; i < this.batchQueueSize; i++) {
|
|
345
|
+
const n = this.batchQueue[i];
|
|
338
346
|
n._nextEpoch !== this._epoch && (n._nextEpoch = this._epoch, this.queue[this.queueSize++] = n);
|
|
339
347
|
}
|
|
340
348
|
this.batchQueueSize = 0;
|
|
@@ -343,30 +351,30 @@ class re {
|
|
|
343
351
|
for (; this.queueSize > 0; ) {
|
|
344
352
|
if (++t > this.maxFlushIterations) {
|
|
345
353
|
console.error(
|
|
346
|
-
new
|
|
354
|
+
new x(
|
|
347
355
|
`Maximum flush iterations (${this.maxFlushIterations}) exceeded. Possible infinite loop.`
|
|
348
356
|
)
|
|
349
357
|
), this.queueSize = 0, this.queue.length = 0, this.batchQueueSize = 0;
|
|
350
358
|
break;
|
|
351
359
|
}
|
|
352
|
-
const
|
|
360
|
+
const i = this.queue, n = this.queueSize;
|
|
353
361
|
this.queue = this.queue === this.queueA ? this.queueB : this.queueA, this.queueSize = 0, this._epoch++;
|
|
354
362
|
for (let r = 0; r < n; r++)
|
|
355
363
|
try {
|
|
356
|
-
|
|
364
|
+
i[r]?.();
|
|
357
365
|
} catch (c) {
|
|
358
366
|
console.error(
|
|
359
|
-
new
|
|
367
|
+
new x("Error occurred during batch execution", c)
|
|
360
368
|
);
|
|
361
369
|
}
|
|
362
|
-
if (
|
|
370
|
+
if (i.length = 0, this.batchQueueSize > 0) {
|
|
363
371
|
for (let r = 0; r < this.batchQueueSize; r++)
|
|
364
372
|
this.queue[this.queueSize++] = this.batchQueue[r];
|
|
365
373
|
this.batchQueueSize = 0;
|
|
366
374
|
}
|
|
367
375
|
}
|
|
368
376
|
} finally {
|
|
369
|
-
this.isFlushingSync = !1, e &&
|
|
377
|
+
this.isFlushingSync = !1, e && H();
|
|
370
378
|
}
|
|
371
379
|
}
|
|
372
380
|
startBatch() {
|
|
@@ -376,29 +384,31 @@ class re {
|
|
|
376
384
|
this.batchDepth = Math.max(0, this.batchDepth - 1), this.batchDepth === 0 && (this.flushSync(), this.isBatching = !1);
|
|
377
385
|
}
|
|
378
386
|
setMaxFlushIterations(e) {
|
|
379
|
-
if (e <
|
|
380
|
-
throw new
|
|
387
|
+
if (e < y.MIN_FLUSH_ITERATIONS)
|
|
388
|
+
throw new x(
|
|
389
|
+
`Max flush iterations must be at least ${y.MIN_FLUSH_ITERATIONS}`
|
|
390
|
+
);
|
|
381
391
|
this.maxFlushIterations = e;
|
|
382
392
|
}
|
|
383
393
|
}
|
|
384
|
-
const U = new
|
|
385
|
-
function
|
|
386
|
-
if (typeof
|
|
394
|
+
const U = new he();
|
|
395
|
+
function be(s) {
|
|
396
|
+
if (typeof s != "function")
|
|
387
397
|
throw new E("Batch callback must be a function");
|
|
388
398
|
U.startBatch();
|
|
389
399
|
try {
|
|
390
|
-
return
|
|
400
|
+
return s();
|
|
391
401
|
} catch (e) {
|
|
392
402
|
throw new E("Error occurred during batch execution", e);
|
|
393
403
|
} finally {
|
|
394
404
|
U.endBatch();
|
|
395
405
|
}
|
|
396
406
|
}
|
|
397
|
-
const
|
|
407
|
+
const N = {
|
|
398
408
|
current: null,
|
|
399
|
-
run(
|
|
409
|
+
run(s, e) {
|
|
400
410
|
const t = this.current;
|
|
401
|
-
this.current =
|
|
411
|
+
this.current = s;
|
|
402
412
|
try {
|
|
403
413
|
return e();
|
|
404
414
|
} finally {
|
|
@@ -409,20 +419,32 @@ const m = {
|
|
|
409
419
|
return this.current;
|
|
410
420
|
}
|
|
411
421
|
};
|
|
412
|
-
function
|
|
413
|
-
|
|
422
|
+
function le(s) {
|
|
423
|
+
return typeof s == "object" && s !== null;
|
|
424
|
+
}
|
|
425
|
+
function Z(s) {
|
|
426
|
+
return (typeof s == "object" || typeof s == "function") && s !== null && typeof s.addDependency == "function";
|
|
427
|
+
}
|
|
428
|
+
function ee(s) {
|
|
429
|
+
return typeof s == "function" && typeof s.addDependency != "function";
|
|
430
|
+
}
|
|
431
|
+
function te(s) {
|
|
432
|
+
return le(s) && typeof s.execute == "function";
|
|
433
|
+
}
|
|
434
|
+
function _e(s) {
|
|
435
|
+
if (typeof s != "function")
|
|
414
436
|
throw new E("Untracked callback must be a function");
|
|
415
|
-
const e =
|
|
416
|
-
|
|
437
|
+
const e = N.current;
|
|
438
|
+
N.current = null;
|
|
417
439
|
try {
|
|
418
|
-
return
|
|
440
|
+
return s();
|
|
419
441
|
} catch (t) {
|
|
420
442
|
throw new E("Error occurred during untracked execution", t);
|
|
421
443
|
} finally {
|
|
422
|
-
|
|
444
|
+
N.current = e;
|
|
423
445
|
}
|
|
424
446
|
}
|
|
425
|
-
class
|
|
447
|
+
class v {
|
|
426
448
|
constructor() {
|
|
427
449
|
this.subscribers = null;
|
|
428
450
|
}
|
|
@@ -444,8 +466,8 @@ class M {
|
|
|
444
466
|
const t = this.subscribers.indexOf(e);
|
|
445
467
|
if (t === -1)
|
|
446
468
|
return !1;
|
|
447
|
-
const
|
|
448
|
-
return t !==
|
|
469
|
+
const i = this.subscribers.length - 1;
|
|
470
|
+
return t !== i && (this.subscribers[t] = this.subscribers[i]), this.subscribers.pop(), !0;
|
|
449
471
|
}
|
|
450
472
|
has(e) {
|
|
451
473
|
return this.subscribers ? this.subscribers.indexOf(e) !== -1 : !1;
|
|
@@ -458,9 +480,9 @@ class M {
|
|
|
458
480
|
/** Iterates with error handling to prevent one failure from breaking the chain */
|
|
459
481
|
forEachSafe(e, t) {
|
|
460
482
|
if (this.subscribers)
|
|
461
|
-
for (let
|
|
483
|
+
for (let i = 0; i < this.subscribers.length; i++)
|
|
462
484
|
try {
|
|
463
|
-
e(this.subscribers[
|
|
485
|
+
e(this.subscribers[i], i);
|
|
464
486
|
} catch (n) {
|
|
465
487
|
t ? t(n) : console.error("[SubscriberManager] Error in subscriber callback:", n);
|
|
466
488
|
}
|
|
@@ -469,7 +491,7 @@ class M {
|
|
|
469
491
|
return this.subscribers?.length ?? 0;
|
|
470
492
|
}
|
|
471
493
|
get hasSubscribers() {
|
|
472
|
-
return this.
|
|
494
|
+
return this.subscribers !== null && this.subscribers.length > 0;
|
|
473
495
|
}
|
|
474
496
|
clear() {
|
|
475
497
|
this.subscribers = null;
|
|
@@ -478,9 +500,9 @@ class M {
|
|
|
478
500
|
return this.subscribers ? [...this.subscribers] : [];
|
|
479
501
|
}
|
|
480
502
|
}
|
|
481
|
-
class
|
|
503
|
+
class ae extends W {
|
|
482
504
|
constructor(e, t) {
|
|
483
|
-
super(), this._isNotificationScheduled = !1, this._value = e, this._functionSubscribersStore = new
|
|
505
|
+
super(), this._isNotificationScheduled = !1, this._value = e, this._functionSubscribersStore = new v(), this._objectSubscribersStore = new v(), this._sync = t, this._notifyTask = this._flushNotifications.bind(this), S.attachDebugInfo(this, "atom", this.id);
|
|
484
506
|
}
|
|
485
507
|
get _functionSubscribers() {
|
|
486
508
|
return this._functionSubscribersStore;
|
|
@@ -490,28 +512,28 @@ class ue extends W {
|
|
|
490
512
|
}
|
|
491
513
|
/** Gets value and registers as dependency in current tracking context */
|
|
492
514
|
get value() {
|
|
493
|
-
const e =
|
|
494
|
-
return e
|
|
515
|
+
const e = N.getCurrent();
|
|
516
|
+
return e && this._track(e), this._value;
|
|
495
517
|
}
|
|
496
518
|
/** Sets value and notifies subscribers if changed (uses Object.is) */
|
|
497
519
|
set value(e) {
|
|
498
520
|
if (Object.is(this._value, e)) return;
|
|
499
521
|
const t = this._value;
|
|
500
|
-
this.version = this.version + 1 &
|
|
501
|
-
const s = this.version;
|
|
502
|
-
this._value = e, !(!this._functionSubscribersStore.hasSubscribers && !this._objectSubscribersStore.hasSubscribers) && this._notify(e, t, s);
|
|
522
|
+
this.version = this.version + 1 & A, this._value = e, !(!this._functionSubscribersStore.hasSubscribers && !this._objectSubscribersStore.hasSubscribers) && this._scheduleNotification(t);
|
|
503
523
|
}
|
|
504
524
|
_track(e) {
|
|
505
|
-
if (
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
} else {
|
|
509
|
-
const t = e;
|
|
510
|
-
t.addDependency !== void 0 ? t.addDependency(this) : t.execute !== void 0 && this._objectSubscribersStore.add(t);
|
|
525
|
+
if (Z(e)) {
|
|
526
|
+
e.addDependency(this);
|
|
527
|
+
return;
|
|
511
528
|
}
|
|
529
|
+
if (ee(e)) {
|
|
530
|
+
this._functionSubscribersStore.add(e);
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
te(e) && this._objectSubscribersStore.add(e);
|
|
512
534
|
}
|
|
513
|
-
|
|
514
|
-
this._isNotificationScheduled || (this._pendingOldValue =
|
|
535
|
+
_scheduleNotification(e) {
|
|
536
|
+
this._isNotificationScheduled || (this._pendingOldValue = e, this._isNotificationScheduled = !0), this._sync && !U.isBatching ? this._flushNotifications() : U.schedule(this._notifyTask);
|
|
515
537
|
}
|
|
516
538
|
_flushNotifications() {
|
|
517
539
|
if (!this._isNotificationScheduled) return;
|
|
@@ -526,11 +548,11 @@ class ue extends W {
|
|
|
526
548
|
this._functionSubscribersStore.clear(), this._objectSubscribersStore.clear(), this._value = void 0;
|
|
527
549
|
}
|
|
528
550
|
}
|
|
529
|
-
function
|
|
530
|
-
return new
|
|
551
|
+
function pe(s, e = {}) {
|
|
552
|
+
return new ae(s, e.sync ?? !1);
|
|
531
553
|
}
|
|
532
|
-
const
|
|
533
|
-
class
|
|
554
|
+
const a = Object.freeze([]), b = Object.freeze([]), f = Object.freeze([]);
|
|
555
|
+
class j {
|
|
534
556
|
constructor() {
|
|
535
557
|
this.pool = [], this.maxPoolSize = 50, this.maxReusableCapacity = 256, this.stats = d ? {
|
|
536
558
|
acquired: 0,
|
|
@@ -560,11 +582,11 @@ class z {
|
|
|
560
582
|
}
|
|
561
583
|
getStats() {
|
|
562
584
|
if (!d || !this.stats) return null;
|
|
563
|
-
const { acquired: e, released: t, rejected:
|
|
585
|
+
const { acquired: e, released: t, rejected: i } = this.stats, n = i.frozen + i.tooLarge + i.poolFull;
|
|
564
586
|
return {
|
|
565
587
|
acquired: e,
|
|
566
588
|
released: t,
|
|
567
|
-
rejected:
|
|
589
|
+
rejected: i,
|
|
568
590
|
leaked: e - t - n,
|
|
569
591
|
poolSize: this.pool.length
|
|
570
592
|
};
|
|
@@ -573,44 +595,44 @@ class z {
|
|
|
573
595
|
this.pool.length = 0, d && this.stats && (this.stats.acquired = 0, this.stats.released = 0, this.stats.rejected = { frozen: 0, tooLarge: 0, poolFull: 0 });
|
|
574
596
|
}
|
|
575
597
|
}
|
|
576
|
-
const
|
|
577
|
-
function q(
|
|
578
|
-
if (e !==
|
|
598
|
+
const I = new j(), m = new j(), p = new j();
|
|
599
|
+
function q(s, e, t, i) {
|
|
600
|
+
if (e !== a && t !== b)
|
|
579
601
|
for (let r = 0; r < e.length; r++) {
|
|
580
602
|
const c = e[r];
|
|
581
603
|
c && (c._tempUnsub = t[r]);
|
|
582
604
|
}
|
|
583
|
-
const n =
|
|
584
|
-
n.length =
|
|
585
|
-
for (let r = 0; r <
|
|
586
|
-
const c =
|
|
587
|
-
c && (c._tempUnsub ? (n[r] = c._tempUnsub, c._tempUnsub = void 0) : (S.checkCircular(c,
|
|
605
|
+
const n = m.acquire();
|
|
606
|
+
n.length = s.length;
|
|
607
|
+
for (let r = 0; r < s.length; r++) {
|
|
608
|
+
const c = s[r];
|
|
609
|
+
c && (c._tempUnsub ? (n[r] = c._tempUnsub, c._tempUnsub = void 0) : (S.checkCircular(c, i), n[r] = c.subscribe(i)));
|
|
588
610
|
}
|
|
589
|
-
if (e !==
|
|
611
|
+
if (e !== a)
|
|
590
612
|
for (let r = 0; r < e.length; r++) {
|
|
591
613
|
const c = e[r];
|
|
592
614
|
c?._tempUnsub && (c._tempUnsub(), c._tempUnsub = void 0);
|
|
593
615
|
}
|
|
594
|
-
return t !== b &&
|
|
616
|
+
return t !== b && m.release(t), n;
|
|
595
617
|
}
|
|
596
|
-
class
|
|
618
|
+
class se extends W {
|
|
597
619
|
constructor(e, t = {}) {
|
|
598
620
|
if (typeof e != "function")
|
|
599
|
-
throw new
|
|
600
|
-
if (super(), this._value = void 0, this.flags = o.DIRTY | o.IDLE, this._error = null, this._promiseId = 0, this._equal = t.equal ?? Object.is, this._fn = e, this._defaultValue = "defaultValue" in t ? t.defaultValue : X, this._hasDefaultValue = this._defaultValue !== X, this._onError = t.onError ?? null, this.MAX_PROMISE_ID = Number.MAX_SAFE_INTEGER - 1, this._functionSubscribersStore = new
|
|
621
|
+
throw new T(l.COMPUTED_MUST_BE_FUNCTION);
|
|
622
|
+
if (super(), this._value = void 0, this.flags = o.DIRTY | o.IDLE, this._error = null, this._promiseId = 0, this._equal = t.equal ?? Object.is, this._fn = e, this._defaultValue = "defaultValue" in t ? t.defaultValue : X, this._hasDefaultValue = this._defaultValue !== X, this._onError = t.onError ?? null, this.MAX_PROMISE_ID = Number.MAX_SAFE_INTEGER - 1, this._functionSubscribersStore = new v(), this._objectSubscribersStore = new v(), this._dependencies = a, this._dependencyVersions = f, this._unsubscribes = b, this._notifyJob = () => {
|
|
601
623
|
this._functionSubscribersStore.forEachSafe(
|
|
602
|
-
(
|
|
603
|
-
(
|
|
624
|
+
(i) => i(),
|
|
625
|
+
(i) => console.error(i)
|
|
604
626
|
), this._objectSubscribersStore.forEachSafe(
|
|
605
|
-
(
|
|
606
|
-
(
|
|
627
|
+
(i) => i.execute(),
|
|
628
|
+
(i) => console.error(i)
|
|
607
629
|
);
|
|
608
630
|
}, this._trackable = Object.assign(() => this._markDirty(), {
|
|
609
|
-
addDependency: (
|
|
631
|
+
addDependency: (i) => {
|
|
610
632
|
}
|
|
611
633
|
}), S.attachDebugInfo(this, "computed", this.id), S.enabled) {
|
|
612
|
-
const
|
|
613
|
-
|
|
634
|
+
const i = this;
|
|
635
|
+
i.subscriberCount = () => this._functionSubscribersStore.size + this._objectSubscribersStore.size, i.isDirty = () => this._isDirty(), i.dependencies = this._dependencies, i.stateFlags = this._getFlagsAsString();
|
|
614
636
|
}
|
|
615
637
|
if (t.lazy === !1)
|
|
616
638
|
try {
|
|
@@ -655,9 +677,9 @@ class Z extends W {
|
|
|
655
677
|
const t = this._unsubscribes[e];
|
|
656
678
|
t && t();
|
|
657
679
|
}
|
|
658
|
-
|
|
680
|
+
m.release(this._unsubscribes), this._unsubscribes = b;
|
|
659
681
|
}
|
|
660
|
-
this._dependencies !==
|
|
682
|
+
this._dependencies !== a && (I.release(this._dependencies), this._dependencies = a), this._dependencyVersions !== f && (p.release(this._dependencyVersions), this._dependencyVersions = f), this._functionSubscribersStore.clear(), this._objectSubscribersStore.clear(), this.flags = o.DIRTY | o.IDLE, this._error = null, this._value = void 0, this._promiseId = (this._promiseId + 1) % this.MAX_PROMISE_ID;
|
|
661
683
|
}
|
|
662
684
|
// State flag operations
|
|
663
685
|
_isDirty() {
|
|
@@ -701,7 +723,7 @@ class Z extends W {
|
|
|
701
723
|
this.flags = this.flags & ~t | -Number(e) & t;
|
|
702
724
|
}
|
|
703
725
|
_getAsyncState() {
|
|
704
|
-
return this.
|
|
726
|
+
return this._isResolved() ? F.RESOLVED : this._isPending() ? F.PENDING : this._isRejected() ? F.REJECTED : F.IDLE;
|
|
705
727
|
}
|
|
706
728
|
_getFlagsAsString() {
|
|
707
729
|
const e = [];
|
|
@@ -713,65 +735,65 @@ class Z extends W {
|
|
|
713
735
|
_recompute() {
|
|
714
736
|
if (this._isRecomputing()) return;
|
|
715
737
|
this._setRecomputing(!0);
|
|
716
|
-
const e = this._dependencies, t = this._dependencyVersions,
|
|
738
|
+
const e = this._dependencies, t = this._dependencyVersions, i = I.acquire(), n = p.acquire(), r = K();
|
|
717
739
|
let c = 0;
|
|
718
|
-
const
|
|
719
|
-
h._lastSeenEpoch !== r && (h._lastSeenEpoch = r, c <
|
|
740
|
+
const O = (h) => {
|
|
741
|
+
h._lastSeenEpoch !== r && (h._lastSeenEpoch = r, c < i.length ? (i[c] = h, n[c] = h.version) : (i.push(h), n.push(h.version)), c++);
|
|
720
742
|
}, D = this._trackable.addDependency;
|
|
721
|
-
this._trackable.addDependency =
|
|
743
|
+
this._trackable.addDependency = O;
|
|
722
744
|
let R = !1;
|
|
723
745
|
try {
|
|
724
|
-
const h =
|
|
725
|
-
if (
|
|
726
|
-
this._unsubscribes = q(
|
|
746
|
+
const h = N.run(this._trackable, this._fn);
|
|
747
|
+
if (i.length = c, n.length = c, Y(h)) {
|
|
748
|
+
this._unsubscribes = q(i, e, this._unsubscribes, this), this._dependencies = i, this._dependencyVersions = n, R = !0, this._handleAsyncComputation(h), this._setRecomputing(!1);
|
|
727
749
|
return;
|
|
728
750
|
}
|
|
729
|
-
this._unsubscribes = q(
|
|
751
|
+
this._unsubscribes = q(i, e, this._unsubscribes, this), this._dependencies = i, this._dependencyVersions = n, R = !0, this._handleSyncResult(h);
|
|
730
752
|
} catch (h) {
|
|
731
|
-
|
|
753
|
+
i.length = c, n.length = c, this._unsubscribes = q(i, e, this._unsubscribes, this), this._dependencies = i, this._dependencyVersions = n, R = !0, this._handleComputationError(h);
|
|
732
754
|
} finally {
|
|
733
|
-
this._trackable.addDependency = D, R ? (e !==
|
|
755
|
+
this._trackable.addDependency = D, R ? (e !== a && I.release(e), t !== f && p.release(t)) : (I.release(i), p.release(n));
|
|
734
756
|
}
|
|
735
757
|
}
|
|
736
758
|
_handleSyncResult(e) {
|
|
737
|
-
(!this._isResolved() || !this._equal(this._value, e)) && (this.version = this.version + 1 &
|
|
759
|
+
(!this._isResolved() || !this._equal(this._value, e)) && (this.version = this.version + 1 & A), this._value = e, this._clearDirty(), this._setResolved(), this._error = null, this._setRecomputing(!1);
|
|
738
760
|
}
|
|
739
761
|
_handleAsyncComputation(e) {
|
|
740
762
|
this._setPending(), this._clearDirty(), this._promiseId = this._promiseId >= this.MAX_PROMISE_ID ? 1 : this._promiseId + 1;
|
|
741
763
|
const t = this._promiseId;
|
|
742
|
-
e.then((
|
|
743
|
-
t === this._promiseId && this._handleAsyncResolution(
|
|
744
|
-
}).catch((
|
|
745
|
-
t === this._promiseId && this._handleAsyncRejection(
|
|
764
|
+
e.then((i) => {
|
|
765
|
+
t === this._promiseId && this._handleAsyncResolution(i);
|
|
766
|
+
}).catch((i) => {
|
|
767
|
+
t === this._promiseId && this._handleAsyncRejection(i);
|
|
746
768
|
});
|
|
747
769
|
}
|
|
748
770
|
_handleAsyncResolution(e) {
|
|
749
|
-
(!this._isResolved() || !this._equal(this._value, e)) && (this.version = this.version + 1 &
|
|
771
|
+
(!this._isResolved() || !this._equal(this._value, e)) && (this.version = this.version + 1 & A), this._value = e, this._clearDirty(), this._setResolved(), this._error = null, this._setRecomputing(!1);
|
|
750
772
|
}
|
|
751
773
|
_handleAsyncRejection(e) {
|
|
752
|
-
const t =
|
|
753
|
-
if (this._error = t, this._setRejected(), this._clearDirty(), this._setRecomputing(!1), this._onError
|
|
774
|
+
const t = C(e, T, l.COMPUTED_ASYNC_COMPUTATION_FAILED);
|
|
775
|
+
if (this._error = t, this._setRejected(), this._clearDirty(), this._setRecomputing(!1), this._onError)
|
|
754
776
|
try {
|
|
755
777
|
this._onError(t);
|
|
756
|
-
} catch (
|
|
757
|
-
console.error(l.CALLBACK_ERROR_IN_ERROR_HANDLER,
|
|
778
|
+
} catch (i) {
|
|
779
|
+
console.error(l.CALLBACK_ERROR_IN_ERROR_HANDLER, i);
|
|
758
780
|
}
|
|
759
781
|
this._notifySubscribers(void 0, void 0);
|
|
760
782
|
}
|
|
761
783
|
_handleComputationError(e) {
|
|
762
|
-
const t =
|
|
763
|
-
if (this._error = t, this._setRejected(), this._clearDirty(), this._setRecomputing(!1), this._onError
|
|
784
|
+
const t = C(e, T, l.COMPUTED_COMPUTATION_FAILED);
|
|
785
|
+
if (this._error = t, this._setRejected(), this._clearDirty(), this._setRecomputing(!1), this._onError)
|
|
764
786
|
try {
|
|
765
787
|
this._onError(t);
|
|
766
|
-
} catch (
|
|
767
|
-
console.error(l.CALLBACK_ERROR_IN_ERROR_HANDLER,
|
|
788
|
+
} catch (i) {
|
|
789
|
+
console.error(l.CALLBACK_ERROR_IN_ERROR_HANDLER, i);
|
|
768
790
|
}
|
|
769
791
|
throw t;
|
|
770
792
|
}
|
|
771
793
|
_handlePending() {
|
|
772
794
|
if (this._hasDefaultValue)
|
|
773
795
|
return this._defaultValue;
|
|
774
|
-
throw new
|
|
796
|
+
throw new T(l.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
|
|
775
797
|
}
|
|
776
798
|
_handleRejected() {
|
|
777
799
|
if (this._error?.recoverable && this._hasDefaultValue)
|
|
@@ -786,21 +808,25 @@ class Z extends W {
|
|
|
786
808
|
this._isRecomputing() || this._isDirty() || (this._setDirty(), this._notifyJob());
|
|
787
809
|
}
|
|
788
810
|
_registerTracking() {
|
|
789
|
-
const e =
|
|
790
|
-
if (e)
|
|
791
|
-
if (
|
|
811
|
+
const e = N.getCurrent();
|
|
812
|
+
if (e) {
|
|
813
|
+
if (Z(e)) {
|
|
792
814
|
e.addDependency(this);
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
if (ee(e)) {
|
|
818
|
+
this._functionSubscribersStore.add(e);
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
te(e) && this._objectSubscribersStore.add(e);
|
|
822
|
+
}
|
|
797
823
|
}
|
|
798
824
|
}
|
|
799
|
-
Object.freeze(
|
|
800
|
-
function
|
|
801
|
-
return new
|
|
825
|
+
Object.freeze(se.prototype);
|
|
826
|
+
function Se(s, e = {}) {
|
|
827
|
+
return new se(s, e);
|
|
802
828
|
}
|
|
803
|
-
class
|
|
829
|
+
class fe extends J {
|
|
804
830
|
constructor(e, t = {}) {
|
|
805
831
|
super(), this.run = () => {
|
|
806
832
|
if (this.isDisposed)
|
|
@@ -809,62 +835,62 @@ class oe extends J {
|
|
|
809
835
|
}, this.dispose = () => {
|
|
810
836
|
if (!this.isDisposed) {
|
|
811
837
|
if (this._setDisposed(), this._safeCleanup(), this._unsubscribes !== b) {
|
|
812
|
-
for (let
|
|
813
|
-
const n = this._unsubscribes[
|
|
838
|
+
for (let i = 0; i < this._unsubscribes.length; i++) {
|
|
839
|
+
const n = this._unsubscribes[i];
|
|
814
840
|
n && n();
|
|
815
841
|
}
|
|
816
|
-
|
|
842
|
+
m.release(this._unsubscribes), this._unsubscribes = b;
|
|
817
843
|
}
|
|
818
|
-
this._dependencies !==
|
|
844
|
+
this._dependencies !== a && (I.release(this._dependencies), this._dependencies = a), this._dependencyVersions !== f && (p.release(this._dependencyVersions), this._dependencyVersions = f);
|
|
819
845
|
}
|
|
820
|
-
}, this.addDependency = (
|
|
846
|
+
}, this.addDependency = (i) => {
|
|
821
847
|
if (this.isExecuting && this._nextDeps && this._nextUnsubs && this._nextVersions) {
|
|
822
|
-
const n =
|
|
823
|
-
if (
|
|
824
|
-
|
|
848
|
+
const n = this._currentEpoch;
|
|
849
|
+
if (i._lastSeenEpoch === n) return;
|
|
850
|
+
i._lastSeenEpoch = n, this._nextDeps.push(i), this._nextVersions.push(i.version), i._tempUnsub ? (this._nextUnsubs.push(i._tempUnsub), i._tempUnsub = void 0) : this._subscribeTo(i);
|
|
825
851
|
}
|
|
826
852
|
}, this.execute = () => {
|
|
827
853
|
if (this.isDisposed || this.isExecuting || !this._shouldExecute()) return;
|
|
828
854
|
this._checkInfiniteLoop(), this._setExecuting(!0), this._safeCleanup();
|
|
829
|
-
const
|
|
830
|
-
if (
|
|
831
|
-
for (let u = 0; u <
|
|
832
|
-
const
|
|
833
|
-
|
|
855
|
+
const i = this._dependencies, n = this._dependencyVersions, r = this._unsubscribes, c = I.acquire(), O = p.acquire(), D = m.acquire(), R = K();
|
|
856
|
+
if (i !== a && r !== b)
|
|
857
|
+
for (let u = 0; u < i.length; u++) {
|
|
858
|
+
const _ = i[u];
|
|
859
|
+
_ && (_._tempUnsub = r[u]);
|
|
834
860
|
}
|
|
835
|
-
this._nextDeps = c, this._nextVersions =
|
|
861
|
+
this._nextDeps = c, this._nextVersions = O, this._nextUnsubs = D, this._currentEpoch = R;
|
|
836
862
|
let h = !1;
|
|
837
863
|
try {
|
|
838
|
-
const u =
|
|
839
|
-
this._dependencies = c, this._dependencyVersions =
|
|
840
|
-
!this.isDisposed && typeof
|
|
841
|
-
}).catch((
|
|
842
|
-
console.error(
|
|
864
|
+
const u = N.run(this, this._fn);
|
|
865
|
+
this._dependencies = c, this._dependencyVersions = O, this._unsubscribes = D, h = !0, this._checkLoopWarnings(), Y(u) ? u.then((_) => {
|
|
866
|
+
!this.isDisposed && typeof _ == "function" && (this._cleanup = _);
|
|
867
|
+
}).catch((_) => {
|
|
868
|
+
console.error(C(_, g, l.EFFECT_EXECUTION_FAILED));
|
|
843
869
|
}) : this._cleanup = typeof u == "function" ? u : null;
|
|
844
870
|
} catch (u) {
|
|
845
|
-
h = !0, console.error(
|
|
871
|
+
h = !0, console.error(C(u, g, l.EFFECT_EXECUTION_FAILED)), this._cleanup = null;
|
|
846
872
|
} finally {
|
|
847
873
|
if (this._setExecuting(!1), this._nextDeps = null, this._nextVersions = null, this._nextUnsubs = null, h) {
|
|
848
|
-
if (
|
|
849
|
-
for (let u = 0; u <
|
|
850
|
-
const
|
|
851
|
-
|
|
874
|
+
if (i !== a) {
|
|
875
|
+
for (let u = 0; u < i.length; u++) {
|
|
876
|
+
const _ = i[u];
|
|
877
|
+
_?._tempUnsub && (_._tempUnsub(), _._tempUnsub = void 0);
|
|
852
878
|
}
|
|
853
|
-
|
|
879
|
+
I.release(i);
|
|
854
880
|
}
|
|
855
|
-
r !== b &&
|
|
881
|
+
r !== b && m.release(r), n !== f && p.release(n);
|
|
856
882
|
} else {
|
|
857
|
-
|
|
883
|
+
I.release(c), p.release(O);
|
|
858
884
|
for (let u = 0; u < D.length; u++)
|
|
859
885
|
D[u]?.();
|
|
860
|
-
if (
|
|
861
|
-
for (let u = 0; u <
|
|
862
|
-
const
|
|
863
|
-
|
|
886
|
+
if (m.release(D), i !== a)
|
|
887
|
+
for (let u = 0; u < i.length; u++) {
|
|
888
|
+
const _ = i[u];
|
|
889
|
+
_ && (_._tempUnsub = void 0);
|
|
864
890
|
}
|
|
865
891
|
}
|
|
866
892
|
}
|
|
867
|
-
}, this._currentEpoch = -1, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._fn = e, this._sync = t.sync ?? !1, this._maxExecutions = t.maxExecutionsPerSecond ??
|
|
893
|
+
}, this._currentEpoch = -1, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._fn = e, this._sync = t.sync ?? !1, this._maxExecutions = t.maxExecutionsPerSecond ?? y.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = t.maxExecutionsPerFlush ?? y.MAX_EXECUTIONS_PER_EFFECT, this._trackModifications = t.trackModifications ?? !1, this._cleanup = null, this._dependencies = a, this._dependencyVersions = f, this._unsubscribes = b, this._nextDeps = null, this._nextVersions = null, this._nextUnsubs = null, this._history = d ? [] : null, this._executionCount = 0, S.attachDebugInfo(this, "effect", this.id);
|
|
868
894
|
}
|
|
869
895
|
_subscribeTo(e) {
|
|
870
896
|
try {
|
|
@@ -873,48 +899,48 @@ class oe extends J {
|
|
|
873
899
|
});
|
|
874
900
|
this._nextUnsubs && this._nextUnsubs.push(t);
|
|
875
901
|
} catch (t) {
|
|
876
|
-
console.error(
|
|
902
|
+
console.error(C(t, g, l.EFFECT_EXECUTION_FAILED)), this._nextUnsubs && this._nextUnsubs.push(() => {
|
|
877
903
|
});
|
|
878
904
|
}
|
|
879
905
|
}
|
|
880
906
|
get isDisposed() {
|
|
881
|
-
return (this.flags &
|
|
907
|
+
return (this.flags & P.DISPOSED) !== 0;
|
|
882
908
|
}
|
|
883
909
|
get executionCount() {
|
|
884
910
|
return this._executionCount;
|
|
885
911
|
}
|
|
886
912
|
get isExecuting() {
|
|
887
|
-
return (this.flags &
|
|
913
|
+
return (this.flags & P.EXECUTING) !== 0;
|
|
888
914
|
}
|
|
889
915
|
_setDisposed() {
|
|
890
|
-
this.flags |=
|
|
916
|
+
this.flags |= P.DISPOSED;
|
|
891
917
|
}
|
|
892
918
|
_setExecuting(e) {
|
|
893
|
-
const t =
|
|
919
|
+
const t = P.EXECUTING;
|
|
894
920
|
this.flags = this.flags & ~t | -Number(e) & t;
|
|
895
921
|
}
|
|
896
922
|
_safeCleanup() {
|
|
897
|
-
if (this._cleanup
|
|
923
|
+
if (this._cleanup) {
|
|
898
924
|
try {
|
|
899
925
|
this._cleanup();
|
|
900
926
|
} catch (e) {
|
|
901
|
-
console.error(
|
|
927
|
+
console.error(C(e, g, l.EFFECT_CLEANUP_FAILED));
|
|
902
928
|
}
|
|
903
929
|
this._cleanup = null;
|
|
904
930
|
}
|
|
905
931
|
}
|
|
906
932
|
_checkInfiniteLoop() {
|
|
907
|
-
if (this._lastFlushEpoch !==
|
|
933
|
+
if (this._lastFlushEpoch !== M && (this._lastFlushEpoch = M, this._executionsInEpoch = 0), this._executionsInEpoch++, this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), oe() > y.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++, this._history) {
|
|
908
934
|
const e = Date.now();
|
|
909
|
-
this._history.push(e), this._history.length >
|
|
935
|
+
this._history.push(e), this._history.length > y.MAX_EXECUTIONS_PER_SECOND + 10 && this._history.shift(), this._checkTimestampLoop(e);
|
|
910
936
|
}
|
|
911
937
|
}
|
|
912
938
|
_checkTimestampLoop(e) {
|
|
913
939
|
const t = this._history;
|
|
914
940
|
if (!t || this._maxExecutions <= 0) return;
|
|
915
|
-
const
|
|
941
|
+
const i = e - ie.ONE_SECOND_MS;
|
|
916
942
|
let n = 0;
|
|
917
|
-
for (let r = t.length - 1; r >= 0 && !(t[r] <
|
|
943
|
+
for (let r = t.length - 1; r >= 0 && !(t[r] < i); r--)
|
|
918
944
|
n++;
|
|
919
945
|
if (n > this._maxExecutions) {
|
|
920
946
|
const r = new g(
|
|
@@ -931,13 +957,14 @@ class oe extends J {
|
|
|
931
957
|
throw this.dispose(), console.error(t), t;
|
|
932
958
|
}
|
|
933
959
|
_shouldExecute() {
|
|
934
|
-
if (this._dependencies ===
|
|
960
|
+
if (this._dependencies === a || this._dependencyVersions === f)
|
|
961
|
+
return !0;
|
|
935
962
|
for (let e = 0; e < this._dependencies.length; e++) {
|
|
936
963
|
const t = this._dependencies[e];
|
|
937
964
|
if (t) {
|
|
938
965
|
if ("value" in t)
|
|
939
966
|
try {
|
|
940
|
-
|
|
967
|
+
_e(() => t.value);
|
|
941
968
|
} catch {
|
|
942
969
|
return !0;
|
|
943
970
|
}
|
|
@@ -951,53 +978,53 @@ class oe extends J {
|
|
|
951
978
|
if (this._trackModifications && S.enabled) {
|
|
952
979
|
const e = this._dependencies;
|
|
953
980
|
for (let t = 0; t < e.length; t++) {
|
|
954
|
-
const
|
|
955
|
-
|
|
981
|
+
const i = e[t];
|
|
982
|
+
i && i._modifiedAtEpoch === this._currentEpoch && S.warn(
|
|
956
983
|
!0,
|
|
957
|
-
`Effect is reading a dependency (${S.getDebugName(
|
|
984
|
+
`Effect is reading a dependency (${S.getDebugName(i) || "unknown"}) that it just modified. Infinite loop may occur`
|
|
958
985
|
);
|
|
959
986
|
}
|
|
960
987
|
}
|
|
961
988
|
}
|
|
962
989
|
}
|
|
963
|
-
function
|
|
964
|
-
if (typeof
|
|
990
|
+
function ge(s, e = {}) {
|
|
991
|
+
if (typeof s != "function")
|
|
965
992
|
throw new g(l.EFFECT_MUST_BE_FUNCTION);
|
|
966
|
-
const t = new
|
|
993
|
+
const t = new fe(s, e);
|
|
967
994
|
return t.execute(), t;
|
|
968
995
|
}
|
|
969
|
-
function
|
|
970
|
-
return
|
|
996
|
+
function de(s) {
|
|
997
|
+
return s !== null && typeof s == "object" && "value" in s && "subscribe" in s && typeof s.subscribe == "function";
|
|
971
998
|
}
|
|
972
|
-
function
|
|
973
|
-
if (S.enabled) {
|
|
974
|
-
const e = S.getDebugType(
|
|
999
|
+
function Ie(s) {
|
|
1000
|
+
if (S.enabled && (s == null || typeof s == "object")) {
|
|
1001
|
+
const e = S.getDebugType(s);
|
|
975
1002
|
if (e)
|
|
976
1003
|
return e === "computed";
|
|
977
1004
|
}
|
|
978
|
-
return
|
|
1005
|
+
return de(s) && "invalidate" in s && typeof s.invalidate == "function";
|
|
979
1006
|
}
|
|
980
|
-
function
|
|
981
|
-
return
|
|
1007
|
+
function De(s) {
|
|
1008
|
+
return s !== null && typeof s == "object" && "dispose" in s && "run" in s && typeof s.dispose == "function" && typeof s.run == "function";
|
|
982
1009
|
}
|
|
983
1010
|
export {
|
|
984
|
-
|
|
1011
|
+
F as AsyncState,
|
|
985
1012
|
E as AtomError,
|
|
986
|
-
|
|
987
|
-
|
|
1013
|
+
T as ComputedError,
|
|
1014
|
+
z as DEBUG_CONFIG,
|
|
988
1015
|
S as DEBUG_RUNTIME,
|
|
989
1016
|
g as EffectError,
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1017
|
+
Ee as POOL_CONFIG,
|
|
1018
|
+
y as SCHEDULER_CONFIG,
|
|
1019
|
+
x as SchedulerError,
|
|
1020
|
+
pe as atom,
|
|
1021
|
+
be as batch,
|
|
1022
|
+
Se as computed,
|
|
1023
|
+
ge as effect,
|
|
1024
|
+
de as isAtom,
|
|
1025
|
+
Ie as isComputed,
|
|
1026
|
+
De as isEffect,
|
|
1000
1027
|
U as scheduler,
|
|
1001
|
-
|
|
1028
|
+
_e as untracked
|
|
1002
1029
|
};
|
|
1003
1030
|
//# sourceMappingURL=index.mjs.map
|