@but212/atom-effect 0.14.0 → 0.15.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 +7 -7
- 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 +11 -34
- package/dist/index.mjs +399 -366
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const ne = {
|
|
2
2
|
/** One second in milliseconds */
|
|
3
3
|
ONE_SECOND_MS: 1e3
|
|
4
4
|
}, M = {
|
|
@@ -6,15 +6,15 @@ const re = {
|
|
|
6
6
|
PENDING: "pending",
|
|
7
7
|
RESOLVED: "resolved",
|
|
8
8
|
REJECTED: "rejected"
|
|
9
|
-
},
|
|
9
|
+
}, g = {
|
|
10
10
|
DISPOSED: 1,
|
|
11
11
|
HAS_FN_SUBS: 2,
|
|
12
12
|
HAS_OBJ_SUBS: 4
|
|
13
|
-
},
|
|
14
|
-
...
|
|
13
|
+
}, S = {
|
|
14
|
+
...g,
|
|
15
15
|
EXECUTING: 8
|
|
16
16
|
}, u = {
|
|
17
|
-
...
|
|
17
|
+
...g,
|
|
18
18
|
DIRTY: 8,
|
|
19
19
|
IDLE: 16,
|
|
20
20
|
PENDING: 32,
|
|
@@ -22,16 +22,16 @@ const re = {
|
|
|
22
22
|
REJECTED: 128,
|
|
23
23
|
RECOMPUTING: 256,
|
|
24
24
|
HAS_ERROR: 512
|
|
25
|
-
},
|
|
26
|
-
...
|
|
25
|
+
}, b = {
|
|
26
|
+
...g,
|
|
27
27
|
SYNC: 8,
|
|
28
28
|
NOTIFICATION_SCHEDULED: 16
|
|
29
|
-
},
|
|
29
|
+
}, De = {
|
|
30
30
|
/** Maximum number of pooled objects to prevent memory bloat */
|
|
31
31
|
MAX_SIZE: 1e3,
|
|
32
32
|
/** Number of objects to pre-allocate for performance-critical paths */
|
|
33
33
|
WARMUP_SIZE: 100
|
|
34
|
-
},
|
|
34
|
+
}, T = {
|
|
35
35
|
/** Maximum effect executions per second to detect infinite loops (Legacy/Fallback) */
|
|
36
36
|
MAX_EXECUTIONS_PER_SECOND: 1e3,
|
|
37
37
|
/** Threshold for cleaning up old execution timestamps */
|
|
@@ -57,8 +57,8 @@ const re = {
|
|
|
57
57
|
MAX_DEPENDENCIES: 1e3,
|
|
58
58
|
/** Enable infinite loop detection warnings */
|
|
59
59
|
WARN_INFINITE_LOOP: !0
|
|
60
|
-
},
|
|
61
|
-
class
|
|
60
|
+
}, A = 1073741823, E = typeof process < "u" && process.env && process.env.NODE_ENV !== "production", re = Object.freeze([]);
|
|
61
|
+
class C extends Error {
|
|
62
62
|
/**
|
|
63
63
|
* Creates a new AtomError
|
|
64
64
|
* @param message - Error message describing what went wrong
|
|
@@ -69,7 +69,7 @@ class T extends Error {
|
|
|
69
69
|
super(e), this.name = "AtomError", this.cause = t, this.recoverable = s, this.timestamp = /* @__PURE__ */ new Date();
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
class
|
|
72
|
+
class R extends C {
|
|
73
73
|
/**
|
|
74
74
|
* Creates a new ComputedError
|
|
75
75
|
* @param message - Error message
|
|
@@ -79,7 +79,7 @@ class x extends T {
|
|
|
79
79
|
super(e, t, !0), this.name = "ComputedError";
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
class
|
|
82
|
+
class y extends C {
|
|
83
83
|
/**
|
|
84
84
|
* Creates a new EffectError
|
|
85
85
|
* @param message - Error message
|
|
@@ -89,7 +89,7 @@ class R extends T {
|
|
|
89
89
|
super(e, t, !1), this.name = "EffectError";
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
class
|
|
92
|
+
class P extends C {
|
|
93
93
|
/**
|
|
94
94
|
* Creates a new SchedulerError
|
|
95
95
|
* @param message - Error message
|
|
@@ -107,6 +107,10 @@ const l = {
|
|
|
107
107
|
* Error thrown when computed() receives a non-function argument.
|
|
108
108
|
*/
|
|
109
109
|
COMPUTED_MUST_BE_FUNCTION: "Computed function must be a function",
|
|
110
|
+
/**
|
|
111
|
+
* Error thrown when subscribe() receives an invalid listener.
|
|
112
|
+
*/
|
|
113
|
+
COMPUTED_SUBSCRIBER_MUST_BE_FUNCTION: "Subscriber listener must be a function or Subscriber object",
|
|
110
114
|
/**
|
|
111
115
|
* Error thrown when accessing a pending async computed without a default value.
|
|
112
116
|
*/
|
|
@@ -119,6 +123,14 @@ const l = {
|
|
|
119
123
|
* Error thrown when an asynchronous computed computation fails.
|
|
120
124
|
*/
|
|
121
125
|
COMPUTED_ASYNC_COMPUTATION_FAILED: "Async computed computation failed",
|
|
126
|
+
/**
|
|
127
|
+
* Error thrown when a circular dependency is detected during computation.
|
|
128
|
+
*/
|
|
129
|
+
COMPUTED_CIRCULAR_DEPENDENCY: "Circular dependency detected during computation",
|
|
130
|
+
/**
|
|
131
|
+
* Error thrown when subscribing to a dependency fails.
|
|
132
|
+
*/
|
|
133
|
+
COMPUTED_DEPENDENCY_SUBSCRIPTION_FAILED: "Failed to subscribe to dependency",
|
|
122
134
|
// ─────────────────────────────────────────────────────────────────
|
|
123
135
|
// Atom errors
|
|
124
136
|
// ─────────────────────────────────────────────────────────────────
|
|
@@ -126,6 +138,10 @@ const l = {
|
|
|
126
138
|
* Error thrown when atom.subscribe() receives an invalid listener.
|
|
127
139
|
*/
|
|
128
140
|
ATOM_SUBSCRIBER_MUST_BE_FUNCTION: "Subscription listener must be a function or Subscriber object",
|
|
141
|
+
/**
|
|
142
|
+
* Error thrown when the atom subscriber notification process fails.
|
|
143
|
+
*/
|
|
144
|
+
ATOM_SUBSCRIBER_EXECUTION_FAILED: "Error occurred while executing atom subscribers",
|
|
129
145
|
/**
|
|
130
146
|
* Error logged when an individual subscriber throws during notification.
|
|
131
147
|
* @remarks This error is caught and logged to prevent cascading failures.
|
|
@@ -146,24 +162,48 @@ const l = {
|
|
|
146
162
|
* Error thrown when an effect's cleanup function fails.
|
|
147
163
|
*/
|
|
148
164
|
EFFECT_CLEANUP_FAILED: "Effect cleanup function execution failed",
|
|
165
|
+
/**
|
|
166
|
+
* Error thrown when attempting to run a disposed effect.
|
|
167
|
+
*/
|
|
168
|
+
EFFECT_DISPOSED: "Cannot run a disposed effect",
|
|
169
|
+
// ─────────────────────────────────────────────────────────────────
|
|
170
|
+
// Debug warnings
|
|
171
|
+
// ─────────────────────────────────────────────────────────────────
|
|
172
|
+
/**
|
|
173
|
+
* Warning message for large dependency graphs.
|
|
174
|
+
*
|
|
175
|
+
* @param count - The number of dependencies detected
|
|
176
|
+
* @returns Formatted warning message with dependency count
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* console.warn(ERROR_MESSAGES.LARGE_DEPENDENCY_GRAPH(150));
|
|
181
|
+
* // Output: "Large dependency graph detected: 150 dependencies"
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
LARGE_DEPENDENCY_GRAPH: (i) => `Large dependency graph detected: ${i} dependencies`,
|
|
185
|
+
/**
|
|
186
|
+
* Warning logged when attempting to unsubscribe a non-existent listener.
|
|
187
|
+
*/
|
|
188
|
+
UNSUBSCRIBE_NON_EXISTENT: "Attempted to unsubscribe a non-existent listener",
|
|
149
189
|
/**
|
|
150
190
|
* Error logged when the onError callback itself throws an error.
|
|
151
191
|
* @remarks This prevents cascading failures from masking the original error.
|
|
152
192
|
*/
|
|
153
193
|
CALLBACK_ERROR_IN_ERROR_HANDLER: "Error occurred during onError callback execution"
|
|
154
|
-
}, w = /* @__PURE__ */ Symbol("debugName"),
|
|
155
|
-
function
|
|
156
|
-
return "dependencies" in
|
|
194
|
+
}, w = /* @__PURE__ */ Symbol("debugName"), oe = /* @__PURE__ */ Symbol("id"), k = /* @__PURE__ */ Symbol("type"), Y = /* @__PURE__ */ Symbol("noDefaultValue");
|
|
195
|
+
function ce(i) {
|
|
196
|
+
return "dependencies" in i && Array.isArray(i.dependencies);
|
|
157
197
|
}
|
|
158
|
-
let
|
|
159
|
-
function K(
|
|
160
|
-
if (
|
|
161
|
-
if (
|
|
162
|
-
throw new
|
|
163
|
-
if (
|
|
164
|
-
const s =
|
|
165
|
-
for (let
|
|
166
|
-
const r = s[
|
|
198
|
+
let q = 0;
|
|
199
|
+
function K(i, e, t) {
|
|
200
|
+
if (i._visitedEpoch !== t) {
|
|
201
|
+
if (i._visitedEpoch = t, i === e)
|
|
202
|
+
throw new R("Indirect circular dependency detected");
|
|
203
|
+
if (ce(i)) {
|
|
204
|
+
const s = i.dependencies;
|
|
205
|
+
for (let n = 0; n < s.length; n++) {
|
|
206
|
+
const r = s[n];
|
|
167
207
|
r && K(r, e, t);
|
|
168
208
|
}
|
|
169
209
|
}
|
|
@@ -173,45 +213,45 @@ const I = {
|
|
|
173
213
|
enabled: typeof process < "u" && process.env?.NODE_ENV === "development",
|
|
174
214
|
maxDependencies: G.MAX_DEPENDENCIES,
|
|
175
215
|
warnInfiniteLoop: G.WARN_INFINITE_LOOP,
|
|
176
|
-
warn(
|
|
177
|
-
this.enabled &&
|
|
216
|
+
warn(i, e) {
|
|
217
|
+
this.enabled && i && console.warn(`[Atom Effect] ${e}`);
|
|
178
218
|
},
|
|
179
219
|
/**
|
|
180
220
|
* Checks for circular dependencies.
|
|
181
221
|
* Direct check runs always; indirect check only in dev mode.
|
|
182
222
|
* @throws {ComputedError} When circular dependency detected
|
|
183
223
|
*/
|
|
184
|
-
checkCircular(
|
|
185
|
-
if (
|
|
186
|
-
throw new
|
|
187
|
-
this.enabled && (
|
|
224
|
+
checkCircular(i, e) {
|
|
225
|
+
if (i === e)
|
|
226
|
+
throw new R("Direct circular dependency detected");
|
|
227
|
+
this.enabled && (q++, K(i, e, q));
|
|
188
228
|
},
|
|
189
|
-
attachDebugInfo(
|
|
229
|
+
attachDebugInfo(i, e, t) {
|
|
190
230
|
if (!this.enabled)
|
|
191
231
|
return;
|
|
192
|
-
const s =
|
|
193
|
-
s[w] = `${e}_${t}`, s[
|
|
232
|
+
const s = i;
|
|
233
|
+
s[w] = `${e}_${t}`, s[oe] = t, s[k] = e;
|
|
194
234
|
},
|
|
195
|
-
getDebugName(
|
|
196
|
-
if (
|
|
197
|
-
return
|
|
235
|
+
getDebugName(i) {
|
|
236
|
+
if (i != null && w in i)
|
|
237
|
+
return i[w];
|
|
198
238
|
},
|
|
199
|
-
getDebugType(
|
|
200
|
-
if (
|
|
201
|
-
return
|
|
239
|
+
getDebugType(i) {
|
|
240
|
+
if (i != null && k in i)
|
|
241
|
+
return i[k];
|
|
202
242
|
}
|
|
203
243
|
};
|
|
204
|
-
let
|
|
205
|
-
const
|
|
244
|
+
let he = 1;
|
|
245
|
+
const ue = () => he++;
|
|
206
246
|
class W {
|
|
207
247
|
constructor() {
|
|
208
|
-
this.flags = 0, this.version = 0, this._lastSeenEpoch = -1, this._modifiedAtEpoch = -1, this._visitedEpoch = -1, this.id =
|
|
248
|
+
this.flags = 0, this.version = 0, this._lastSeenEpoch = -1, this._modifiedAtEpoch = -1, this._visitedEpoch = -1, this.id = ue() & A, this._tempUnsub = void 0;
|
|
209
249
|
}
|
|
210
250
|
/**
|
|
211
251
|
* Calculates the logical distance (shift) between current and cached version.
|
|
212
252
|
*/
|
|
213
253
|
getShift(e) {
|
|
214
|
-
return this.version - e &
|
|
254
|
+
return this.version - e & A;
|
|
215
255
|
}
|
|
216
256
|
}
|
|
217
257
|
class Z extends W {
|
|
@@ -223,11 +263,11 @@ class Z extends W {
|
|
|
223
263
|
return this._addSubscriber(
|
|
224
264
|
this._fnSubs,
|
|
225
265
|
e,
|
|
226
|
-
|
|
266
|
+
g.HAS_FN_SUBS
|
|
227
267
|
);
|
|
228
268
|
if (e !== null && typeof e == "object" && "execute" in e)
|
|
229
|
-
return this._addSubscriber(this._objSubs, e,
|
|
230
|
-
throw new
|
|
269
|
+
return this._addSubscriber(this._objSubs, e, g.HAS_OBJ_SUBS);
|
|
270
|
+
throw new C(l.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
|
|
231
271
|
}
|
|
232
272
|
/**
|
|
233
273
|
* Gets the total number of active subscribers.
|
|
@@ -240,8 +280,11 @@ class Z extends W {
|
|
|
240
280
|
* Uses swap-and-pop for efficient removals.
|
|
241
281
|
*/
|
|
242
282
|
_addSubscriber(e, t, s) {
|
|
243
|
-
if (e.indexOf(t) !== -1)
|
|
244
|
-
|
|
283
|
+
if (e.indexOf(t) !== -1)
|
|
284
|
+
return E && console.warn(
|
|
285
|
+
"Attempted to subscribe the same listener twice. Ignoring duplicate subscription."
|
|
286
|
+
), () => {
|
|
287
|
+
};
|
|
245
288
|
e.push(t), this.flags |= s;
|
|
246
289
|
let r = !1;
|
|
247
290
|
return () => {
|
|
@@ -258,9 +301,9 @@ class Z extends W {
|
|
|
258
301
|
* Notifies all subscribers of a change.
|
|
259
302
|
*/
|
|
260
303
|
_notifySubscribers(e, t) {
|
|
261
|
-
const s = this.flags,
|
|
262
|
-
if (s &
|
|
263
|
-
if (s &
|
|
304
|
+
const s = this.flags, n = g.HAS_FN_SUBS | g.HAS_OBJ_SUBS;
|
|
305
|
+
if (s & n) {
|
|
306
|
+
if (s & g.HAS_FN_SUBS) {
|
|
264
307
|
const r = this._fnSubs;
|
|
265
308
|
for (let o = 0, c = r.length; o < c; o++) {
|
|
266
309
|
const h = r[o];
|
|
@@ -269,12 +312,12 @@ class Z extends W {
|
|
|
269
312
|
h(e, t);
|
|
270
313
|
} catch (_) {
|
|
271
314
|
console.error(
|
|
272
|
-
new
|
|
315
|
+
new C(l.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED, _)
|
|
273
316
|
);
|
|
274
317
|
}
|
|
275
318
|
}
|
|
276
319
|
}
|
|
277
|
-
if (s &
|
|
320
|
+
if (s & g.HAS_OBJ_SUBS) {
|
|
278
321
|
const r = this._objSubs;
|
|
279
322
|
for (let o = 0, c = r.length; o < c; o++) {
|
|
280
323
|
const h = r[o];
|
|
@@ -283,7 +326,7 @@ class Z extends W {
|
|
|
283
326
|
h.execute();
|
|
284
327
|
} catch (_) {
|
|
285
328
|
console.error(
|
|
286
|
-
new
|
|
329
|
+
new C(l.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED, _)
|
|
287
330
|
);
|
|
288
331
|
}
|
|
289
332
|
}
|
|
@@ -291,24 +334,24 @@ class Z extends W {
|
|
|
291
334
|
}
|
|
292
335
|
}
|
|
293
336
|
}
|
|
294
|
-
class
|
|
337
|
+
class _e {
|
|
295
338
|
constructor() {
|
|
296
|
-
this.acquired = 0, this.released = 0, this.rejected = new
|
|
339
|
+
this.acquired = 0, this.released = 0, this.rejected = new le();
|
|
297
340
|
}
|
|
298
341
|
}
|
|
299
|
-
class
|
|
342
|
+
class le {
|
|
300
343
|
constructor() {
|
|
301
344
|
this.frozen = 0, this.tooLarge = 0, this.poolFull = 0;
|
|
302
345
|
}
|
|
303
346
|
}
|
|
304
|
-
class
|
|
347
|
+
class z {
|
|
305
348
|
constructor() {
|
|
306
|
-
this.pool = [], this.maxPoolSize = 50, this.maxReusableCapacity = 256, this.stats =
|
|
349
|
+
this.pool = [], this.maxPoolSize = 50, this.maxReusableCapacity = 256, this.stats = E ? new _e() : null;
|
|
307
350
|
}
|
|
308
351
|
/** Acquires an array from the pool or creates a new one if the pool is empty. */
|
|
309
352
|
acquire() {
|
|
310
353
|
const e = this.stats;
|
|
311
|
-
return
|
|
354
|
+
return E && e && e.acquired++, this.pool.pop() ?? [];
|
|
312
355
|
}
|
|
313
356
|
/**
|
|
314
357
|
* Releases an array back to the pool.
|
|
@@ -317,31 +360,31 @@ class k {
|
|
|
317
360
|
release(e, t) {
|
|
318
361
|
if (t && e === t || Object.isFrozen(e)) {
|
|
319
362
|
const c = this.stats;
|
|
320
|
-
|
|
363
|
+
E && c && e !== t && c.rejected.frozen++;
|
|
321
364
|
return;
|
|
322
365
|
}
|
|
323
|
-
const s = e.length,
|
|
366
|
+
const s = e.length, n = this.pool, r = n.length;
|
|
324
367
|
if (s > this.maxReusableCapacity || r >= this.maxPoolSize) {
|
|
325
368
|
const c = this.stats;
|
|
326
|
-
|
|
369
|
+
E && c && (s > this.maxReusableCapacity ? c.rejected.tooLarge++ : c.rejected.poolFull++);
|
|
327
370
|
return;
|
|
328
371
|
}
|
|
329
|
-
e.length = 0,
|
|
372
|
+
e.length = 0, n.push(e);
|
|
330
373
|
const o = this.stats;
|
|
331
|
-
|
|
374
|
+
E && o && o.released++;
|
|
332
375
|
}
|
|
333
376
|
/** Returns current stats for the pool (dev mode only). */
|
|
334
377
|
getStats() {
|
|
335
378
|
const e = this.stats;
|
|
336
|
-
if (!
|
|
337
|
-
const { acquired: t, released: s, rejected:
|
|
379
|
+
if (!E || !e) return null;
|
|
380
|
+
const { acquired: t, released: s, rejected: n } = e, r = n.frozen + n.tooLarge + n.poolFull;
|
|
338
381
|
return {
|
|
339
382
|
acquired: t,
|
|
340
383
|
released: s,
|
|
341
384
|
rejected: {
|
|
342
|
-
frozen:
|
|
343
|
-
tooLarge:
|
|
344
|
-
poolFull:
|
|
385
|
+
frozen: n.frozen,
|
|
386
|
+
tooLarge: n.tooLarge,
|
|
387
|
+
poolFull: n.poolFull
|
|
345
388
|
},
|
|
346
389
|
leaked: t - s - r,
|
|
347
390
|
poolSize: this.pool.length
|
|
@@ -351,76 +394,71 @@ class k {
|
|
|
351
394
|
reset() {
|
|
352
395
|
this.pool.length = 0;
|
|
353
396
|
const e = this.stats;
|
|
354
|
-
|
|
397
|
+
E && e && (e.acquired = 0, e.released = 0, e.rejected.frozen = 0, e.rejected.tooLarge = 0, e.rejected.poolFull = 0);
|
|
355
398
|
}
|
|
356
399
|
}
|
|
357
|
-
const
|
|
358
|
-
function
|
|
400
|
+
const d = Object.freeze([]), O = Object.freeze([]), p = Object.freeze([]), x = new z(), U = new z(), D = new z();
|
|
401
|
+
function N(i, e, t, s) {
|
|
359
402
|
if (e != null) {
|
|
360
403
|
if ((typeof e == "object" || typeof e == "function") && typeof e.addDependency == "function") {
|
|
361
|
-
e.addDependency(
|
|
404
|
+
e.addDependency(i);
|
|
362
405
|
return;
|
|
363
406
|
}
|
|
364
407
|
if (typeof e == "function") {
|
|
365
|
-
const
|
|
366
|
-
t.indexOf(
|
|
408
|
+
const n = e;
|
|
409
|
+
t.indexOf(n) === -1 && (t.push(n), i.flags |= g.HAS_FN_SUBS);
|
|
367
410
|
return;
|
|
368
411
|
}
|
|
369
|
-
typeof e == "object" && typeof e.execute == "function" && s.indexOf(e) === -1 && (s.push(e),
|
|
412
|
+
typeof e == "object" && typeof e.execute == "function" && s.indexOf(e) === -1 && (s.push(e), i.flags |= g.HAS_OBJ_SUBS);
|
|
370
413
|
}
|
|
371
414
|
}
|
|
372
|
-
function
|
|
373
|
-
const
|
|
415
|
+
function Q(i, e, t, s) {
|
|
416
|
+
const n = i.length, r = e.length, o = e !== d && r > 0;
|
|
374
417
|
if (o)
|
|
375
418
|
for (let h = 0; h < r; h++) {
|
|
376
419
|
const _ = e[h];
|
|
377
420
|
_ && (_._tempUnsub = t[h]);
|
|
378
421
|
}
|
|
379
422
|
const c = U.acquire();
|
|
380
|
-
c.length =
|
|
381
|
-
for (let h = 0; h <
|
|
382
|
-
const _ =
|
|
423
|
+
c.length = n;
|
|
424
|
+
for (let h = 0; h < n; h++) {
|
|
425
|
+
const _ = i[h];
|
|
383
426
|
if (!_) continue;
|
|
384
|
-
const
|
|
385
|
-
|
|
427
|
+
const a = _._tempUnsub;
|
|
428
|
+
a ? (c[h] = a, _._tempUnsub = void 0) : (I.checkCircular(_, s), c[h] = _.subscribe(s));
|
|
386
429
|
}
|
|
387
430
|
if (o)
|
|
388
431
|
for (let h = 0; h < r; h++) {
|
|
389
432
|
const _ = e[h];
|
|
390
433
|
if (_) {
|
|
391
|
-
const
|
|
392
|
-
|
|
434
|
+
const a = _._tempUnsub;
|
|
435
|
+
a && (a(), _._tempUnsub = void 0);
|
|
393
436
|
}
|
|
394
437
|
}
|
|
395
|
-
return t !==
|
|
438
|
+
return t !== O && U.release(t), c;
|
|
396
439
|
}
|
|
397
|
-
let
|
|
440
|
+
let v = 0;
|
|
398
441
|
function ee() {
|
|
399
|
-
return
|
|
442
|
+
return v = v + 1 & A || 1, v;
|
|
400
443
|
}
|
|
401
|
-
function
|
|
402
|
-
return
|
|
444
|
+
function ae() {
|
|
445
|
+
return v;
|
|
403
446
|
}
|
|
404
447
|
let H = 0, j = 0, L = !1;
|
|
405
448
|
function J() {
|
|
406
|
-
return L ? (
|
|
449
|
+
return L ? (E && console.warn(
|
|
407
450
|
"Warning: startFlush() called during flush - ignored to prevent infinite loop detection bypass"
|
|
408
|
-
), !1) : (L = !0, H = H + 1 &
|
|
451
|
+
), !1) : (L = !0, H = H + 1 & A || 1, j = 0, !0);
|
|
409
452
|
}
|
|
410
453
|
function $() {
|
|
411
454
|
L = !1;
|
|
412
455
|
}
|
|
413
|
-
function
|
|
456
|
+
function fe() {
|
|
414
457
|
return L ? ++j : 0;
|
|
415
458
|
}
|
|
416
|
-
class
|
|
459
|
+
class Ee {
|
|
417
460
|
constructor() {
|
|
418
|
-
this.
|
|
419
|
-
[[], []],
|
|
420
|
-
// Normal [0][0], [0][1]
|
|
421
|
-
[[], []]
|
|
422
|
-
// Urgent [1][0], [1][1]
|
|
423
|
-
], this._bufferIndices = new Uint8Array(2), this._sizes = new Uint32Array(2), this._activeQueues = [this._queueBuffers[0][0], this._queueBuffers[1][0]], this._epoch = 0, this.isProcessing = !1, this.isBatching = !1, this.batchDepth = 0, this.batchQueue = [], this.batchQueueSize = 0, this.isFlushingSync = !1, this.maxFlushIterations = A.MAX_FLUSH_ITERATIONS;
|
|
461
|
+
this._queueBuffer = [[], []], this._bufferIndex = 0, this._size = 0, this._epoch = 0, this.isProcessing = !1, this.isBatching = !1, this.batchDepth = 0, this.batchQueue = [], this.batchQueueSize = 0, this.isFlushingSync = !1, this.maxFlushIterations = T.MAX_FLUSH_ITERATIONS;
|
|
424
462
|
}
|
|
425
463
|
/**
|
|
426
464
|
* Returns the current operational phase of the scheduler.
|
|
@@ -428,57 +466,37 @@ class pe {
|
|
|
428
466
|
get phase() {
|
|
429
467
|
return this.isProcessing || this.isFlushingSync ? 2 : this.isBatching ? 1 : 0;
|
|
430
468
|
}
|
|
431
|
-
/** Current number of pending
|
|
469
|
+
/** Current number of pending jobs. */
|
|
432
470
|
get queueSize() {
|
|
433
|
-
return this.
|
|
434
|
-
}
|
|
435
|
-
/** Current number of pending urgent jobs. */
|
|
436
|
-
get urgentQueueSize() {
|
|
437
|
-
return this._sizes[1];
|
|
471
|
+
return this._size;
|
|
438
472
|
}
|
|
439
473
|
/**
|
|
440
|
-
* Schedules a task for execution
|
|
474
|
+
* Schedules a task for execution.
|
|
441
475
|
*/
|
|
442
|
-
schedule(e
|
|
443
|
-
if (typeof e != "function")
|
|
444
|
-
throw new
|
|
445
|
-
const
|
|
446
|
-
if (e._nextEpoch
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
476
|
+
schedule(e) {
|
|
477
|
+
if (E && typeof e != "function")
|
|
478
|
+
throw new P("Scheduler callback must be a function");
|
|
479
|
+
const t = this._epoch;
|
|
480
|
+
if (e._nextEpoch !== t) {
|
|
481
|
+
if (e._nextEpoch = t, this.isBatching || this.isFlushingSync) {
|
|
482
|
+
this.batchQueue[this.batchQueueSize++] = e;
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
this._queueBuffer[this._bufferIndex][this._size++] = e, this.isProcessing || this.flush();
|
|
450
486
|
}
|
|
451
|
-
const i = this._calculateUrgency(e, t);
|
|
452
|
-
this._activeQueues[i][this._sizes[i]++] = e, this.isProcessing || this.flush();
|
|
453
487
|
}
|
|
454
488
|
/**
|
|
455
|
-
*
|
|
456
|
-
*
|
|
457
|
-
* Logic:
|
|
458
|
-
* 1. Calculate the 'shift' (rotation distance) from the cached version.
|
|
459
|
-
* 2. Compare against PHASE_THRESHOLD (180° rotation equivalent).
|
|
460
|
-
* 3. Use (N >>> 31) to extract the sign bit in O(1) time.
|
|
461
|
-
*
|
|
462
|
-
* @returns 1 if urgent (shift >= PHASE_THRESHOLD), 0 otherwise.
|
|
463
|
-
*/
|
|
464
|
-
_calculateUrgency(e, t) {
|
|
465
|
-
if (!t || e._cachedVersion === void 0)
|
|
466
|
-
return 0;
|
|
467
|
-
const s = t.getShift(e._cachedVersion);
|
|
468
|
-
return z - 1 - s >>> 31 & 1;
|
|
469
|
-
}
|
|
470
|
-
/**
|
|
471
|
-
* Schedules a microtask-based flush of the queues.
|
|
489
|
+
* Schedules a microtask-based flush of the queue.
|
|
472
490
|
* Coalesces multiple schedule calls into a single microtask execution.
|
|
473
491
|
*/
|
|
474
492
|
flush() {
|
|
475
|
-
this.isProcessing || this.
|
|
493
|
+
this.isProcessing || this._size === 0 || (this.isProcessing = !0, queueMicrotask(() => {
|
|
476
494
|
try {
|
|
477
|
-
if (this.
|
|
495
|
+
if (this._size === 0) return;
|
|
478
496
|
const e = J();
|
|
479
497
|
this._drainQueue(), e && $();
|
|
480
498
|
} finally {
|
|
481
|
-
this.isProcessing = !1,
|
|
499
|
+
this.isProcessing = !1, this._size > 0 && !this.isBatching && this.flush();
|
|
482
500
|
}
|
|
483
501
|
}));
|
|
484
502
|
}
|
|
@@ -496,49 +514,49 @@ class pe {
|
|
|
496
514
|
}
|
|
497
515
|
}
|
|
498
516
|
/**
|
|
499
|
-
* Merges jobs from the batching queue into the primary
|
|
500
|
-
* Increments the epoch
|
|
517
|
+
* Merges jobs from the batching queue into the primary queue.
|
|
518
|
+
* Increments the epoch to ensure deduplication.
|
|
501
519
|
*/
|
|
502
520
|
_mergeBatchQueue() {
|
|
503
521
|
const e = this.batchQueueSize;
|
|
504
522
|
if (e === 0) return;
|
|
505
|
-
const t = ++this._epoch, s = this.batchQueue,
|
|
506
|
-
let r = this.
|
|
523
|
+
const t = ++this._epoch, s = this.batchQueue, n = this._queueBuffer[this._bufferIndex];
|
|
524
|
+
let r = this._size;
|
|
507
525
|
for (let o = 0; o < e; o++) {
|
|
508
526
|
const c = s[o];
|
|
509
|
-
c._nextEpoch !== t && (c._nextEpoch = t,
|
|
527
|
+
c._nextEpoch !== t && (c._nextEpoch = t, n[r++] = c);
|
|
510
528
|
}
|
|
511
|
-
this.
|
|
529
|
+
this._size = r, this.batchQueueSize = 0, s.length > T.BATCH_QUEUE_SHRINK_THRESHOLD && (s.length = 0);
|
|
512
530
|
}
|
|
513
531
|
_drainQueue() {
|
|
514
532
|
let e = 0;
|
|
515
533
|
const t = this.maxFlushIterations;
|
|
516
|
-
for (; this.
|
|
534
|
+
for (; this._size > 0; ) {
|
|
517
535
|
if (++e > t) {
|
|
518
536
|
this._handleFlushOverflow();
|
|
519
537
|
return;
|
|
520
538
|
}
|
|
521
|
-
this.
|
|
539
|
+
this._processQueue(), this._mergeBatchQueue();
|
|
522
540
|
}
|
|
523
541
|
}
|
|
524
|
-
_processQueue(
|
|
525
|
-
const
|
|
526
|
-
this.
|
|
542
|
+
_processQueue() {
|
|
543
|
+
const e = this._bufferIndex, t = this._queueBuffer[e], s = this._size, n = e ^ 1;
|
|
544
|
+
this._bufferIndex = n, this._size = 0, this._epoch++, this._processJobs(t, s);
|
|
527
545
|
}
|
|
528
546
|
_handleFlushOverflow() {
|
|
529
547
|
console.error(
|
|
530
|
-
new
|
|
548
|
+
new P(
|
|
531
549
|
`Maximum flush iterations (${this.maxFlushIterations}) exceeded. Possible infinite loop.`
|
|
532
550
|
)
|
|
533
|
-
), this.
|
|
551
|
+
), this._size = 0, this._queueBuffer[this._bufferIndex].length = 0, this.batchQueueSize = 0;
|
|
534
552
|
}
|
|
535
553
|
_processJobs(e, t) {
|
|
536
554
|
for (let s = 0; s < t; s++)
|
|
537
555
|
try {
|
|
538
556
|
e[s]();
|
|
539
|
-
} catch (
|
|
557
|
+
} catch (n) {
|
|
540
558
|
console.error(
|
|
541
|
-
new
|
|
559
|
+
new P("Error occurred during scheduler execution", n)
|
|
542
560
|
);
|
|
543
561
|
}
|
|
544
562
|
e.length = 0;
|
|
@@ -547,18 +565,22 @@ class pe {
|
|
|
547
565
|
this.batchDepth++, this.isBatching = !0;
|
|
548
566
|
}
|
|
549
567
|
endBatch() {
|
|
550
|
-
|
|
568
|
+
if (this.batchDepth === 0) {
|
|
569
|
+
E && console.warn("endBatch() called without matching startBatch(). Ignoring.");
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
this.batchDepth--, this.batchDepth === 0 && (this.flushSync(), this.isBatching = !1);
|
|
551
573
|
}
|
|
552
574
|
setMaxFlushIterations(e) {
|
|
553
|
-
if (e <
|
|
554
|
-
throw new
|
|
555
|
-
`Max flush iterations must be at least ${
|
|
575
|
+
if (e < T.MIN_FLUSH_ITERATIONS)
|
|
576
|
+
throw new P(
|
|
577
|
+
`Max flush iterations must be at least ${T.MIN_FLUSH_ITERATIONS}`
|
|
556
578
|
);
|
|
557
579
|
this.maxFlushIterations = e;
|
|
558
580
|
}
|
|
559
581
|
}
|
|
560
|
-
const
|
|
561
|
-
class
|
|
582
|
+
const F = new Ee();
|
|
583
|
+
class de {
|
|
562
584
|
constructor() {
|
|
563
585
|
this.current = null;
|
|
564
586
|
}
|
|
@@ -585,28 +607,28 @@ class Se {
|
|
|
585
607
|
return this.current;
|
|
586
608
|
}
|
|
587
609
|
}
|
|
588
|
-
const
|
|
589
|
-
function
|
|
590
|
-
if (typeof
|
|
591
|
-
throw new
|
|
592
|
-
const e =
|
|
593
|
-
|
|
610
|
+
const f = new de();
|
|
611
|
+
function pe(i) {
|
|
612
|
+
if (typeof i != "function")
|
|
613
|
+
throw new C("Untracked callback must be a function");
|
|
614
|
+
const e = f.current;
|
|
615
|
+
f.current = null;
|
|
594
616
|
try {
|
|
595
|
-
return
|
|
617
|
+
return i();
|
|
596
618
|
} finally {
|
|
597
|
-
|
|
619
|
+
f.current = e;
|
|
598
620
|
}
|
|
599
621
|
}
|
|
600
|
-
class
|
|
622
|
+
class Se extends Z {
|
|
601
623
|
constructor(e, t) {
|
|
602
|
-
super(), this._value = e, this._pendingOldValue = void 0, this._notifyTask = void 0, this._fnSubs = [], this._objSubs = [], t && (this.flags |=
|
|
624
|
+
super(), this._value = e, this._pendingOldValue = void 0, this._notifyTask = void 0, this._fnSubs = [], this._objSubs = [], t && (this.flags |= b.SYNC), I.attachDebugInfo(this, "atom", this.id);
|
|
603
625
|
}
|
|
604
626
|
/**
|
|
605
627
|
* Returns the current value and registers the atom as a dependency if in a tracking context.
|
|
606
628
|
*/
|
|
607
629
|
get value() {
|
|
608
|
-
const e =
|
|
609
|
-
return e &&
|
|
630
|
+
const e = f.current;
|
|
631
|
+
return e && N(this, e, this._fnSubs, this._objSubs), this._value;
|
|
610
632
|
}
|
|
611
633
|
/**
|
|
612
634
|
* Sets a new value and schedules notifications if the value has changed.
|
|
@@ -614,30 +636,31 @@ class be extends Z {
|
|
|
614
636
|
set value(e) {
|
|
615
637
|
const t = this._value;
|
|
616
638
|
if (Object.is(t, e)) return;
|
|
617
|
-
this._value = e, this.version = this.version + 1 &
|
|
618
|
-
const s = this.flags,
|
|
619
|
-
s &
|
|
639
|
+
this._value = e, this.version = this.version + 1 & A;
|
|
640
|
+
const s = this.flags, n = b.HAS_FN_SUBS | b.HAS_OBJ_SUBS;
|
|
641
|
+
s & n && this._scheduleNotification(t);
|
|
620
642
|
}
|
|
621
643
|
/**
|
|
622
644
|
* Schedules or flushes notifications based on sync mode and batching state.
|
|
623
645
|
*/
|
|
624
646
|
_scheduleNotification(e) {
|
|
625
647
|
let t = this.flags;
|
|
626
|
-
if (t &
|
|
648
|
+
if (t & b.NOTIFICATION_SCHEDULED || (this._pendingOldValue = e, this.flags = t |= b.NOTIFICATION_SCHEDULED), t & b.SYNC && !F.isBatching) {
|
|
627
649
|
this._flushNotifications();
|
|
628
650
|
return;
|
|
629
651
|
}
|
|
630
652
|
let s = this._notifyTask;
|
|
631
|
-
s || (s = this._notifyTask = () => this._flushNotifications()),
|
|
653
|
+
s || (s = this._notifyTask = () => this._flushNotifications()), F.schedule(s);
|
|
632
654
|
}
|
|
633
655
|
/**
|
|
634
656
|
* Flushes scheduled notifications and resets state for the next cycle.
|
|
635
657
|
*/
|
|
636
658
|
_flushNotifications() {
|
|
637
|
-
|
|
659
|
+
const e = this.flags;
|
|
660
|
+
if (!(e & b.NOTIFICATION_SCHEDULED) || e & b.DISPOSED)
|
|
638
661
|
return;
|
|
639
|
-
const
|
|
640
|
-
this._pendingOldValue = void 0, this.flags &= -17, this._notifySubscribers(
|
|
662
|
+
const t = this._pendingOldValue, s = this._value;
|
|
663
|
+
this._pendingOldValue = void 0, this.flags &= -17, this._notifySubscribers(s, t);
|
|
641
664
|
}
|
|
642
665
|
/**
|
|
643
666
|
* Returns the current value without registering it as a dependency.
|
|
@@ -649,46 +672,46 @@ class be extends Z {
|
|
|
649
672
|
* Disposes of the atom and releases all subscribers and tasks.
|
|
650
673
|
*/
|
|
651
674
|
dispose() {
|
|
652
|
-
this.flags &
|
|
675
|
+
this.flags & b.DISPOSED || (this._fnSubs = [], this._objSubs = [], this.flags |= b.DISPOSED, this._value = void 0, this._pendingOldValue = void 0, this._notifyTask = void 0);
|
|
653
676
|
}
|
|
654
677
|
}
|
|
655
|
-
function
|
|
656
|
-
return new
|
|
678
|
+
function Ce(i, e = {}) {
|
|
679
|
+
return new Se(i, e.sync ?? !1);
|
|
657
680
|
}
|
|
658
|
-
function m(
|
|
659
|
-
if (
|
|
660
|
-
return new e(`Type error (${t}): ${
|
|
661
|
-
if (
|
|
662
|
-
return new e(`Reference error (${t}): ${
|
|
663
|
-
if (
|
|
664
|
-
return
|
|
665
|
-
const s =
|
|
666
|
-
return new e(`Unexpected error (${t}): ${s}`,
|
|
681
|
+
function m(i, e, t) {
|
|
682
|
+
if (i instanceof TypeError)
|
|
683
|
+
return new e(`Type error (${t}): ${i.message}`, i);
|
|
684
|
+
if (i instanceof ReferenceError)
|
|
685
|
+
return new e(`Reference error (${t}): ${i.message}`, i);
|
|
686
|
+
if (i instanceof C)
|
|
687
|
+
return i;
|
|
688
|
+
const s = i instanceof Error ? i.message : String(i), n = i instanceof Error ? i : null;
|
|
689
|
+
return new e(`Unexpected error (${t}): ${s}`, n);
|
|
667
690
|
}
|
|
668
|
-
function
|
|
669
|
-
return
|
|
691
|
+
function ge(i) {
|
|
692
|
+
return i !== null && typeof i == "object" && "value" in i && "subscribe" in i && typeof i.subscribe == "function";
|
|
670
693
|
}
|
|
671
|
-
function
|
|
672
|
-
if (I.enabled &&
|
|
673
|
-
const e = I.getDebugType(
|
|
694
|
+
function Ne(i) {
|
|
695
|
+
if (I.enabled && i != null && typeof i == "object") {
|
|
696
|
+
const e = I.getDebugType(i);
|
|
674
697
|
if (e)
|
|
675
698
|
return e === "computed";
|
|
676
699
|
}
|
|
677
|
-
return
|
|
700
|
+
return ge(i) && "invalidate" in i && typeof i.invalidate == "function";
|
|
678
701
|
}
|
|
679
|
-
function
|
|
680
|
-
return
|
|
702
|
+
function Re(i) {
|
|
703
|
+
return i !== null && typeof i == "object" && "dispose" in i && "run" in i && typeof i.dispose == "function" && typeof i.run == "function";
|
|
681
704
|
}
|
|
682
|
-
function te(
|
|
683
|
-
return
|
|
705
|
+
function te(i) {
|
|
706
|
+
return i != null && typeof i.then == "function";
|
|
684
707
|
}
|
|
685
708
|
const se = u.RESOLVED | u.PENDING | u.REJECTED, V = Array(se + 1).fill(M.IDLE);
|
|
686
709
|
V[u.RESOLVED] = M.RESOLVED;
|
|
687
710
|
V[u.PENDING] = M.PENDING;
|
|
688
711
|
V[u.REJECTED] = M.REJECTED;
|
|
689
|
-
class
|
|
712
|
+
class be {
|
|
690
713
|
constructor(e) {
|
|
691
|
-
this._owner = e, this._epoch = -1, this._nextDeps =
|
|
714
|
+
this._owner = e, this._epoch = -1, this._nextDeps = d, this._nextVersions = p, this._depCount = 0;
|
|
692
715
|
}
|
|
693
716
|
execute() {
|
|
694
717
|
this._owner._markDirty();
|
|
@@ -697,18 +720,18 @@ class De {
|
|
|
697
720
|
if (e._lastSeenEpoch === this._epoch)
|
|
698
721
|
return;
|
|
699
722
|
e._lastSeenEpoch = this._epoch;
|
|
700
|
-
const t = this._depCount, s = this._nextDeps,
|
|
701
|
-
t < s.length ? (s[t] = e,
|
|
723
|
+
const t = this._depCount, s = this._nextDeps, n = this._nextVersions;
|
|
724
|
+
t < s.length ? (s[t] = e, n[t] = e.version) : (s.push(e), n.push(e.version)), this._depCount = t + 1;
|
|
702
725
|
}
|
|
703
726
|
reset() {
|
|
704
|
-
this._epoch = -1, this._nextDeps =
|
|
727
|
+
this._epoch = -1, this._nextDeps = d, this._nextVersions = p, this._depCount = 0;
|
|
705
728
|
}
|
|
706
729
|
}
|
|
707
730
|
class ie extends Z {
|
|
708
731
|
constructor(e, t = {}) {
|
|
709
732
|
if (typeof e != "function")
|
|
710
|
-
throw new
|
|
711
|
-
if (super(), this.MAX_ASYNC_RETRIES = 3, this._value = void 0, this.flags = u.DIRTY | u.IDLE, this._error = null, this._promiseId = 0, this._equal = t.equal ?? Object.is, this._fn = e, this._defaultValue = "defaultValue" in t ? t.defaultValue :
|
|
733
|
+
throw new R(l.COMPUTED_MUST_BE_FUNCTION);
|
|
734
|
+
if (super(), this.MAX_ASYNC_RETRIES = 3, this._value = void 0, this.flags = u.DIRTY | u.IDLE, this._error = null, this._promiseId = 0, this._equal = t.equal ?? Object.is, this._fn = e, this._defaultValue = "defaultValue" in t ? t.defaultValue : Y, this._hasDefaultValue = this._defaultValue !== Y, this._onError = t.onError ?? null, this.MAX_PROMISE_ID = Number.MAX_SAFE_INTEGER - 1, this._fnSubs = [], this._objSubs = [], this._dependencies = d, this._dependencyVersions = p, this._unsubscribes = O, this._cachedErrors = null, this._errorCacheEpoch = -1, this._asyncStartAggregateVersion = 0, this._asyncRetryCount = 0, this._trackable = new be(this), I.attachDebugInfo(this, "computed", this.id), I.enabled) {
|
|
712
735
|
const s = this;
|
|
713
736
|
s.subscriberCount = this.subscriberCount.bind(this), s.isDirty = () => (this.flags & u.DIRTY) !== 0, s.dependencies = this._dependencies, s.stateFlags = "";
|
|
714
737
|
}
|
|
@@ -719,10 +742,13 @@ class ie extends Z {
|
|
|
719
742
|
}
|
|
720
743
|
}
|
|
721
744
|
get value() {
|
|
722
|
-
const e =
|
|
723
|
-
e &&
|
|
745
|
+
const e = f.current;
|
|
746
|
+
e && N(this, e, this._fnSubs, this._objSubs);
|
|
724
747
|
const t = this.flags;
|
|
725
|
-
if (t & u.RECOMPUTING)
|
|
748
|
+
if (t & u.RECOMPUTING) {
|
|
749
|
+
if (this._hasDefaultValue) return this._defaultValue;
|
|
750
|
+
throw new R(l.COMPUTED_CIRCULAR_DEPENDENCY);
|
|
751
|
+
}
|
|
726
752
|
t & (u.DIRTY | u.IDLE) && this._recompute();
|
|
727
753
|
const s = this.flags;
|
|
728
754
|
return s & u.PENDING ? this._handlePending() : s & u.REJECTED ? this._handleRejected() : this._value;
|
|
@@ -731,15 +757,15 @@ class ie extends Z {
|
|
|
731
757
|
return this._value;
|
|
732
758
|
}
|
|
733
759
|
get state() {
|
|
734
|
-
const e =
|
|
735
|
-
return e &&
|
|
760
|
+
const e = f.current;
|
|
761
|
+
return e && N(this, e, this._fnSubs, this._objSubs), V[this.flags & se];
|
|
736
762
|
}
|
|
737
763
|
get hasError() {
|
|
738
|
-
const e =
|
|
739
|
-
if (e &&
|
|
764
|
+
const e = f.current;
|
|
765
|
+
if (e && N(this, e, this._fnSubs, this._objSubs), this.flags & (u.REJECTED | u.HAS_ERROR)) return !0;
|
|
740
766
|
const s = this._dependencies;
|
|
741
|
-
for (let
|
|
742
|
-
const o = s[
|
|
767
|
+
for (let n = 0, r = s.length; n < r; n++) {
|
|
768
|
+
const o = s[n];
|
|
743
769
|
if (o && o.flags & u.HAS_ERROR) return !0;
|
|
744
770
|
}
|
|
745
771
|
return !1;
|
|
@@ -748,20 +774,20 @@ class ie extends Z {
|
|
|
748
774
|
return !this.hasError;
|
|
749
775
|
}
|
|
750
776
|
get errors() {
|
|
751
|
-
const e =
|
|
752
|
-
if (e &&
|
|
753
|
-
const t =
|
|
777
|
+
const e = f.current;
|
|
778
|
+
if (e && N(this, e, this._fnSubs, this._objSubs), !this.hasError) return re;
|
|
779
|
+
const t = ae();
|
|
754
780
|
if (this._errorCacheEpoch === t && this._cachedErrors !== null)
|
|
755
781
|
return this._cachedErrors;
|
|
756
782
|
const s = /* @__PURE__ */ new Set();
|
|
757
783
|
this._error && s.add(this._error);
|
|
758
|
-
const
|
|
759
|
-
for (let o = 0, c =
|
|
760
|
-
const h =
|
|
784
|
+
const n = this._dependencies;
|
|
785
|
+
for (let o = 0, c = n.length; o < c; o++) {
|
|
786
|
+
const h = n[o];
|
|
761
787
|
if (h && "errors" in h) {
|
|
762
788
|
const _ = h.errors;
|
|
763
|
-
for (let
|
|
764
|
-
const X = _[
|
|
789
|
+
for (let a = 0, B = _.length; a < B; a++) {
|
|
790
|
+
const X = _[a];
|
|
765
791
|
X && s.add(X);
|
|
766
792
|
}
|
|
767
793
|
}
|
|
@@ -770,35 +796,35 @@ class ie extends Z {
|
|
|
770
796
|
return this._cachedErrors = r, this._errorCacheEpoch = t, r;
|
|
771
797
|
}
|
|
772
798
|
get lastError() {
|
|
773
|
-
const e =
|
|
774
|
-
return e &&
|
|
799
|
+
const e = f.current;
|
|
800
|
+
return e && N(this, e, this._fnSubs, this._objSubs), this._error;
|
|
775
801
|
}
|
|
776
802
|
get isPending() {
|
|
777
|
-
const e =
|
|
778
|
-
return e &&
|
|
803
|
+
const e = f.current;
|
|
804
|
+
return e && N(this, e, this._fnSubs, this._objSubs), (this.flags & u.PENDING) !== 0;
|
|
779
805
|
}
|
|
780
806
|
get isResolved() {
|
|
781
|
-
const e =
|
|
782
|
-
return e &&
|
|
807
|
+
const e = f.current;
|
|
808
|
+
return e && N(this, e, this._fnSubs, this._objSubs), (this.flags & u.RESOLVED) !== 0;
|
|
783
809
|
}
|
|
784
810
|
invalidate() {
|
|
785
811
|
this._markDirty();
|
|
786
812
|
const e = this._dependencyVersions;
|
|
787
|
-
e !== p && (
|
|
813
|
+
e !== p && (D.release(e), this._dependencyVersions = p), this._errorCacheEpoch = -1, this._cachedErrors = null;
|
|
788
814
|
}
|
|
789
815
|
dispose() {
|
|
790
816
|
const e = this._unsubscribes;
|
|
791
|
-
if (e !==
|
|
792
|
-
for (let
|
|
793
|
-
const o = e[
|
|
817
|
+
if (e !== O) {
|
|
818
|
+
for (let n = 0, r = e.length; n < r; n++) {
|
|
819
|
+
const o = e[n];
|
|
794
820
|
o && o();
|
|
795
821
|
}
|
|
796
|
-
U.release(e), this._unsubscribes =
|
|
822
|
+
U.release(e), this._unsubscribes = O;
|
|
797
823
|
}
|
|
798
824
|
const t = this._dependencies;
|
|
799
|
-
t !==
|
|
825
|
+
t !== d && (x.release(t), this._dependencies = d);
|
|
800
826
|
const s = this._dependencyVersions;
|
|
801
|
-
s !== p && (
|
|
827
|
+
s !== p && (D.release(s), this._dependencyVersions = p), this._fnSubs = [], this._objSubs = [], this.flags = u.DISPOSED | u.DIRTY | u.IDLE, this._error = null, this._value = void 0, this._promiseId = (this._promiseId + 1) % this.MAX_PROMISE_ID, this._cachedErrors = null, this._errorCacheEpoch = -1;
|
|
802
828
|
}
|
|
803
829
|
_clearDirty() {
|
|
804
830
|
this.flags &= -9;
|
|
@@ -827,52 +853,39 @@ class ie extends Z {
|
|
|
827
853
|
return;
|
|
828
854
|
this._setRecomputing(!0);
|
|
829
855
|
const e = this._trackable, t = this._dependencies, s = this._dependencyVersions;
|
|
830
|
-
e._epoch = ee(), e._nextDeps =
|
|
831
|
-
let
|
|
856
|
+
e._epoch = ee(), e._nextDeps = x.acquire(), e._nextVersions = D.acquire(), e._depCount = 0;
|
|
857
|
+
let n = !1;
|
|
832
858
|
try {
|
|
833
|
-
const r =
|
|
834
|
-
o.length = h, c.length = h, this._unsubscribes =
|
|
859
|
+
const r = f.run(e, this._fn), o = e._nextDeps, c = e._nextVersions, h = e._depCount;
|
|
860
|
+
o.length = h, c.length = h, this._unsubscribes = Q(o, t, this._unsubscribes, this), this._dependencies = o, this._dependencyVersions = c, n = !0, te(r) ? this._handleAsyncComputation(r) : this._finalizeResolution(r);
|
|
835
861
|
} catch (r) {
|
|
836
862
|
let o = r;
|
|
837
|
-
if (!
|
|
863
|
+
if (!n)
|
|
838
864
|
try {
|
|
839
865
|
const c = e._nextDeps, h = e._nextVersions, _ = e._depCount;
|
|
840
|
-
c.length = _, h.length = _, this._unsubscribes =
|
|
866
|
+
c.length = _, h.length = _, this._unsubscribes = Q(c, t, this._unsubscribes, this), this._dependencies = c, this._dependencyVersions = h, n = !0;
|
|
841
867
|
} catch (c) {
|
|
842
868
|
o = c;
|
|
843
869
|
}
|
|
844
870
|
this._handleComputationError(o);
|
|
845
871
|
} finally {
|
|
846
|
-
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
_getAggregateShift() {
|
|
850
|
-
let e = 0;
|
|
851
|
-
const t = this._dependencies, s = this._dependencyVersions;
|
|
852
|
-
for (let i = 0, r = t.length; i < r; i++) {
|
|
853
|
-
const o = t[i], c = s[i];
|
|
854
|
-
o && c !== void 0 && (e = e + o.getShift(c) & b);
|
|
872
|
+
n ? (t !== d && x.release(t), s !== p && D.release(s)) : (x.release(e._nextDeps), D.release(e._nextVersions)), e.reset(), this._setRecomputing(!1);
|
|
855
873
|
}
|
|
856
|
-
return e;
|
|
857
|
-
}
|
|
858
|
-
isUrgent() {
|
|
859
|
-
return this._getAggregateShift() >= z;
|
|
860
874
|
}
|
|
861
875
|
_handleAsyncComputation(e) {
|
|
862
876
|
this._setPending(), this._clearDirty(), this._notifySubscribers(void 0, void 0), this._asyncStartAggregateVersion = this._captureVersionSnapshot(), this._asyncRetryCount = 0, this._promiseId = (this._promiseId + 1) % this.MAX_PROMISE_ID;
|
|
863
877
|
const t = this._promiseId;
|
|
864
878
|
e.then((s) => {
|
|
865
879
|
if (t !== this._promiseId) return;
|
|
866
|
-
|
|
867
|
-
if (z - 1 - r >>> 31 & 1) {
|
|
880
|
+
if (this._captureVersionSnapshot() !== this._asyncStartAggregateVersion) {
|
|
868
881
|
if (this._asyncRetryCount < this.MAX_ASYNC_RETRIES) {
|
|
869
882
|
this._asyncRetryCount++, this._markDirty();
|
|
870
883
|
return;
|
|
871
884
|
}
|
|
872
|
-
const
|
|
885
|
+
const o = new R(
|
|
873
886
|
`Async drift exceeded threshold after ${this.MAX_ASYNC_RETRIES} retries.`
|
|
874
887
|
);
|
|
875
|
-
this._handleAsyncRejection(
|
|
888
|
+
this._handleAsyncRejection(o);
|
|
876
889
|
return;
|
|
877
890
|
}
|
|
878
891
|
this._finalizeResolution(s), this._notifySubscribers(s, void 0);
|
|
@@ -883,43 +896,46 @@ class ie extends Z {
|
|
|
883
896
|
_captureVersionSnapshot() {
|
|
884
897
|
let e = 0;
|
|
885
898
|
const t = this._dependencies;
|
|
886
|
-
for (let s = 0,
|
|
899
|
+
for (let s = 0, n = t.length; s < n; s++) {
|
|
887
900
|
const r = t[s];
|
|
888
|
-
|
|
901
|
+
if (r) {
|
|
902
|
+
const o = r.version;
|
|
903
|
+
e = ((e << 5) - e | 0) + o & A;
|
|
904
|
+
}
|
|
889
905
|
}
|
|
890
906
|
return e;
|
|
891
907
|
}
|
|
892
908
|
_handleAsyncRejection(e) {
|
|
893
|
-
const t = m(e,
|
|
894
|
-
this.flags & u.REJECTED || (this.version = this.version + 1 &
|
|
909
|
+
const t = m(e, R, l.COMPUTED_ASYNC_COMPUTATION_FAILED);
|
|
910
|
+
this.flags & u.REJECTED || (this.version = this.version + 1 & A), this._error = t, this._setRejected(), this._clearDirty();
|
|
895
911
|
const s = this._onError;
|
|
896
912
|
if (s)
|
|
897
913
|
try {
|
|
898
914
|
s(t);
|
|
899
|
-
} catch (
|
|
900
|
-
console.error(l.CALLBACK_ERROR_IN_ERROR_HANDLER,
|
|
915
|
+
} catch (n) {
|
|
916
|
+
console.error(l.CALLBACK_ERROR_IN_ERROR_HANDLER, n);
|
|
901
917
|
}
|
|
902
918
|
this._notifySubscribers(void 0, void 0);
|
|
903
919
|
}
|
|
904
920
|
_finalizeResolution(e) {
|
|
905
|
-
(!(this.flags & u.RESOLVED) || !this._equal(this._value, e)) && (this.version = this.version + 1 &
|
|
921
|
+
(!(this.flags & u.RESOLVED) || !this._equal(this._value, e)) && (this.version = this.version + 1 & A), this._value = e, this._clearDirty(), this._setResolved(), this._error = null, this._setRecomputing(!1), this._cachedErrors = null, this._errorCacheEpoch = -1;
|
|
906
922
|
}
|
|
907
923
|
_handleComputationError(e) {
|
|
908
|
-
const t = m(e,
|
|
924
|
+
const t = m(e, R, l.COMPUTED_COMPUTATION_FAILED);
|
|
909
925
|
this._error = t, this._setRejected(), this._clearDirty(), this._setRecomputing(!1);
|
|
910
926
|
const s = this._onError;
|
|
911
927
|
if (s)
|
|
912
928
|
try {
|
|
913
929
|
s(t);
|
|
914
|
-
} catch (
|
|
915
|
-
console.error(l.CALLBACK_ERROR_IN_ERROR_HANDLER,
|
|
930
|
+
} catch (n) {
|
|
931
|
+
console.error(l.CALLBACK_ERROR_IN_ERROR_HANDLER, n);
|
|
916
932
|
}
|
|
917
933
|
throw t;
|
|
918
934
|
}
|
|
919
935
|
_handlePending() {
|
|
920
936
|
if (this._hasDefaultValue)
|
|
921
937
|
return this._defaultValue;
|
|
922
|
-
throw new
|
|
938
|
+
throw new R(l.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
|
|
923
939
|
}
|
|
924
940
|
_handleRejected() {
|
|
925
941
|
const e = this._error;
|
|
@@ -937,91 +953,105 @@ class ie extends Z {
|
|
|
937
953
|
}
|
|
938
954
|
}
|
|
939
955
|
Object.freeze(ie.prototype);
|
|
940
|
-
function
|
|
941
|
-
return new ie(
|
|
956
|
+
function Te(i, e = {}) {
|
|
957
|
+
return new ie(i, e);
|
|
942
958
|
}
|
|
943
|
-
class
|
|
959
|
+
class Ie extends W {
|
|
944
960
|
constructor(e, t = {}) {
|
|
945
|
-
super(), this._cleanup = null, this._dependencies =
|
|
946
|
-
const s = Number.isFinite(this._maxExecutions),
|
|
947
|
-
this._historyCapacity =
|
|
961
|
+
super(), this._cleanup = null, this._dependencies = d, this._dependencyVersions = p, this._unsubscribes = O, this._nextDeps = null, this._nextVersions = null, this._nextUnsubs = null, this._executeTask = void 0, this._onError = t.onError ?? null, this._currentEpoch = -1, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._fn = e, this._sync = t.sync ?? !1, this._maxExecutions = t.maxExecutionsPerSecond ?? T.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = t.maxExecutionsPerFlush ?? T.MAX_EXECUTIONS_PER_EFFECT, this._trackModifications = t.trackModifications ?? !1, this._executionCount = 0, this._historyPtr = 0;
|
|
962
|
+
const s = Number.isFinite(this._maxExecutions), n = s ? Math.min(this._maxExecutions + 1, T.MAX_EXECUTIONS_PER_SECOND + 1) : 0;
|
|
963
|
+
this._historyCapacity = n, this._history = E && s && n > 0 ? new Array(n).fill(0) : null, this._execId = 0, I.attachDebugInfo(this, "effect", this.id);
|
|
948
964
|
}
|
|
949
965
|
run() {
|
|
950
|
-
if (this.flags &
|
|
951
|
-
throw new
|
|
966
|
+
if (this.flags & S.DISPOSED)
|
|
967
|
+
throw new y(l.EFFECT_DISPOSED);
|
|
952
968
|
this.execute(!0);
|
|
953
969
|
}
|
|
954
970
|
dispose() {
|
|
955
971
|
const e = this.flags;
|
|
956
|
-
if (e &
|
|
957
|
-
this.flags = e |
|
|
972
|
+
if (e & S.DISPOSED) return;
|
|
973
|
+
this.flags = e | S.DISPOSED, this._safeCleanup();
|
|
958
974
|
const t = this._unsubscribes;
|
|
959
|
-
if (t !==
|
|
975
|
+
if (t !== O) {
|
|
960
976
|
for (let r = 0, o = t.length; r < o; r++) {
|
|
961
977
|
const c = t[r];
|
|
962
978
|
c && c();
|
|
963
979
|
}
|
|
964
|
-
U.release(t), this._unsubscribes =
|
|
980
|
+
U.release(t), this._unsubscribes = O;
|
|
965
981
|
}
|
|
966
982
|
const s = this._dependencies;
|
|
967
|
-
s !==
|
|
968
|
-
const
|
|
969
|
-
|
|
983
|
+
s !== d && (x.release(s), this._dependencies = d);
|
|
984
|
+
const n = this._dependencyVersions;
|
|
985
|
+
n !== p && (D.release(n), this._dependencyVersions = p), this._executeTask = void 0;
|
|
970
986
|
}
|
|
971
987
|
addDependency(e) {
|
|
972
|
-
if (!(this.flags &
|
|
988
|
+
if (!(this.flags & S.EXECUTING)) return;
|
|
973
989
|
const s = this._currentEpoch;
|
|
974
990
|
if (e._lastSeenEpoch === s) return;
|
|
975
991
|
e._lastSeenEpoch = s;
|
|
976
|
-
const
|
|
977
|
-
if (!
|
|
978
|
-
|
|
992
|
+
const n = this._nextDeps, r = this._nextVersions, o = this._nextUnsubs;
|
|
993
|
+
if (!n || !r || !o) return;
|
|
994
|
+
n.push(e), r.push(e.version);
|
|
979
995
|
const c = e._tempUnsub;
|
|
980
996
|
c ? (o.push(c), e._tempUnsub = void 0) : this._subscribeTo(e);
|
|
981
997
|
}
|
|
982
998
|
execute(e = !1) {
|
|
983
|
-
if (this.flags & (
|
|
999
|
+
if (this.flags & (S.DISPOSED | S.EXECUTING) || !e && !this._shouldExecute()) return;
|
|
984
1000
|
this._checkInfiniteLoop(), this._setExecuting(!0), this._safeCleanup();
|
|
985
1001
|
const s = this._prepareEffectExecutionContext();
|
|
986
|
-
let
|
|
1002
|
+
let n = !1;
|
|
987
1003
|
try {
|
|
988
|
-
const r =
|
|
989
|
-
s.nextDeps.length = o, s.nextVersions.length = o, this._dependencies = s.nextDeps, this._dependencyVersions = s.nextVersions, this._unsubscribes = s.nextUnsubs,
|
|
990
|
-
|
|
991
|
-
|
|
1004
|
+
const r = f.run(this, this._fn), o = s.nextDeps.length;
|
|
1005
|
+
s.nextDeps.length = o, s.nextVersions.length = o, this._dependencies = s.nextDeps, this._dependencyVersions = s.nextVersions, this._unsubscribes = s.nextUnsubs, n = !0, this._checkLoopWarnings();
|
|
1006
|
+
const c = ++this._execId;
|
|
1007
|
+
te(r) ? r.then((h) => {
|
|
1008
|
+
const _ = c !== this._execId, a = this.flags & S.DISPOSED;
|
|
1009
|
+
if (_ || a) {
|
|
1010
|
+
if (typeof h == "function")
|
|
1011
|
+
try {
|
|
1012
|
+
h();
|
|
1013
|
+
} catch (B) {
|
|
1014
|
+
this._handleExecutionError(B, l.EFFECT_CLEANUP_FAILED);
|
|
1015
|
+
}
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1018
|
+
typeof h == "function" && (this._cleanup = h);
|
|
1019
|
+
}).catch((h) => {
|
|
1020
|
+
c === this._execId && this._handleExecutionError(h);
|
|
1021
|
+
}) : this._cleanup = typeof r == "function" ? r : null;
|
|
992
1022
|
} catch (r) {
|
|
993
|
-
|
|
1023
|
+
n = !0, this._handleExecutionError(r), this._cleanup = null;
|
|
994
1024
|
} finally {
|
|
995
|
-
this._cleanupEffect(s,
|
|
1025
|
+
this._cleanupEffect(s, n), this._setExecuting(!1);
|
|
996
1026
|
}
|
|
997
1027
|
}
|
|
998
1028
|
_prepareEffectExecutionContext() {
|
|
999
|
-
const e = this._dependencies, t = this._dependencyVersions, s = this._unsubscribes,
|
|
1000
|
-
if (e !==
|
|
1029
|
+
const e = this._dependencies, t = this._dependencyVersions, s = this._unsubscribes, n = x.acquire(), r = D.acquire(), o = U.acquire(), c = ee();
|
|
1030
|
+
if (e !== d)
|
|
1001
1031
|
for (let h = 0, _ = e.length; h < _; h++) {
|
|
1002
|
-
const
|
|
1003
|
-
|
|
1032
|
+
const a = e[h];
|
|
1033
|
+
a && (a._tempUnsub = s[h]);
|
|
1004
1034
|
}
|
|
1005
|
-
return this._nextDeps =
|
|
1035
|
+
return this._nextDeps = n, this._nextVersions = r, this._nextUnsubs = o, this._currentEpoch = c, { prevDeps: e, prevVersions: t, prevUnsubs: s, nextDeps: n, nextVersions: r, nextUnsubs: o };
|
|
1006
1036
|
}
|
|
1007
1037
|
_cleanupEffect(e, t) {
|
|
1008
1038
|
this._nextDeps = null, this._nextVersions = null, this._nextUnsubs = null;
|
|
1009
1039
|
const s = e.prevDeps;
|
|
1010
1040
|
if (t) {
|
|
1011
|
-
if (s !==
|
|
1012
|
-
for (let
|
|
1013
|
-
const o = s[
|
|
1041
|
+
if (s !== d) {
|
|
1042
|
+
for (let n = 0, r = s.length; n < r; n++) {
|
|
1043
|
+
const o = s[n], c = o ? o._tempUnsub : void 0;
|
|
1014
1044
|
c && (c(), o && (o._tempUnsub = void 0));
|
|
1015
1045
|
}
|
|
1016
|
-
|
|
1046
|
+
x.release(s);
|
|
1017
1047
|
}
|
|
1018
|
-
e.prevUnsubs !==
|
|
1048
|
+
e.prevUnsubs !== O && U.release(e.prevUnsubs), e.prevVersions !== p && D.release(e.prevVersions);
|
|
1019
1049
|
} else {
|
|
1020
|
-
|
|
1021
|
-
const
|
|
1022
|
-
for (let r = 0, o =
|
|
1023
|
-
|
|
1024
|
-
if (U.release(
|
|
1050
|
+
x.release(e.nextDeps), D.release(e.nextVersions);
|
|
1051
|
+
const n = e.nextUnsubs;
|
|
1052
|
+
for (let r = 0, o = n.length; r < o; r++)
|
|
1053
|
+
n[r]?.();
|
|
1054
|
+
if (U.release(n), s !== d)
|
|
1025
1055
|
for (let r = 0, o = s.length; r < o; r++) {
|
|
1026
1056
|
const c = s[r];
|
|
1027
1057
|
c && (c._tempUnsub = void 0);
|
|
@@ -1031,35 +1061,32 @@ class Ce extends W {
|
|
|
1031
1061
|
_subscribeTo(e) {
|
|
1032
1062
|
try {
|
|
1033
1063
|
const t = e.subscribe(() => {
|
|
1034
|
-
if (this._trackModifications && this.flags &
|
|
1064
|
+
if (this._trackModifications && this.flags & S.EXECUTING && (e._modifiedAtEpoch = this._currentEpoch), this._sync) {
|
|
1035
1065
|
this.execute();
|
|
1036
1066
|
return;
|
|
1037
1067
|
}
|
|
1038
|
-
let
|
|
1039
|
-
|
|
1068
|
+
let n = this._executeTask;
|
|
1069
|
+
n || (n = this._executeTask = () => this.execute()), F.schedule(n);
|
|
1040
1070
|
}), s = this._nextUnsubs;
|
|
1041
1071
|
s && s.push(t);
|
|
1042
1072
|
} catch (t) {
|
|
1043
|
-
console.error(m(t,
|
|
1073
|
+
console.error(m(t, y, l.EFFECT_EXECUTION_FAILED));
|
|
1044
1074
|
const s = this._nextUnsubs;
|
|
1045
1075
|
s && s.push(() => {
|
|
1046
1076
|
});
|
|
1047
1077
|
}
|
|
1048
1078
|
}
|
|
1049
1079
|
get isDisposed() {
|
|
1050
|
-
return (this.flags &
|
|
1080
|
+
return (this.flags & S.DISPOSED) !== 0;
|
|
1051
1081
|
}
|
|
1052
1082
|
get executionCount() {
|
|
1053
1083
|
return this._executionCount;
|
|
1054
1084
|
}
|
|
1055
1085
|
get isExecuting() {
|
|
1056
|
-
return (this.flags &
|
|
1057
|
-
}
|
|
1058
|
-
_setDisposed() {
|
|
1059
|
-
this.flags |= d.DISPOSED;
|
|
1086
|
+
return (this.flags & S.EXECUTING) !== 0;
|
|
1060
1087
|
}
|
|
1061
1088
|
_setExecuting(e) {
|
|
1062
|
-
const t =
|
|
1089
|
+
const t = S.EXECUTING;
|
|
1063
1090
|
this.flags = this.flags & ~t | (e ? -1 : 0) & t;
|
|
1064
1091
|
}
|
|
1065
1092
|
_safeCleanup() {
|
|
@@ -1068,31 +1095,32 @@ class Ce extends W {
|
|
|
1068
1095
|
try {
|
|
1069
1096
|
e();
|
|
1070
1097
|
} catch (t) {
|
|
1071
|
-
|
|
1098
|
+
this._handleExecutionError(t, l.EFFECT_CLEANUP_FAILED);
|
|
1072
1099
|
}
|
|
1073
1100
|
this._cleanup = null;
|
|
1074
1101
|
}
|
|
1075
1102
|
}
|
|
1076
1103
|
_checkInfiniteLoop() {
|
|
1077
1104
|
const e = H;
|
|
1078
|
-
this._lastFlushEpoch !== e && (this._lastFlushEpoch = e, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"),
|
|
1105
|
+
this._lastFlushEpoch !== e && (this._lastFlushEpoch = e, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), fe() > T.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++;
|
|
1079
1106
|
const s = this._history;
|
|
1080
1107
|
if (s) {
|
|
1081
|
-
const
|
|
1082
|
-
s[r] =
|
|
1108
|
+
const n = Date.now(), r = this._historyPtr, o = this._historyCapacity;
|
|
1109
|
+
s[r] = n;
|
|
1083
1110
|
const c = (r + 1) % o;
|
|
1084
1111
|
this._historyPtr = c;
|
|
1085
1112
|
const h = s[c] ?? 0;
|
|
1086
|
-
if (h > 0 &&
|
|
1087
|
-
const _ = new
|
|
1113
|
+
if (h > 0 && n - h < ne.ONE_SECOND_MS) {
|
|
1114
|
+
const _ = new y(
|
|
1088
1115
|
`Effect executed ${o} times within 1 second. Infinite loop suspected`
|
|
1089
1116
|
);
|
|
1090
|
-
if (this.dispose(), console.error(_), this._onError && this._onError(_),
|
|
1117
|
+
if (this.dispose(), console.error(_), this._onError && this._onError(_), E) throw _;
|
|
1118
|
+
return;
|
|
1091
1119
|
}
|
|
1092
1120
|
}
|
|
1093
1121
|
}
|
|
1094
1122
|
_throwInfiniteLoopError(e) {
|
|
1095
|
-
const t = new
|
|
1123
|
+
const t = new y(
|
|
1096
1124
|
`Infinite loop detected (${e}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${j}`
|
|
1097
1125
|
);
|
|
1098
1126
|
throw this.dispose(), console.error(t), t;
|
|
@@ -1101,13 +1129,13 @@ class Ce extends W {
|
|
|
1101
1129
|
const e = this._dependencies;
|
|
1102
1130
|
if (e.length === 0) return !0;
|
|
1103
1131
|
const t = this._dependencyVersions;
|
|
1104
|
-
for (let s = 0,
|
|
1132
|
+
for (let s = 0, n = e.length; s < n; s++) {
|
|
1105
1133
|
const r = e[s];
|
|
1106
1134
|
if (r) {
|
|
1107
1135
|
if (r.version !== t[s]) return !0;
|
|
1108
1136
|
if ("value" in r)
|
|
1109
1137
|
try {
|
|
1110
|
-
|
|
1138
|
+
pe(() => r.value);
|
|
1111
1139
|
} catch {
|
|
1112
1140
|
return !0;
|
|
1113
1141
|
}
|
|
@@ -1115,16 +1143,21 @@ class Ce extends W {
|
|
|
1115
1143
|
}
|
|
1116
1144
|
return !1;
|
|
1117
1145
|
}
|
|
1118
|
-
_handleExecutionError(e) {
|
|
1119
|
-
const
|
|
1120
|
-
console.error(
|
|
1121
|
-
const
|
|
1122
|
-
|
|
1146
|
+
_handleExecutionError(e, t = l.EFFECT_EXECUTION_FAILED) {
|
|
1147
|
+
const s = m(e, y, t);
|
|
1148
|
+
console.error(s);
|
|
1149
|
+
const n = this._onError;
|
|
1150
|
+
if (n)
|
|
1151
|
+
try {
|
|
1152
|
+
n(s);
|
|
1153
|
+
} catch (r) {
|
|
1154
|
+
console.error(m(r, y, l.CALLBACK_ERROR_IN_ERROR_HANDLER));
|
|
1155
|
+
}
|
|
1123
1156
|
}
|
|
1124
1157
|
_checkLoopWarnings() {
|
|
1125
1158
|
if (this._trackModifications && I.enabled) {
|
|
1126
1159
|
const e = this._dependencies, t = this._currentEpoch;
|
|
1127
|
-
for (let s = 0,
|
|
1160
|
+
for (let s = 0, n = e.length; s < n; s++) {
|
|
1128
1161
|
const r = e[s];
|
|
1129
1162
|
r && r._modifiedAtEpoch === t && I.warn(
|
|
1130
1163
|
!0,
|
|
@@ -1134,40 +1167,40 @@ class Ce extends W {
|
|
|
1134
1167
|
}
|
|
1135
1168
|
}
|
|
1136
1169
|
}
|
|
1137
|
-
function
|
|
1138
|
-
if (typeof
|
|
1139
|
-
throw new
|
|
1140
|
-
const t = new
|
|
1170
|
+
function Oe(i, e = {}) {
|
|
1171
|
+
if (typeof i != "function")
|
|
1172
|
+
throw new y(l.EFFECT_MUST_BE_FUNCTION);
|
|
1173
|
+
const t = new Ie(i, e);
|
|
1141
1174
|
return t.execute(), t;
|
|
1142
1175
|
}
|
|
1143
|
-
function xe(
|
|
1144
|
-
if (typeof
|
|
1145
|
-
throw new
|
|
1146
|
-
|
|
1176
|
+
function xe(i) {
|
|
1177
|
+
if (typeof i != "function")
|
|
1178
|
+
throw new C("Batch callback must be a function");
|
|
1179
|
+
F.startBatch();
|
|
1147
1180
|
try {
|
|
1148
|
-
return
|
|
1181
|
+
return i();
|
|
1149
1182
|
} finally {
|
|
1150
|
-
|
|
1183
|
+
F.endBatch();
|
|
1151
1184
|
}
|
|
1152
1185
|
}
|
|
1153
1186
|
export {
|
|
1154
1187
|
M as AsyncState,
|
|
1155
|
-
|
|
1156
|
-
|
|
1188
|
+
C as AtomError,
|
|
1189
|
+
R as ComputedError,
|
|
1157
1190
|
G as DEBUG_CONFIG,
|
|
1158
1191
|
I as DEBUG_RUNTIME,
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1192
|
+
y as EffectError,
|
|
1193
|
+
De as POOL_CONFIG,
|
|
1194
|
+
T as SCHEDULER_CONFIG,
|
|
1195
|
+
P as SchedulerError,
|
|
1196
|
+
Ce as atom,
|
|
1164
1197
|
xe as batch,
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1198
|
+
Te as computed,
|
|
1199
|
+
Oe as effect,
|
|
1200
|
+
ge as isAtom,
|
|
1201
|
+
Ne as isComputed,
|
|
1202
|
+
Re as isEffect,
|
|
1203
|
+
F as scheduler,
|
|
1204
|
+
pe as untracked
|
|
1172
1205
|
};
|
|
1173
1206
|
//# sourceMappingURL=index.mjs.map
|