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