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