@but212/atom-effect 0.30.1 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/atom-effect.min.js +1 -1
- package/dist/atom-effect.min.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +24 -46
- package/dist/index.mjs +522 -473
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var h = {
|
|
2
2
|
DISPOSED: 1,
|
|
3
3
|
IS_COMPUTED: 2,
|
|
4
4
|
DIRTY: 256,
|
|
@@ -12,107 +12,108 @@ var u = {
|
|
|
12
12
|
ATOM_SYNC: 16777216,
|
|
13
13
|
ATOM_NOTIFICATION_SCHEDULED: 33554432,
|
|
14
14
|
EFFECT_EXECUTING: 268435456
|
|
15
|
-
},
|
|
16
|
-
ASYNC_STATE:
|
|
17
|
-
COMPUTED_DIRTY_MASK:
|
|
18
|
-
}),
|
|
15
|
+
}, yt = Object.freeze({
|
|
16
|
+
ASYNC_STATE: h.IDLE | h.PENDING | h.RESOLVED | h.REJECTED,
|
|
17
|
+
COMPUTED_DIRTY_MASK: h.DIRTY | h.RECOMPUTING | h.FORCE_COMPUTE
|
|
18
|
+
}), P = Object.freeze({
|
|
19
19
|
IDLE: "idle",
|
|
20
20
|
PENDING: "pending",
|
|
21
21
|
RESOLVED: "resolved",
|
|
22
22
|
REJECTED: "rejected"
|
|
23
23
|
}), S = Object.freeze({
|
|
24
|
-
DISPOSED:
|
|
25
|
-
EXECUTING:
|
|
26
|
-
}),
|
|
27
|
-
DISPOSED:
|
|
28
|
-
IS_COMPUTED:
|
|
29
|
-
DIRTY:
|
|
30
|
-
IDLE:
|
|
31
|
-
PENDING:
|
|
32
|
-
RESOLVED:
|
|
33
|
-
REJECTED:
|
|
34
|
-
RECOMPUTING:
|
|
35
|
-
HAS_ERROR:
|
|
36
|
-
FORCE_COMPUTE:
|
|
37
|
-
}), f = Object.freeze({
|
|
38
|
-
DISPOSED: u.DISPOSED,
|
|
39
|
-
SYNC: u.ATOM_SYNC,
|
|
40
|
-
NOTIFICATION_SCHEDULED: u.ATOM_NOTIFICATION_SCHEDULED
|
|
24
|
+
DISPOSED: h.DISPOSED,
|
|
25
|
+
EXECUTING: h.EFFECT_EXECUTING
|
|
26
|
+
}), $ = Object.freeze({
|
|
27
|
+
DISPOSED: h.DISPOSED,
|
|
28
|
+
IS_COMPUTED: h.IS_COMPUTED,
|
|
29
|
+
DIRTY: h.DIRTY,
|
|
30
|
+
IDLE: h.IDLE,
|
|
31
|
+
PENDING: h.PENDING,
|
|
32
|
+
RESOLVED: h.RESOLVED,
|
|
33
|
+
REJECTED: h.REJECTED,
|
|
34
|
+
RECOMPUTING: h.RECOMPUTING,
|
|
35
|
+
HAS_ERROR: h.HAS_ERROR,
|
|
36
|
+
FORCE_COMPUTE: h.FORCE_COMPUTE
|
|
41
37
|
}), C = Object.freeze({
|
|
38
|
+
DISPOSED: h.DISPOSED,
|
|
39
|
+
SYNC: h.ATOM_SYNC,
|
|
40
|
+
NOTIFICATION_SCHEDULED: h.ATOM_NOTIFICATION_SCHEDULED
|
|
41
|
+
}), g = Object.freeze({
|
|
42
42
|
MAX_EXECUTIONS_PER_SECOND: 1e3,
|
|
43
43
|
MAX_EXECUTIONS_PER_EFFECT: 100,
|
|
44
44
|
MAX_EXECUTIONS_PER_FLUSH: 1e4,
|
|
45
45
|
MAX_FLUSH_ITERATIONS: 1e3,
|
|
46
46
|
MIN_FLUSH_ITERATIONS: 10,
|
|
47
47
|
BATCH_QUEUE_SHRINK_THRESHOLD: 1e3
|
|
48
|
-
}),
|
|
48
|
+
}), H = 1073741823, W = Object.freeze({
|
|
49
49
|
WARN_INFINITE_LOOP: !0,
|
|
50
50
|
EFFECT_FREQUENCY_WINDOW: 1e3,
|
|
51
51
|
LOOP_THRESHOLD: 100
|
|
52
|
-
}),
|
|
52
|
+
}), Et = Object.freeze({ MAX_PROMISE_ID: H }), U = Object.freeze({
|
|
53
53
|
UNINITIALIZED: -1,
|
|
54
54
|
MIN: 1
|
|
55
|
-
}),
|
|
55
|
+
}), ht = !1;
|
|
56
56
|
try {
|
|
57
|
-
|
|
57
|
+
ht = !!(typeof globalThis < "u" && globalThis.__ATOM_DEBUG__ || typeof sessionStorage < "u" && sessionStorage.getItem("__ATOM_DEBUG__") === "true");
|
|
58
58
|
} catch {
|
|
59
59
|
}
|
|
60
|
-
var
|
|
60
|
+
var f = (typeof process < "u" && process.env, typeof __DEV__ < "u" && !!__DEV__ || ht), it = Object.freeze([]), y = class j extends Error {
|
|
61
61
|
constructor(e, s = null, i = !0, n) {
|
|
62
62
|
super(e), this.cause = s, this.recoverable = i, this.code = n, this.name = "AtomError", Error.captureStackTrace && Error.captureStackTrace(this, this.constructor);
|
|
63
63
|
}
|
|
64
64
|
getChain() {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
if (
|
|
72
|
-
else if (i instanceof Error && "cause" in i) i = i.cause;
|
|
65
|
+
const e = this.cause;
|
|
66
|
+
if (e == null) return [this];
|
|
67
|
+
const s = [this];
|
|
68
|
+
let i = e, n = null;
|
|
69
|
+
for (; i != null && (s.push(i), !(i === this || n?.has(i))); ) {
|
|
70
|
+
if (i instanceof j) i = i.cause;
|
|
71
|
+
else if (i instanceof Error) i = i.cause;
|
|
73
72
|
else break;
|
|
73
|
+
s.length > 3 && (n === null ? n = new Set(s) : n.add(i));
|
|
74
74
|
}
|
|
75
|
-
return
|
|
75
|
+
return s;
|
|
76
76
|
}
|
|
77
|
-
toJSON(e
|
|
78
|
-
|
|
77
|
+
toJSON(e) {
|
|
78
|
+
const s = e ?? /* @__PURE__ */ new Set();
|
|
79
|
+
if (s.has(this)) return {
|
|
79
80
|
name: this.name,
|
|
80
81
|
message: "[Circular Reference]",
|
|
81
82
|
recoverable: this.recoverable,
|
|
82
83
|
code: this.code
|
|
83
84
|
};
|
|
84
|
-
|
|
85
|
-
let
|
|
86
|
-
return
|
|
87
|
-
name:
|
|
88
|
-
message:
|
|
89
|
-
stack:
|
|
90
|
-
cause:
|
|
85
|
+
s.add(this);
|
|
86
|
+
let i = this.cause;
|
|
87
|
+
return i instanceof j ? i = i.toJSON(s) : i instanceof Error && (i = {
|
|
88
|
+
name: i.name,
|
|
89
|
+
message: i.message,
|
|
90
|
+
stack: i.stack,
|
|
91
|
+
cause: i.cause
|
|
91
92
|
}), {
|
|
92
93
|
name: this.name,
|
|
93
94
|
message: this.message,
|
|
94
95
|
code: this.code,
|
|
95
96
|
recoverable: this.recoverable,
|
|
96
97
|
stack: this.stack,
|
|
97
|
-
cause:
|
|
98
|
+
cause: i
|
|
98
99
|
};
|
|
99
100
|
}
|
|
100
101
|
static format(e, s, i) {
|
|
101
102
|
return `${e} (${s}): ${i}`;
|
|
102
103
|
}
|
|
103
|
-
},
|
|
104
|
+
}, w = class extends y {
|
|
104
105
|
constructor(...t) {
|
|
105
106
|
super(...t), this.name = "ComputedError";
|
|
106
107
|
}
|
|
107
|
-
},
|
|
108
|
+
}, N = class extends y {
|
|
108
109
|
constructor(t, e = null, s = !1, i) {
|
|
109
110
|
super(t, e, s, i), this.name = "EffectError";
|
|
110
111
|
}
|
|
111
|
-
},
|
|
112
|
+
}, x = class extends y {
|
|
112
113
|
constructor(t, e = null, s = !1, i) {
|
|
113
114
|
super(t, e, s, i), this.name = "SchedulerError";
|
|
114
115
|
}
|
|
115
|
-
},
|
|
116
|
+
}, l = {
|
|
116
117
|
COMPUTED_MUST_BE_FUNCTION: "Computed target must be a function",
|
|
117
118
|
COMPUTED_ASYNC_PENDING_NO_DEFAULT: "Async computation pending with no default value",
|
|
118
119
|
COMPUTED_COMPUTATION_FAILED: "Computation execution failed",
|
|
@@ -132,39 +133,24 @@ var _ = (typeof process < "u" && process.env, typeof __DEV__ < "u" && !!__DEV__
|
|
|
132
133
|
SCHEDULER_END_BATCH_WITHOUT_START: "endBatch() called without matching startBatch(). Ignoring.",
|
|
133
134
|
BATCH_CALLBACK_MUST_BE_FUNCTION: "Batch callback must be a function"
|
|
134
135
|
};
|
|
135
|
-
function
|
|
136
|
-
|
|
137
|
-
if (t instanceof Error) {
|
|
138
|
-
const i = t.name || t.constructor.name || "Error";
|
|
139
|
-
return new e(g.format(i, s, t.message), t);
|
|
140
|
-
}
|
|
141
|
-
return new e(g.format("Unexpected error", s, String(t)), t);
|
|
136
|
+
function A(t, e, s) {
|
|
137
|
+
return t instanceof y ? new e(`${t.name} (${s}): ${t.message}`, t, t.recoverable, t.code) : t instanceof Error ? new e(`${t.name || "Error"} (${s}): ${t.message}`, t) : new e(`Unexpected error (${s}): ${String(t)}`, t);
|
|
142
138
|
}
|
|
143
|
-
var
|
|
139
|
+
var nt = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), dt = /* @__PURE__ */ Symbol("AtomEffect.Id"), rt = /* @__PURE__ */ Symbol("AtomEffect.Type"), G = /* @__PURE__ */ Symbol("AtomEffect.NoDefaultValue"), pt = "[Atom Effect]", M = () => {
|
|
140
|
+
}, It = class {
|
|
144
141
|
constructor() {
|
|
145
|
-
this.enabled = !0, this.warnInfiniteLoop =
|
|
146
|
-
this.enabled && t && console.warn(`${
|
|
142
|
+
this.enabled = !0, this.warnInfiniteLoop = W.WARN_INFINITE_LOOP, this._updateCounts = /* @__PURE__ */ new Map(), this._nodeRegistry = /* @__PURE__ */ new Map(), this._threshold = W.LOOP_THRESHOLD, this._cleanupScheduled = !1, this.warn = (t, e) => {
|
|
143
|
+
this.enabled && t && console.warn(`${pt} ${e}`);
|
|
147
144
|
}, this.registerNode = (t) => {
|
|
148
145
|
this._nodeRegistry.set(t.id, new WeakRef(t));
|
|
149
146
|
}, this.attachDebugInfo = (t, e, s, i) => {
|
|
150
|
-
this.enabled
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
configurable: !0
|
|
154
|
-
},
|
|
155
|
-
[Et]: {
|
|
156
|
-
value: s,
|
|
157
|
-
configurable: !0
|
|
158
|
-
},
|
|
159
|
-
[it]: {
|
|
160
|
-
value: e,
|
|
161
|
-
configurable: !0
|
|
162
|
-
}
|
|
163
|
-
}), this.registerNode(t));
|
|
147
|
+
if (!this.enabled) return;
|
|
148
|
+
const n = t;
|
|
149
|
+
n[nt] = i ?? `${e}_${s}`, n[dt] = s, n[rt] = e, this.registerNode(t);
|
|
164
150
|
}, this.trackUpdate = (t, e) => {
|
|
165
151
|
if (!this.enabled || !this.warnInfiniteLoop) return;
|
|
166
152
|
const s = this._updateCounts, i = (s.get(t) ?? 0) + 1;
|
|
167
|
-
i > this._threshold ? this.warn(!0, `Infinite loop detected for ${e ?? `dependency ${t}`}. Over ${this._threshold} updates in a single execution scope.`) : s.set(t, i), this._cleanupScheduled || (this._cleanupScheduled = !0,
|
|
153
|
+
i > this._threshold ? this.warn(!0, `Infinite loop detected for ${e ?? `dependency ${t}`}. Over ${this._threshold} updates in a single execution scope.`) : s.set(t, i), this._cleanupScheduled || (this._cleanupScheduled = !0, queueMicrotask(() => {
|
|
168
154
|
this._updateCounts.clear(), this._cleanupScheduled = !1;
|
|
169
155
|
}));
|
|
170
156
|
}, this.dumpGraph = () => {
|
|
@@ -180,39 +166,35 @@ var st = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), Et = /* @__PURE__ */ Sy
|
|
|
180
166
|
}
|
|
181
167
|
return t;
|
|
182
168
|
}, this.getDebugName = (t) => {
|
|
183
|
-
if (t)
|
|
184
|
-
return t[
|
|
169
|
+
if (t != null)
|
|
170
|
+
return t[nt];
|
|
185
171
|
}, this.getDebugType = (t) => {
|
|
186
|
-
if (t)
|
|
187
|
-
return t[
|
|
172
|
+
if (t != null)
|
|
173
|
+
return t[rt];
|
|
188
174
|
};
|
|
189
175
|
}
|
|
190
|
-
},
|
|
176
|
+
}, Ct = {
|
|
191
177
|
enabled: !1,
|
|
192
178
|
warnInfiniteLoop: !1,
|
|
193
|
-
warn:
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
attachDebugInfo: () => {
|
|
198
|
-
},
|
|
199
|
-
trackUpdate: () => {
|
|
200
|
-
},
|
|
179
|
+
warn: M,
|
|
180
|
+
registerNode: M,
|
|
181
|
+
attachDebugInfo: M,
|
|
182
|
+
trackUpdate: M,
|
|
201
183
|
dumpGraph: () => [],
|
|
202
184
|
getDebugName: () => {
|
|
203
185
|
},
|
|
204
186
|
getDebugType: () => {
|
|
205
187
|
}
|
|
206
|
-
}, d =
|
|
188
|
+
}, d = f ? new It() : Ct, Dt = 1, gt = () => Dt++ | 0, lt = class {
|
|
207
189
|
constructor() {
|
|
208
|
-
this.
|
|
190
|
+
this._count = 0, this._actualCount = 0, this._s0 = null, this._s1 = null, this._s2 = null, this._s3 = null, this._overflow = null, this._freeIndices = null;
|
|
209
191
|
}
|
|
210
192
|
_rawWrite(t, e) {
|
|
211
193
|
if (t < 4) t === 0 ? this._s0 = e : t === 1 ? this._s1 = e : t === 2 ? this._s2 = e : this._s3 = e;
|
|
212
194
|
else {
|
|
213
195
|
this._overflow === null && (this._overflow = []);
|
|
214
|
-
const s = this._overflow
|
|
215
|
-
s[
|
|
196
|
+
const s = this._overflow;
|
|
197
|
+
s[t - 4] = e;
|
|
216
198
|
}
|
|
217
199
|
}
|
|
218
200
|
_rawAdd(t) {
|
|
@@ -230,7 +212,7 @@ var st = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), Et = /* @__PURE__ */ Sy
|
|
|
230
212
|
const i = s.pop();
|
|
231
213
|
return e[i] = t, i + 4;
|
|
232
214
|
}
|
|
233
|
-
return e.push(t),
|
|
215
|
+
return e.push(t), 3 + e.length;
|
|
234
216
|
}
|
|
235
217
|
_rawSwap(t, e) {
|
|
236
218
|
if (t === e) return;
|
|
@@ -244,18 +226,26 @@ var st = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), Et = /* @__PURE__ */ Sy
|
|
|
244
226
|
return this._count;
|
|
245
227
|
}
|
|
246
228
|
getAt(t) {
|
|
247
|
-
|
|
229
|
+
if (t < 4)
|
|
230
|
+
return t === 0 ? this._s0 : t === 1 ? this._s1 : t === 2 ? this._s2 : t === 3 ? this._s3 : null;
|
|
231
|
+
const e = this._overflow;
|
|
232
|
+
return e === null ? null : e[t - 4] ?? null;
|
|
248
233
|
}
|
|
249
234
|
setAt(t, e) {
|
|
250
235
|
const s = this.getAt(t);
|
|
251
|
-
s !== e && (this._rawWrite(t, e), s === null ? this._actualCount++ : e === null && this._actualCount--, e !== null
|
|
236
|
+
s !== e && (this._rawWrite(t, e), s === null ? this._actualCount++ : e === null && this._actualCount--, e !== null ? t >= this._count && (this._count = t + 1) : this._shrinkPhysicalSizeFrom(t));
|
|
252
237
|
}
|
|
253
238
|
_shrinkPhysicalSizeFrom(t) {
|
|
254
|
-
if (t === this._count - 1)
|
|
255
|
-
|
|
239
|
+
if (t === this._count - 1) {
|
|
240
|
+
if (this._count--, this._count > 4) {
|
|
241
|
+
const e = this._overflow;
|
|
242
|
+
for (; this._count > 4 && e[this._count - 5] === null; ) this._count--;
|
|
243
|
+
}
|
|
244
|
+
this._count === 4 && this._s3 === null && (this._count = 3, this._s2 === null && (this._count = 2, this._s1 === null && (this._count = 1, this._s0 === null && (this._count = 0))));
|
|
245
|
+
}
|
|
256
246
|
}
|
|
257
247
|
truncateFrom(t) {
|
|
258
|
-
t <= 3 && (t <=
|
|
248
|
+
t <= 3 && (t <= 3 && this._s3 !== null && (this._onItemRemoved(this._s3), this._s3 = null, this._actualCount--), t <= 2 && this._s2 !== null && (this._onItemRemoved(this._s2), this._s2 = null, this._actualCount--), t <= 1 && this._s1 !== null && (this._onItemRemoved(this._s1), this._s1 = null, this._actualCount--), t <= 0 && this._s0 !== null && (this._onItemRemoved(this._s0), this._s0 = null, this._actualCount--));
|
|
259
249
|
const e = this._overflow;
|
|
260
250
|
if (e !== null) {
|
|
261
251
|
const s = t > 4 ? t - 4 : 0, i = e.length;
|
|
@@ -295,31 +285,37 @@ var st = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), Et = /* @__PURE__ */ Sy
|
|
|
295
285
|
const e = this._actualCount;
|
|
296
286
|
if (e === 0) return;
|
|
297
287
|
if (e === this._count) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
const c = n[r];
|
|
302
|
-
c != null && t(c);
|
|
288
|
+
if (t(this._s0), e > 1 && (t(this._s1), e > 2 && (t(this._s2), e > 3 && (t(this._s3), e > 4)))) {
|
|
289
|
+
const n = this._overflow;
|
|
290
|
+
for (let r = 0, o = n.length; r < o; r++) t(n[r]);
|
|
303
291
|
}
|
|
304
292
|
return;
|
|
305
293
|
}
|
|
306
294
|
let s = 0;
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
295
|
+
if (this._s0 !== null && (t(this._s0), ++s >= e) || this._s1 !== null && (t(this._s1), ++s >= e) || this._s2 !== null && (t(this._s2), ++s >= e) || this._s3 !== null && (t(this._s3), ++s >= e))
|
|
296
|
+
return;
|
|
297
|
+
const i = this._overflow;
|
|
298
|
+
if (i !== null) for (let n = 0, r = i.length; n < r; n++) {
|
|
299
|
+
const o = i[n];
|
|
300
|
+
if (o != null && (t(o), ++s >= e))
|
|
301
|
+
return;
|
|
312
302
|
}
|
|
313
303
|
}
|
|
314
304
|
compact() {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
305
|
+
const t = this._actualCount;
|
|
306
|
+
if (t === this._count) return;
|
|
307
|
+
if (t === 0) {
|
|
308
|
+
this.clear();
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
let e = 0;
|
|
312
|
+
const s = this._count;
|
|
313
|
+
for (let i = 0; i < s; i++) {
|
|
314
|
+
const n = this.getAt(i);
|
|
315
|
+
if (n !== null && (i !== e && (this._rawWrite(e, n), this._rawWrite(i, null)), e++, e === t))
|
|
316
|
+
break;
|
|
321
317
|
}
|
|
322
|
-
this._count =
|
|
318
|
+
this._count = t, this._overflow !== null && (e <= 4 ? this._overflow = null : this._overflow.length = e - 4), this._freeIndices = null;
|
|
323
319
|
}
|
|
324
320
|
clear() {
|
|
325
321
|
this._s0 = this._s1 = this._s2 = this._s3 = null, this._count = 0, this._actualCount = 0, this._overflow = null, this._freeIndices = null;
|
|
@@ -327,7 +323,7 @@ var st = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), Et = /* @__PURE__ */ Sy
|
|
|
327
323
|
dispose() {
|
|
328
324
|
this.clear();
|
|
329
325
|
}
|
|
330
|
-
},
|
|
326
|
+
}, ct = class extends lt {
|
|
331
327
|
constructor(...t) {
|
|
332
328
|
super(...t), this._map = null, this._SCAN_THRESHOLD = 32, this.hasComputeds = !1;
|
|
333
329
|
}
|
|
@@ -339,28 +335,41 @@ var st = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), Et = /* @__PURE__ */ Sy
|
|
|
339
335
|
}
|
|
340
336
|
setAt(t, e) {
|
|
341
337
|
const s = this.getAt(t);
|
|
342
|
-
super.setAt(t, e), this._map !== null && (s
|
|
338
|
+
super.setAt(t, e), this._map !== null && (s !== null && this._map.delete(s.node), e !== null && this._map.set(e.node, t));
|
|
343
339
|
}
|
|
344
340
|
claimExisting(t, e) {
|
|
345
341
|
const s = this._count;
|
|
346
342
|
if (s <= e) return !1;
|
|
347
|
-
|
|
348
|
-
if (i && i.node === t && i.unsub)
|
|
343
|
+
let i = null;
|
|
344
|
+
if (e < 4 ? e === 0 ? i = this._s0 : e === 1 ? i = this._s1 : e === 2 ? i = this._s2 : i = this._s3 : i = this._overflow[e - 4] ?? null, i && i.node === t && i.unsub)
|
|
349
345
|
return i.version = t.version, !0;
|
|
350
346
|
if (this._map !== null || s - e > this._SCAN_THRESHOLD) return this._claimViaMap(t, e);
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
347
|
+
let n = -1, r = null, o = e + 1;
|
|
348
|
+
for (; o < 4 && o < s; o++) {
|
|
349
|
+
const u = o === 1 ? this._s1 : o === 2 ? this._s2 : this._s3;
|
|
350
|
+
if (u && u.node === t && u.unsub) {
|
|
351
|
+
n = o, r = u;
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
355
354
|
}
|
|
356
|
-
|
|
355
|
+
if (n === -1 && o < s) {
|
|
356
|
+
const u = this._overflow;
|
|
357
|
+
for (let c = o - 4, I = s - 4; c < I; c++) {
|
|
358
|
+
const E = u[c];
|
|
359
|
+
if (E && E.node === t && E.unsub) {
|
|
360
|
+
n = c + 4, r = E;
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return n !== -1 ? (r.version = t.version, this._rawWrite(e, r), this._rawWrite(n, i), !0) : !1;
|
|
357
366
|
}
|
|
358
367
|
_claimViaMap(t, e) {
|
|
359
368
|
this._map === null && (this._map = this._initMap());
|
|
360
369
|
const s = this._map, i = s.get(t);
|
|
361
370
|
if (i === void 0 || i < e) return !1;
|
|
362
371
|
const n = this.getAt(i);
|
|
363
|
-
if (n
|
|
372
|
+
if (n === null || !n.unsub) return !1;
|
|
364
373
|
if (n.version = t.version, i !== e) {
|
|
365
374
|
const r = this.getAt(e);
|
|
366
375
|
this._rawSwap(i, e), s.set(t, e), r?.unsub && s.set(r.node, i);
|
|
@@ -369,19 +378,27 @@ var st = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), Et = /* @__PURE__ */ Sy
|
|
|
369
378
|
}
|
|
370
379
|
_initMap() {
|
|
371
380
|
const t = /* @__PURE__ */ new Map();
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
381
|
+
this._s0?.unsub && t.set(this._s0.node, 0), this._s1?.unsub && t.set(this._s1.node, 1), this._s2?.unsub && t.set(this._s2.node, 2), this._s3?.unsub && t.set(this._s3.node, 3);
|
|
382
|
+
const e = this._overflow;
|
|
383
|
+
if (e !== null) for (let s = 0, i = e.length; s < i; s++) {
|
|
384
|
+
const n = e[s];
|
|
385
|
+
n?.unsub && t.set(n.node, s + 4);
|
|
375
386
|
}
|
|
376
387
|
return t;
|
|
377
388
|
}
|
|
378
389
|
insertNew(t, e) {
|
|
379
|
-
|
|
390
|
+
let s = null;
|
|
391
|
+
if (t < 4) t === 0 ? (s = this._s0, this._s0 = e) : t === 1 ? (s = this._s1, this._s1 = e) : t === 2 ? (s = this._s2, this._s2 = e) : (s = this._s3, this._s3 = e);
|
|
392
|
+
else {
|
|
393
|
+
this._overflow === null && (this._overflow = []);
|
|
394
|
+
const i = this._overflow;
|
|
395
|
+
s = i[t - 4] ?? null, i[t - 4] = e;
|
|
396
|
+
}
|
|
380
397
|
if (s !== null) {
|
|
381
398
|
const i = this._rawAdd(s);
|
|
382
399
|
i >= this._count && (this._count = i + 1), this._map !== null && s.unsub && this._map.set(s.node, i);
|
|
383
400
|
}
|
|
384
|
-
|
|
401
|
+
t >= this._count && (this._count = t + 1), this._actualCount++, this._map !== null && e.unsub && this._map.set(e.node, t);
|
|
385
402
|
}
|
|
386
403
|
add(t) {
|
|
387
404
|
const e = super.add(t);
|
|
@@ -398,49 +415,51 @@ var st = /* @__PURE__ */ Symbol("AtomEffect.DebugName"), Et = /* @__PURE__ */ Sy
|
|
|
398
415
|
disposeAll() {
|
|
399
416
|
this.truncateFrom(0), this.hasComputeds = !1;
|
|
400
417
|
}
|
|
401
|
-
},
|
|
418
|
+
}, L = /* @__PURE__ */ Symbol.for("atom-effect/brand"), p = {
|
|
402
419
|
Atom: 1,
|
|
403
420
|
Writable: 2,
|
|
404
421
|
Computed: 4,
|
|
405
422
|
Effect: 8
|
|
406
423
|
};
|
|
407
|
-
function
|
|
408
|
-
|
|
409
|
-
const s = typeof t;
|
|
410
|
-
return (s === "object" || s === "function") && !!((t[F] ?? 0) & e);
|
|
424
|
+
function J(t, e) {
|
|
425
|
+
return !t || typeof t != "object" && typeof t != "function" ? !1 : !!(t[L] & e);
|
|
411
426
|
}
|
|
412
|
-
function
|
|
413
|
-
return
|
|
427
|
+
function wt(t) {
|
|
428
|
+
return J(t, p.Atom);
|
|
414
429
|
}
|
|
415
430
|
function Rt(t) {
|
|
416
|
-
return
|
|
431
|
+
return J(t, p.Computed);
|
|
417
432
|
}
|
|
418
|
-
function
|
|
419
|
-
return
|
|
433
|
+
function Ft(t) {
|
|
434
|
+
return J(t, p.Effect);
|
|
420
435
|
}
|
|
421
|
-
function
|
|
422
|
-
|
|
423
|
-
if (!t) return !1;
|
|
424
|
-
const e = typeof t;
|
|
425
|
-
return (e === "object" || e === "function") && typeof t.then == "function";
|
|
436
|
+
function Z(t) {
|
|
437
|
+
return t instanceof Promise ? !0 : t === null || typeof t != "object" ? !1 : typeof t.then == "function";
|
|
426
438
|
}
|
|
427
|
-
var
|
|
439
|
+
var q = class {
|
|
428
440
|
constructor(t, e, s = void 0) {
|
|
429
441
|
this.node = t, this.version = e, this.unsub = s;
|
|
430
442
|
}
|
|
431
|
-
},
|
|
443
|
+
}, St = class {
|
|
432
444
|
constructor(t = void 0, e = void 0) {
|
|
433
445
|
this.fn = t, this.sub = e;
|
|
434
446
|
}
|
|
435
447
|
notify(t, e) {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
i !== void 0 && i.execute();
|
|
441
|
-
|
|
448
|
+
const s = this.fn, i = this.sub;
|
|
449
|
+
if (s === void 0 && i === void 0) return;
|
|
450
|
+
const n = _, r = n.current;
|
|
451
|
+
if (r === null) {
|
|
452
|
+
s !== void 0 && s(t, e), i !== void 0 && i.execute();
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
n.current = null;
|
|
456
|
+
try {
|
|
457
|
+
s !== void 0 && s(t, e), i !== void 0 && i.execute();
|
|
458
|
+
} finally {
|
|
459
|
+
n.current = r;
|
|
460
|
+
}
|
|
442
461
|
}
|
|
443
|
-
},
|
|
462
|
+
}, vt = class {
|
|
444
463
|
constructor() {
|
|
445
464
|
this.current = null;
|
|
446
465
|
}
|
|
@@ -449,15 +468,16 @@ var W = class {
|
|
|
449
468
|
const s = this.current;
|
|
450
469
|
this.current = t;
|
|
451
470
|
try {
|
|
471
|
+
if (!f) return e();
|
|
452
472
|
const i = e();
|
|
453
|
-
return
|
|
473
|
+
return d.warn(Z(i), 'Detected Promise returned within tracking context. Dependencies accessed after "await" will NOT be tracked. Consider using synchronous tracking before the async boundary.'), i;
|
|
454
474
|
} finally {
|
|
455
475
|
this.current = s;
|
|
456
476
|
}
|
|
457
477
|
}
|
|
458
|
-
},
|
|
459
|
-
function
|
|
460
|
-
const e =
|
|
478
|
+
}, _ = new vt();
|
|
479
|
+
function X(t) {
|
|
480
|
+
const e = _, s = e.current;
|
|
461
481
|
if (s === null) return t();
|
|
462
482
|
e.current = null;
|
|
463
483
|
try {
|
|
@@ -466,48 +486,56 @@ function M(t) {
|
|
|
466
486
|
e.current = s;
|
|
467
487
|
}
|
|
468
488
|
}
|
|
469
|
-
var
|
|
489
|
+
var tt = class {
|
|
470
490
|
constructor() {
|
|
471
|
-
this.flags = 0, this.version = 0, this._lastSeenEpoch =
|
|
491
|
+
this.flags = 0, this.version = 0, this._lastSeenEpoch = U.UNINITIALIZED, this._notifying = 0, this._hotIndex = -1, this.id = gt() & H, this._nextEpoch = void 0, this._slots = null, this._deps = null;
|
|
472
492
|
}
|
|
473
493
|
get isDisposed() {
|
|
474
|
-
return (this.flags &
|
|
494
|
+
return (this.flags & $.DISPOSED) !== 0;
|
|
475
495
|
}
|
|
476
496
|
get isComputed() {
|
|
477
|
-
return (this.flags &
|
|
497
|
+
return (this.flags & $.IS_COMPUTED) !== 0;
|
|
478
498
|
}
|
|
479
499
|
get hasError() {
|
|
480
500
|
return !1;
|
|
481
501
|
}
|
|
482
502
|
subscribe(t) {
|
|
483
503
|
const e = typeof t == "function";
|
|
484
|
-
if (!e && (
|
|
504
|
+
if (!e && (t === null || typeof t.execute != "function")) throw A(/* @__PURE__ */ new TypeError("Invalid subscriber"), y, l.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
|
|
485
505
|
let s = this._slots;
|
|
486
|
-
s
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
506
|
+
if (s === null && (s = new lt(), this._slots = s), s.size > 0) {
|
|
507
|
+
let n = !1;
|
|
508
|
+
if (s._s0 !== null && (s._s0.fn === t || s._s0.sub === t) || s._s1 !== null && (s._s1.fn === t || s._s1.sub === t) || s._s2 !== null && (s._s2.fn === t || s._s2.sub === t) || s._s3 !== null && (s._s3.fn === t || s._s3.sub === t)) n = !0;
|
|
509
|
+
else {
|
|
510
|
+
const r = s._overflow;
|
|
511
|
+
if (r !== null) {
|
|
512
|
+
const o = r.length;
|
|
513
|
+
if (e) for (let u = 0; u < o; u++) {
|
|
514
|
+
const c = r[u];
|
|
515
|
+
if (c !== null && c?.fn === t) {
|
|
516
|
+
n = !0;
|
|
517
|
+
break;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
else for (let u = 0; u < o; u++) {
|
|
521
|
+
const c = r[u];
|
|
522
|
+
if (c !== null && c?.sub === t) {
|
|
523
|
+
n = !0;
|
|
524
|
+
break;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
499
527
|
}
|
|
500
528
|
}
|
|
529
|
+
if (n)
|
|
530
|
+
return f && console.warn(`[atom-effect] Duplicate subscription ignored on node ${this.id}`), () => {
|
|
531
|
+
};
|
|
501
532
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
};
|
|
505
|
-
const n = new Dt(e ? t : void 0, e ? void 0 : t);
|
|
506
|
-
return s.add(n), () => this._unsubscribe(n);
|
|
533
|
+
const i = new St(e ? t : void 0, e ? void 0 : t);
|
|
534
|
+
return s.add(i), () => this._unsubscribe(i);
|
|
507
535
|
}
|
|
508
536
|
_unsubscribe(t) {
|
|
509
537
|
const e = this._slots;
|
|
510
|
-
e && (e.remove(t), this._notifying === 0 && e.compact());
|
|
538
|
+
e !== null && (e.remove(t), this._notifying === 0 && e.compact());
|
|
511
539
|
}
|
|
512
540
|
subscriberCount() {
|
|
513
541
|
const t = this._slots;
|
|
@@ -518,34 +546,33 @@ var K = class {
|
|
|
518
546
|
if (!(s === null || s.size === 0)) {
|
|
519
547
|
this._notifying++;
|
|
520
548
|
try {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
this._logNotifyError(r);
|
|
549
|
+
if (s._s0 !== null) try {
|
|
550
|
+
s._s0.notify(t, e);
|
|
551
|
+
} catch (n) {
|
|
552
|
+
this._logNotifyError(n);
|
|
526
553
|
}
|
|
527
|
-
if (
|
|
528
|
-
|
|
529
|
-
} catch (
|
|
530
|
-
this._logNotifyError(
|
|
554
|
+
if (s._s1 !== null) try {
|
|
555
|
+
s._s1.notify(t, e);
|
|
556
|
+
} catch (n) {
|
|
557
|
+
this._logNotifyError(n);
|
|
531
558
|
}
|
|
532
|
-
if (
|
|
533
|
-
|
|
534
|
-
} catch (
|
|
535
|
-
this._logNotifyError(
|
|
559
|
+
if (s._s2 !== null) try {
|
|
560
|
+
s._s2.notify(t, e);
|
|
561
|
+
} catch (n) {
|
|
562
|
+
this._logNotifyError(n);
|
|
536
563
|
}
|
|
537
|
-
if (
|
|
538
|
-
|
|
539
|
-
} catch (
|
|
540
|
-
this._logNotifyError(
|
|
564
|
+
if (s._s3 !== null) try {
|
|
565
|
+
s._s3.notify(t, e);
|
|
566
|
+
} catch (n) {
|
|
567
|
+
this._logNotifyError(n);
|
|
541
568
|
}
|
|
542
|
-
const
|
|
543
|
-
if (
|
|
544
|
-
const
|
|
545
|
-
if (
|
|
546
|
-
|
|
547
|
-
} catch (
|
|
548
|
-
this._logNotifyError(
|
|
569
|
+
const i = s._overflow;
|
|
570
|
+
if (i !== null) for (let n = 0, r = i.length; n < r; n++) {
|
|
571
|
+
const o = i[n];
|
|
572
|
+
if (o !== null) try {
|
|
573
|
+
o?.notify(t, e);
|
|
574
|
+
} catch (u) {
|
|
575
|
+
this._logNotifyError(u);
|
|
549
576
|
}
|
|
550
577
|
}
|
|
551
578
|
} finally {
|
|
@@ -554,7 +581,7 @@ var K = class {
|
|
|
554
581
|
}
|
|
555
582
|
}
|
|
556
583
|
_logNotifyError(t) {
|
|
557
|
-
console.error(
|
|
584
|
+
console.error(A(t, y, l.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED));
|
|
558
585
|
}
|
|
559
586
|
_isDirty() {
|
|
560
587
|
const t = this._deps;
|
|
@@ -562,38 +589,38 @@ var K = class {
|
|
|
562
589
|
const e = this._hotIndex;
|
|
563
590
|
if (e !== -1) {
|
|
564
591
|
const s = t.getAt(e);
|
|
565
|
-
if (s
|
|
592
|
+
if (s !== null && s.node.version !== s.version) return !0;
|
|
566
593
|
}
|
|
567
594
|
return this._deepDirtyCheck();
|
|
568
595
|
}
|
|
569
|
-
},
|
|
570
|
-
function
|
|
571
|
-
const t =
|
|
572
|
-
return
|
|
596
|
+
}, Q = 0;
|
|
597
|
+
function et() {
|
|
598
|
+
const t = Q + 1 & H;
|
|
599
|
+
return Q = t === 0 ? 1 : t, Q;
|
|
573
600
|
}
|
|
574
|
-
function
|
|
575
|
-
const e = t + 1 &
|
|
601
|
+
function K(t) {
|
|
602
|
+
const e = t + 1 & H;
|
|
576
603
|
return e === 0 ? 1 : e;
|
|
577
604
|
}
|
|
578
|
-
var
|
|
605
|
+
var st = 0, B = !1, _t = 0;
|
|
579
606
|
function Tt() {
|
|
580
|
-
return
|
|
607
|
+
return _t;
|
|
581
608
|
}
|
|
582
|
-
function
|
|
583
|
-
return
|
|
609
|
+
function ot() {
|
|
610
|
+
return B ? (f && console.warn("startFlush() called during flush - ignored"), !1) : (B = !0, _t = et(), st = 0, !0);
|
|
584
611
|
}
|
|
585
|
-
function
|
|
586
|
-
|
|
612
|
+
function ut() {
|
|
613
|
+
B = !1;
|
|
587
614
|
}
|
|
588
615
|
function mt() {
|
|
589
|
-
if (!
|
|
590
|
-
const t = ++
|
|
591
|
-
if (t <=
|
|
592
|
-
throw new Error(`[atom-effect] Infinite loop detected: flush execution count exceeded ${
|
|
616
|
+
if (!B) return 0;
|
|
617
|
+
const t = ++st;
|
|
618
|
+
if (t <= g.MAX_EXECUTIONS_PER_FLUSH) return t;
|
|
619
|
+
throw new Error(`[atom-effect] Infinite loop detected: flush execution count exceeded ${g.MAX_EXECUTIONS_PER_FLUSH}`);
|
|
593
620
|
}
|
|
594
|
-
var
|
|
621
|
+
var Ot = class {
|
|
595
622
|
constructor() {
|
|
596
|
-
this.
|
|
623
|
+
this._bufferIndex = 0, this._size = 0, this._epoch = 0, this._batchDepth = 0, this._batchQueueSize = 0, this._maxFlushIterations = g.MAX_FLUSH_ITERATIONS, this._isProcessing = !1, this._isFlushingSync = !1, this._buffer0 = [], this._buffer1 = [], this._batchQueue = [], this.onOverflow = null, this._boundRunLoop = this._runLoop.bind(this);
|
|
597
624
|
}
|
|
598
625
|
get queueSize() {
|
|
599
626
|
return this._size + this._batchQueueSize;
|
|
@@ -602,25 +629,25 @@ var vt = class {
|
|
|
602
629
|
return this._batchDepth > 0;
|
|
603
630
|
}
|
|
604
631
|
schedule(t) {
|
|
605
|
-
if (
|
|
606
|
-
throw new
|
|
632
|
+
if (f && typeof t != "function" && (!t || typeof t.execute != "function"))
|
|
633
|
+
throw new x(l.SCHEDULER_CALLBACK_MUST_BE_FUNCTION);
|
|
607
634
|
const e = this._epoch;
|
|
608
635
|
if (t._nextEpoch === e) return;
|
|
609
636
|
if (t._nextEpoch = e, this._batchDepth > 0 || this._isFlushingSync) {
|
|
610
637
|
this._batchQueue[this._batchQueueSize++] = t;
|
|
611
638
|
return;
|
|
612
639
|
}
|
|
613
|
-
const s = this.
|
|
640
|
+
const s = this._bufferIndex === 0 ? this._buffer0 : this._buffer1;
|
|
614
641
|
s[this._size++] = t, this._isProcessing || this._flush();
|
|
615
642
|
}
|
|
616
643
|
_flush() {
|
|
617
|
-
this._isProcessing || this._size === 0 || (this._isProcessing = !0, queueMicrotask(this._boundRunLoop));
|
|
644
|
+
this._isProcessing || this._size === 0 && this._batchQueueSize === 0 || (this._isProcessing = !0, queueMicrotask(this._boundRunLoop));
|
|
618
645
|
}
|
|
619
646
|
_runLoop() {
|
|
620
647
|
try {
|
|
621
648
|
if (this._size === 0 && this._batchQueueSize === 0) return;
|
|
622
|
-
const t =
|
|
623
|
-
this._drainQueue(), t &&
|
|
649
|
+
const t = ot();
|
|
650
|
+
this._drainQueue(), t && ut();
|
|
624
651
|
} finally {
|
|
625
652
|
this._isProcessing = !1;
|
|
626
653
|
}
|
|
@@ -629,24 +656,23 @@ var vt = class {
|
|
|
629
656
|
if (this._size === 0 && this._batchQueueSize === 0) return;
|
|
630
657
|
const t = this._isFlushingSync;
|
|
631
658
|
this._isFlushingSync = !0;
|
|
632
|
-
const e =
|
|
659
|
+
const e = ot();
|
|
633
660
|
try {
|
|
634
661
|
this._mergeBatchQueue(), this._drainQueue();
|
|
635
662
|
} finally {
|
|
636
|
-
this._isFlushingSync = t, e &&
|
|
663
|
+
this._isFlushingSync = t, e && ut();
|
|
637
664
|
}
|
|
638
665
|
}
|
|
639
666
|
_mergeBatchQueue() {
|
|
640
667
|
const t = this._batchQueueSize;
|
|
641
668
|
if (t === 0) return;
|
|
642
|
-
this._epoch = this.
|
|
643
|
-
const e = this._epoch, s = this._batchQueue, i = this._queueBuffer[this._bufferIndex];
|
|
669
|
+
const e = ++this._epoch | 0, s = this._batchQueue, i = this._bufferIndex === 0 ? this._buffer0 : this._buffer1;
|
|
644
670
|
let n = this._size;
|
|
645
671
|
for (let r = 0; r < t; r++) {
|
|
646
672
|
const o = s[r];
|
|
647
673
|
o._nextEpoch !== e && (o._nextEpoch = e, i[n++] = o), s[r] = void 0;
|
|
648
674
|
}
|
|
649
|
-
this._size = n, this._batchQueueSize = 0, s.length >
|
|
675
|
+
this._size = n, this._batchQueueSize = 0, s.length > g.BATCH_QUEUE_SHRINK_THRESHOLD && (s.length = 0);
|
|
650
676
|
}
|
|
651
677
|
_drainQueue() {
|
|
652
678
|
let t = 0;
|
|
@@ -659,7 +685,7 @@ var vt = class {
|
|
|
659
685
|
}
|
|
660
686
|
}
|
|
661
687
|
_processQueue() {
|
|
662
|
-
const t = this._bufferIndex, e = this.
|
|
688
|
+
const t = this._bufferIndex, e = t === 0 ? this._buffer0 : this._buffer1, s = this._size;
|
|
663
689
|
this._bufferIndex = t ^ 1, this._size = 0, this._epoch = this._epoch + 1 | 0;
|
|
664
690
|
for (let i = 0; i < s; i++) {
|
|
665
691
|
const n = e[i];
|
|
@@ -667,13 +693,13 @@ var vt = class {
|
|
|
667
693
|
try {
|
|
668
694
|
typeof n == "function" ? n() : n.execute();
|
|
669
695
|
} catch (r) {
|
|
670
|
-
console.error(new
|
|
696
|
+
console.error(new x("Error occurred during scheduler execution", r));
|
|
671
697
|
}
|
|
672
698
|
}
|
|
673
699
|
}
|
|
674
700
|
_handleFlushOverflow() {
|
|
675
701
|
const t = this._size + this._batchQueueSize;
|
|
676
|
-
console.error(new
|
|
702
|
+
console.error(new x(l.SCHEDULER_FLUSH_OVERFLOW(this._maxFlushIterations, t))), this._size = 0, this._buffer0.length = 0, this._buffer1.length = 0, this._batchQueueSize = 0, this._batchQueue.length = 0;
|
|
677
703
|
const e = this.onOverflow;
|
|
678
704
|
if (e) try {
|
|
679
705
|
e(t);
|
|
@@ -685,116 +711,136 @@ var vt = class {
|
|
|
685
711
|
}
|
|
686
712
|
endBatch() {
|
|
687
713
|
if (this._batchDepth === 0) {
|
|
688
|
-
|
|
714
|
+
f && console.warn(l.SCHEDULER_END_BATCH_WITHOUT_START);
|
|
689
715
|
return;
|
|
690
716
|
}
|
|
691
717
|
--this._batchDepth === 0 && (this._isFlushingSync || this._flushSync());
|
|
692
718
|
}
|
|
693
719
|
setMaxFlushIterations(t) {
|
|
694
|
-
if (t <
|
|
720
|
+
if (t < g.MIN_FLUSH_ITERATIONS) throw new x(`Max iterations must be at least ${g.MIN_FLUSH_ITERATIONS}`);
|
|
695
721
|
this._maxFlushIterations = t;
|
|
696
722
|
}
|
|
697
|
-
},
|
|
698
|
-
function
|
|
699
|
-
if (
|
|
700
|
-
|
|
723
|
+
}, T = new Ot();
|
|
724
|
+
function Ut(t) {
|
|
725
|
+
if (f && typeof t != "function") throw new TypeError(l.BATCH_CALLBACK_MUST_BE_FUNCTION);
|
|
726
|
+
T.startBatch();
|
|
701
727
|
try {
|
|
702
728
|
return t();
|
|
703
729
|
} finally {
|
|
704
|
-
|
|
730
|
+
T.endBatch();
|
|
705
731
|
}
|
|
706
732
|
}
|
|
707
|
-
var
|
|
733
|
+
var R = null;
|
|
734
|
+
function Lt(t) {
|
|
735
|
+
return t ? new Promise((e, s) => {
|
|
736
|
+
T.schedule(() => {
|
|
737
|
+
try {
|
|
738
|
+
t(), e();
|
|
739
|
+
} catch (i) {
|
|
740
|
+
s(i);
|
|
741
|
+
}
|
|
742
|
+
});
|
|
743
|
+
}) : R || (R = new Promise((e) => {
|
|
744
|
+
T.schedule(() => {
|
|
745
|
+
R = null, e();
|
|
746
|
+
});
|
|
747
|
+
}), R);
|
|
748
|
+
}
|
|
749
|
+
var Nt = class extends tt {
|
|
708
750
|
constructor(t, e) {
|
|
709
|
-
super(), this[
|
|
751
|
+
super(), this[L] = p.Atom | p.Writable, this._value = t, this._equal = e.equal ?? Object.is, e.sync && (this.flags |= C.SYNC), f && d.attachDebugInfo(this, "atom", this.id, e.name);
|
|
710
752
|
}
|
|
711
753
|
get isNotificationScheduled() {
|
|
712
|
-
return (this.flags &
|
|
754
|
+
return (this.flags & C.NOTIFICATION_SCHEDULED) !== 0;
|
|
713
755
|
}
|
|
714
756
|
get isSync() {
|
|
715
|
-
return (this.flags &
|
|
757
|
+
return (this.flags & C.SYNC) !== 0;
|
|
716
758
|
}
|
|
717
759
|
get value() {
|
|
718
|
-
const t =
|
|
760
|
+
const t = _.current;
|
|
719
761
|
return t?.addDependency(this), this._value;
|
|
720
762
|
}
|
|
721
763
|
set value(t) {
|
|
722
764
|
const e = this._value;
|
|
723
|
-
if (this._equal(e, t)
|
|
724
|
-
|
|
725
|
-
|
|
765
|
+
if (this._equal(e, t)) return;
|
|
766
|
+
this._value = t, this.version = K(this.version), f && d.trackUpdate(this.id, d.getDebugName(this));
|
|
767
|
+
const s = this.flags, i = C.NOTIFICATION_SCHEDULED;
|
|
768
|
+
if ((s & i) !== 0) return;
|
|
769
|
+
const n = this._slots;
|
|
770
|
+
if (n === null || n.size === 0) return;
|
|
771
|
+
this._pendingOldValue = e;
|
|
772
|
+
const r = s | i;
|
|
773
|
+
if (this.flags = r, (r & C.SYNC) !== 0 && !T.isBatching) {
|
|
774
|
+
this._notifying === 0 && this._flushNotifications();
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
T.schedule(this);
|
|
726
778
|
}
|
|
727
779
|
execute() {
|
|
728
780
|
this._flushNotifications();
|
|
729
781
|
}
|
|
730
782
|
_flushNotifications() {
|
|
731
|
-
const t =
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
783
|
+
const t = C.NOTIFICATION_SCHEDULED, e = C.DISPOSED, s = C.SYNC, i = t | e;
|
|
784
|
+
let n = this.flags;
|
|
785
|
+
for (; (n & i) === t; ) {
|
|
786
|
+
const r = this._pendingOldValue;
|
|
787
|
+
this._pendingOldValue = void 0, this.flags = n &= ~t;
|
|
788
|
+
const o = this._value;
|
|
789
|
+
if (this._equal(o, r) || this._notifySubscribers(o, r), n = this.flags, (n & s) === 0 || T.isBatching) break;
|
|
735
790
|
}
|
|
736
791
|
}
|
|
737
792
|
peek() {
|
|
738
793
|
return this._value;
|
|
739
794
|
}
|
|
740
795
|
dispose() {
|
|
741
|
-
const t = this.flags;
|
|
742
|
-
(t &
|
|
796
|
+
const t = this.flags, e = C.DISPOSED;
|
|
797
|
+
(t & e) === 0 && (this.flags = t | e, this._slots?.clear(), this._value = void 0, this._pendingOldValue = void 0, this._equal = Object.is);
|
|
743
798
|
}
|
|
744
799
|
_deepDirtyCheck() {
|
|
745
800
|
return !1;
|
|
746
801
|
}
|
|
747
|
-
[Symbol.dispose]() {
|
|
748
|
-
this.dispose();
|
|
749
|
-
}
|
|
750
802
|
};
|
|
751
|
-
function
|
|
752
|
-
return new
|
|
803
|
+
function Pt(t, e = {}) {
|
|
804
|
+
return new Nt(t, e);
|
|
753
805
|
}
|
|
754
|
-
var { IDLE:
|
|
806
|
+
var { IDLE: v, DIRTY: a, PENDING: b, RESOLVED: D, REJECTED: m, HAS_ERROR: V, RECOMPUTING: O, DISPOSED: z, IS_COMPUTED: F, FORCE_COMPUTE: Y } = $, bt = class extends tt {
|
|
755
807
|
constructor(t, e = {}) {
|
|
756
|
-
if (typeof t != "function") throw new
|
|
757
|
-
if (super(), this[
|
|
808
|
+
if (typeof t != "function") throw new w(l.COMPUTED_MUST_BE_FUNCTION);
|
|
809
|
+
if (super(), this[L] = p.Atom | p.Computed, this._promiseId = 0, this._trackEpoch = U.UNINITIALIZED, this._trackCount = 0, this._error = null, this._deps = new ct(), this._value = void 0, this.flags = F | a | v, this._equal = e.equal ?? Object.is, this._computation = t, this._defaultValue = "defaultValue" in e ? e.defaultValue : G, this._onError = e.onError ?? null, d.attachDebugInfo(this, "computed", this.id, e.name), e.lazy === !1) try {
|
|
758
810
|
this._recompute();
|
|
759
811
|
} catch {
|
|
760
812
|
}
|
|
761
813
|
}
|
|
762
814
|
get isDirty() {
|
|
763
|
-
return (this.flags &
|
|
815
|
+
return (this.flags & a) !== 0;
|
|
764
816
|
}
|
|
765
817
|
get isRejected() {
|
|
766
|
-
return (this.flags &
|
|
818
|
+
return (this.flags & m) !== 0;
|
|
767
819
|
}
|
|
768
820
|
get isRecomputing() {
|
|
769
|
-
return (this.flags &
|
|
770
|
-
}
|
|
771
|
-
get _hasErrorInternal() {
|
|
772
|
-
return (this.flags & P) !== 0;
|
|
773
|
-
}
|
|
774
|
-
_track() {
|
|
775
|
-
l.current?.addDependency(this);
|
|
821
|
+
return (this.flags & O) !== 0;
|
|
776
822
|
}
|
|
777
823
|
get value() {
|
|
778
|
-
const t =
|
|
779
|
-
t
|
|
780
|
-
|
|
781
|
-
if ((e & (
|
|
782
|
-
if ((e &
|
|
783
|
-
if ((e &
|
|
824
|
+
const t = _.current;
|
|
825
|
+
t !== null && t.addDependency(this);
|
|
826
|
+
const e = this.flags;
|
|
827
|
+
if ((e & (D | a | v | z | O)) === D) return this._value;
|
|
828
|
+
if ((e & z) !== 0) throw new w(l.COMPUTED_DISPOSED);
|
|
829
|
+
if ((e & O) !== 0) {
|
|
784
830
|
const n = this._defaultValue;
|
|
785
|
-
if (n !==
|
|
786
|
-
throw new
|
|
831
|
+
if (n !== G) return n;
|
|
832
|
+
throw new w(l.COMPUTED_CIRCULAR_DEPENDENCY);
|
|
787
833
|
}
|
|
788
|
-
if ((e & (
|
|
834
|
+
if ((e & (a | v)) !== 0) {
|
|
789
835
|
const n = this._deps;
|
|
790
|
-
if ((e &
|
|
836
|
+
if ((e & (v | Y)) !== 0 || n.size === 0 || this._isDirty() ? this._recompute() : this.flags &= ~a, (this.flags & D) !== 0) return this._value;
|
|
791
837
|
}
|
|
792
|
-
const s = this._defaultValue, i = s !==
|
|
793
|
-
if ((
|
|
838
|
+
const s = this._defaultValue, i = s !== G;
|
|
839
|
+
if ((this.flags & b) !== 0) {
|
|
794
840
|
if (i) return s;
|
|
795
|
-
throw new
|
|
841
|
+
throw new w(l.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
|
|
796
842
|
}
|
|
797
|
-
if ((
|
|
843
|
+
if ((this.flags & m) !== 0) {
|
|
798
844
|
if (i) return s;
|
|
799
845
|
throw this._error;
|
|
800
846
|
}
|
|
@@ -804,16 +850,16 @@ var { IDLE: D, DIRTY: E, PENDING: O, RESOLVED: I, REJECTED: T, HAS_ERROR: P, REC
|
|
|
804
850
|
return this._value;
|
|
805
851
|
}
|
|
806
852
|
get state() {
|
|
807
|
-
const t =
|
|
808
|
-
t
|
|
853
|
+
const t = _.current;
|
|
854
|
+
t !== null && t.addDependency(this);
|
|
809
855
|
const e = this.flags;
|
|
810
|
-
return (e &
|
|
856
|
+
return (e & D) !== 0 ? P.RESOLVED : (e & b) !== 0 ? P.PENDING : (e & m) !== 0 ? P.REJECTED : P.IDLE;
|
|
811
857
|
}
|
|
812
858
|
get hasError() {
|
|
813
|
-
const t =
|
|
814
|
-
if (t
|
|
859
|
+
const t = _.current;
|
|
860
|
+
if (t !== null && t.addDependency(this), (this.flags & (m | V)) !== 0) return !0;
|
|
815
861
|
const e = this._deps;
|
|
816
|
-
return e.hasComputeds ?
|
|
862
|
+
return e.hasComputeds ? X(() => {
|
|
817
863
|
const s = e.size;
|
|
818
864
|
for (let i = 0; i < s; i++) if (e.getAt(i)?.node.hasError) return !0;
|
|
819
865
|
return !1;
|
|
@@ -823,204 +869,196 @@ var { IDLE: D, DIRTY: E, PENDING: O, RESOLVED: I, REJECTED: T, HAS_ERROR: P, REC
|
|
|
823
869
|
return !this.hasError;
|
|
824
870
|
}
|
|
825
871
|
get errors() {
|
|
826
|
-
const t =
|
|
827
|
-
t
|
|
872
|
+
const t = _.current;
|
|
873
|
+
t !== null && t.addDependency(this);
|
|
828
874
|
const e = this._error, s = this._deps;
|
|
829
875
|
if (!s.hasComputeds)
|
|
830
|
-
return e
|
|
876
|
+
return e === null ? it : Object.freeze([e]);
|
|
831
877
|
const i = [];
|
|
832
|
-
return e
|
|
878
|
+
return e !== null && i.push(e), X(() => {
|
|
833
879
|
const n = s.size;
|
|
834
880
|
for (let r = 0; r < n; r++) {
|
|
835
881
|
const o = s.getAt(r)?.node;
|
|
836
|
-
o
|
|
882
|
+
o !== void 0 && (o.flags & F) !== 0 && this._accumulateErrors(o, i);
|
|
837
883
|
}
|
|
838
|
-
}), i.length === 0 ?
|
|
884
|
+
}), i.length === 0 ? it : Object.freeze(i);
|
|
839
885
|
}
|
|
840
886
|
_accumulateErrors(t, e) {
|
|
841
887
|
const s = t._error;
|
|
842
|
-
s
|
|
888
|
+
s !== null && !e.includes(s) && e.push(s);
|
|
843
889
|
const i = t._deps;
|
|
844
890
|
if (!i.hasComputeds) return;
|
|
845
891
|
const n = i.size;
|
|
846
892
|
for (let r = 0; r < n; r++) {
|
|
847
893
|
const o = i.getAt(r)?.node;
|
|
848
|
-
o
|
|
894
|
+
o !== void 0 && (o.flags & F) !== 0 && this._accumulateErrors(o, e);
|
|
849
895
|
}
|
|
850
896
|
}
|
|
851
897
|
get lastError() {
|
|
852
|
-
const t =
|
|
853
|
-
return t
|
|
898
|
+
const t = _.current;
|
|
899
|
+
return t !== null && t.addDependency(this), this._error;
|
|
854
900
|
}
|
|
855
901
|
get isPending() {
|
|
856
|
-
const t =
|
|
857
|
-
return t
|
|
902
|
+
const t = _.current;
|
|
903
|
+
return t !== null && t.addDependency(this), (this.flags & b) !== 0;
|
|
858
904
|
}
|
|
859
905
|
get isResolved() {
|
|
860
|
-
const t =
|
|
861
|
-
return t
|
|
906
|
+
const t = _.current;
|
|
907
|
+
return t !== null && t.addDependency(this), (this.flags & D) !== 0;
|
|
862
908
|
}
|
|
863
909
|
invalidate() {
|
|
864
|
-
this.flags |=
|
|
910
|
+
this.flags |= Y, this._markDirty();
|
|
865
911
|
}
|
|
866
912
|
dispose() {
|
|
867
|
-
(this.flags &
|
|
868
|
-
}
|
|
869
|
-
[Symbol.dispose]() {
|
|
870
|
-
this.dispose();
|
|
913
|
+
(this.flags & z) === 0 && (this._deps.disposeAll(), this._slots !== null && this._slots.clear(), this.flags = z | a | v, this._error = null, this._value = void 0, this._hotIndex = -1);
|
|
871
914
|
}
|
|
872
915
|
addDependency(t) {
|
|
873
916
|
const e = this._trackEpoch;
|
|
874
917
|
if (t._lastSeenEpoch === e) return;
|
|
875
918
|
t._lastSeenEpoch = e;
|
|
876
|
-
const s = this._trackCount++, i = this._deps
|
|
877
|
-
|
|
919
|
+
const s = this._trackCount++, i = this._deps;
|
|
920
|
+
let n = null;
|
|
921
|
+
if (s < 4) s === 0 ? n = i._s0 : s === 1 ? n = i._s1 : s === 2 ? n = i._s2 : n = i._s3;
|
|
922
|
+
else {
|
|
923
|
+
const r = i._overflow;
|
|
924
|
+
r !== null && (n = r[s - 4] ?? null);
|
|
925
|
+
}
|
|
926
|
+
if (n !== null && n.node === t) n.version = t.version;
|
|
878
927
|
else if (!i.claimExisting(t, s)) {
|
|
879
|
-
const r = new
|
|
928
|
+
const r = new q(t, t.version, t.subscribe(this));
|
|
880
929
|
i.insertNew(s, r);
|
|
881
930
|
}
|
|
882
|
-
(t.flags &
|
|
931
|
+
(t.flags & F) !== 0 && (i.hasComputeds = !0);
|
|
883
932
|
}
|
|
884
933
|
_recompute() {
|
|
885
|
-
if (this.
|
|
886
|
-
this.flags = (this.flags |
|
|
934
|
+
if ((this.flags & O) !== 0) return;
|
|
935
|
+
this.flags = (this.flags | O) & ~Y, this._trackEpoch = et(), this._trackCount = 0, this._deps.prepareTracking(), this._hotIndex = -1;
|
|
887
936
|
let t = !1;
|
|
888
937
|
try {
|
|
889
|
-
const e =
|
|
890
|
-
this._deps.truncateFrom(this._trackCount), t = !0,
|
|
938
|
+
const e = _.run(this, this._computation);
|
|
939
|
+
this._deps.truncateFrom(this._trackCount), t = !0, Z(e) ? this._handleAsyncComputation(e) : this._finalizeResolution(e);
|
|
891
940
|
} catch (e) {
|
|
892
941
|
if (!t) try {
|
|
893
942
|
this._deps.truncateFrom(this._trackCount);
|
|
894
943
|
} catch (s) {
|
|
895
|
-
|
|
944
|
+
f && console.warn("[atom-effect] _commitDeps failed during error recovery:", s);
|
|
896
945
|
}
|
|
897
|
-
this._handleError(e,
|
|
946
|
+
this._handleError(e, l.COMPUTED_COMPUTATION_FAILED, !0);
|
|
898
947
|
} finally {
|
|
899
|
-
this._trackEpoch =
|
|
948
|
+
this._trackEpoch = U.UNINITIALIZED, this._trackCount = 0, this.flags &= ~O;
|
|
900
949
|
}
|
|
901
950
|
}
|
|
902
951
|
_handleAsyncComputation(t) {
|
|
903
|
-
this.flags = (this.flags |
|
|
952
|
+
this.flags = (this.flags | b) & ~(v | a | D | m), this._notifySubscribers(void 0, void 0), this._promiseId = (this._promiseId + 1) % Et.MAX_PROMISE_ID;
|
|
904
953
|
const e = this._promiseId;
|
|
905
954
|
t.then((s) => {
|
|
906
955
|
if (e === this._promiseId) {
|
|
907
956
|
if (this._isDirty()) return this._markDirty();
|
|
908
957
|
this._finalizeResolution(s), this._notifySubscribers(s, void 0);
|
|
909
958
|
}
|
|
910
|
-
}, (s) => e === this._promiseId && this._handleError(s,
|
|
959
|
+
}, (s) => e === this._promiseId && this._handleError(s, l.COMPUTED_ASYNC_COMPUTATION_FAILED));
|
|
911
960
|
}
|
|
912
961
|
_handleError(t, e, s = !1) {
|
|
913
|
-
const i =
|
|
914
|
-
if ((!this.isRejected || this._error !== i) && (this.version =
|
|
962
|
+
const i = A(t, w, e);
|
|
963
|
+
if ((!this.isRejected || this._error !== i) && (this.version = K(this.version)), this._error = i, this.flags = this.flags & ~(v | a | b | D) | m | V, this._onError) try {
|
|
915
964
|
this._onError(i);
|
|
916
965
|
} catch (n) {
|
|
917
|
-
console.error(
|
|
966
|
+
console.error(l.CALLBACK_ERROR_IN_ERROR_HANDLER, n);
|
|
918
967
|
}
|
|
919
968
|
if (this._notifySubscribers(void 0, void 0), s) throw i;
|
|
920
969
|
}
|
|
921
970
|
_finalizeResolution(t) {
|
|
922
971
|
const e = this.flags;
|
|
923
|
-
((e &
|
|
972
|
+
((e & D) === 0 || !this._equal(this._value, t)) && (this.version = K(this.version)), this._value = t, this._error = null, this.flags = (e | D) & ~(v | a | b | m | V);
|
|
924
973
|
}
|
|
925
974
|
execute() {
|
|
926
975
|
this._markDirty();
|
|
927
976
|
}
|
|
928
977
|
_markDirty() {
|
|
929
978
|
const t = this.flags;
|
|
930
|
-
(t & (
|
|
979
|
+
(t & (O | a)) === 0 && (this.flags = t | a, d.trackUpdate(this.id, d.getDebugName(this)), this._notifySubscribers(void 0, void 0));
|
|
931
980
|
}
|
|
932
981
|
_deepDirtyCheck() {
|
|
933
|
-
const t = this._deps;
|
|
934
|
-
return
|
|
935
|
-
|
|
936
|
-
for (let s = 0; s < e; s++) {
|
|
982
|
+
const t = this._deps, e = t.size, s = this._hotIndex;
|
|
983
|
+
return X(() => {
|
|
984
|
+
if (s !== -1 && s < e) {
|
|
937
985
|
const i = t.getAt(s);
|
|
938
|
-
if (i
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
if (n.version !== i.version)
|
|
946
|
-
return this._hotIndex = s, !0;
|
|
986
|
+
if (i !== null && this._checkLinkDirty(i)) return !0;
|
|
987
|
+
}
|
|
988
|
+
for (let i = 0; i < e; i++) {
|
|
989
|
+
if (i === s) continue;
|
|
990
|
+
const n = t.getAt(i);
|
|
991
|
+
if (n !== null && this._checkLinkDirty(n))
|
|
992
|
+
return this._hotIndex = i, !0;
|
|
947
993
|
}
|
|
948
994
|
return this._hotIndex = -1, !1;
|
|
949
995
|
});
|
|
950
996
|
}
|
|
997
|
+
_checkLinkDirty(t) {
|
|
998
|
+
const e = t.node;
|
|
999
|
+
if ((e.flags & F) !== 0) try {
|
|
1000
|
+
e.value;
|
|
1001
|
+
} catch {
|
|
1002
|
+
f && console.warn(`[atom-effect] Dependency #${e.id} threw during check`);
|
|
1003
|
+
}
|
|
1004
|
+
return e.version !== t.version;
|
|
1005
|
+
}
|
|
951
1006
|
};
|
|
952
|
-
function
|
|
953
|
-
return new
|
|
1007
|
+
function xt(t, e = {}) {
|
|
1008
|
+
return new bt(t, e);
|
|
954
1009
|
}
|
|
955
|
-
var
|
|
1010
|
+
var At = class extends tt {
|
|
956
1011
|
constructor(t, e = {}) {
|
|
957
|
-
super(), this[
|
|
1012
|
+
super(), this[L] = p.Effect, this._currentEpoch = U.UNINITIALIZED, this._lastFlushEpoch = U.UNINITIALIZED, this._executionsInEpoch = 0, this._executionCount = 0, this._windowStart = 0, this._windowCount = 0, this._execId = 0, this._trackCount = 0, this._cleanup = null, this._deps = new ct(), this._fn = t, this._onError = e.onError ?? null, this._sync = e.sync ?? !1, this._maxExecutions = e.maxExecutionsPerSecond ?? g.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = e.maxExecutionsPerFlush ?? g.MAX_EXECUTIONS_PER_EFFECT, this._sync ? this._notifyCallback = () => this.execute() : this._notifyCallback = () => T.schedule(this), d.attachDebugInfo(this, "effect", this.id, e.name);
|
|
958
1013
|
}
|
|
959
1014
|
run() {
|
|
960
|
-
if (this.isDisposed) throw new
|
|
1015
|
+
if (this.isDisposed) throw new N(l.EFFECT_DISPOSED);
|
|
961
1016
|
this.execute(!0);
|
|
962
1017
|
}
|
|
963
1018
|
dispose() {
|
|
964
1019
|
this.isDisposed || (this.flags |= S.DISPOSED, this._execCleanup(), this._deps?.disposeAll());
|
|
965
1020
|
}
|
|
966
|
-
[Symbol.dispose]() {
|
|
967
|
-
this.dispose();
|
|
968
|
-
}
|
|
969
1021
|
addDependency(t) {
|
|
970
|
-
if ((this.flags & S.EXECUTING) === 0) return;
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
n = i._s0;
|
|
979
|
-
break;
|
|
980
|
-
case 1:
|
|
981
|
-
n = i._s1;
|
|
982
|
-
break;
|
|
983
|
-
case 2:
|
|
984
|
-
n = i._s2;
|
|
985
|
-
break;
|
|
986
|
-
case 3:
|
|
987
|
-
n = i._s3;
|
|
988
|
-
break;
|
|
989
|
-
default:
|
|
990
|
-
n = i.getAt(s);
|
|
1022
|
+
if ((this.flags & S.EXECUTING) === 0 || t._lastSeenEpoch === this._currentEpoch) return;
|
|
1023
|
+
t._lastSeenEpoch = this._currentEpoch;
|
|
1024
|
+
const e = this._trackCount++, s = this._deps, i = t.version;
|
|
1025
|
+
let n = null;
|
|
1026
|
+
if (e < 4) e === 0 ? n = s._s0 : e === 1 ? n = s._s1 : e === 2 ? n = s._s2 : n = s._s3;
|
|
1027
|
+
else {
|
|
1028
|
+
const r = s._overflow;
|
|
1029
|
+
r !== null && (n = r[e - 4] ?? null);
|
|
991
1030
|
}
|
|
992
|
-
n
|
|
1031
|
+
n !== null && n.node === t ? n.version = i : s.claimExisting(t, e) || this._insertNewDependency(t, e, i), t.isComputed && !s.hasComputeds && (s.hasComputeds = !0);
|
|
993
1032
|
}
|
|
994
|
-
_insertNewDependency(t, e) {
|
|
995
|
-
let
|
|
1033
|
+
_insertNewDependency(t, e, s) {
|
|
1034
|
+
let i;
|
|
996
1035
|
try {
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
this._onError(n);
|
|
1036
|
+
i = new q(t, s, t.subscribe(this._notifyCallback));
|
|
1037
|
+
} catch (n) {
|
|
1038
|
+
const r = A(n, N, l.EFFECT_EXECUTION_FAILED);
|
|
1039
|
+
if (console.error(r), this._onError) try {
|
|
1040
|
+
this._onError(r);
|
|
1003
1041
|
} catch {
|
|
1004
1042
|
}
|
|
1005
|
-
|
|
1043
|
+
i = new q(t, s, void 0);
|
|
1006
1044
|
}
|
|
1007
|
-
this._deps.insertNew(e,
|
|
1045
|
+
this._deps.insertNew(e, i);
|
|
1008
1046
|
}
|
|
1009
1047
|
execute(t = !1) {
|
|
1010
1048
|
const e = this.flags;
|
|
1011
1049
|
if ((e & (S.DISPOSED | S.EXECUTING)) !== 0) return;
|
|
1012
1050
|
const s = this._deps;
|
|
1013
|
-
if (!t && s.
|
|
1014
|
-
this._checkInfiniteLoops(), d.trackUpdate(this.id, d.getDebugName(this)), this.flags = e | S.EXECUTING, this._execCleanup(), this._currentEpoch =
|
|
1051
|
+
if (!t && s.physicalSize > 0 && !this._isDirty()) return;
|
|
1052
|
+
this._checkInfiniteLoops(), d.trackUpdate(this.id, d.getDebugName(this)), this.flags = e | S.EXECUTING, this._execCleanup(), this._currentEpoch = et(), this._trackCount = 0, s.prepareTracking(), this._hotIndex = -1;
|
|
1015
1053
|
let i = !1;
|
|
1016
1054
|
try {
|
|
1017
|
-
const n =
|
|
1018
|
-
s.truncateFrom(this._trackCount), i = !0,
|
|
1055
|
+
const n = _.run(this, this._fn);
|
|
1056
|
+
s.truncateFrom(this._trackCount), i = !0, typeof n == "function" ? this._cleanup = n : Z(n) ? this._handleAsyncResult(n) : this._cleanup = null;
|
|
1019
1057
|
} catch (n) {
|
|
1020
1058
|
if (!i) try {
|
|
1021
1059
|
s.truncateFrom(this._trackCount);
|
|
1022
1060
|
} catch (r) {
|
|
1023
|
-
|
|
1061
|
+
f && console.warn("[atom-effect] _commitDeps failed during error recovery:", r);
|
|
1024
1062
|
}
|
|
1025
1063
|
this._handleExecutionError(n), this._cleanup = null;
|
|
1026
1064
|
} finally {
|
|
@@ -1030,40 +1068,50 @@ var bt = class extends K {
|
|
|
1030
1068
|
_handleAsyncResult(t) {
|
|
1031
1069
|
const e = ++this._execId;
|
|
1032
1070
|
t.then((s) => {
|
|
1033
|
-
if (e !== this._execId || this.
|
|
1071
|
+
if (e !== this._execId || (this.flags & S.DISPOSED) !== 0) {
|
|
1034
1072
|
if (typeof s == "function") try {
|
|
1035
1073
|
s();
|
|
1036
1074
|
} catch (i) {
|
|
1037
|
-
this._handleExecutionError(i,
|
|
1075
|
+
this._handleExecutionError(i, l.EFFECT_CLEANUP_FAILED);
|
|
1038
1076
|
}
|
|
1039
1077
|
return;
|
|
1040
1078
|
}
|
|
1041
1079
|
typeof s == "function" && (this._cleanup = s);
|
|
1042
1080
|
}, (s) => e === this._execId && this._handleExecutionError(s));
|
|
1043
1081
|
}
|
|
1044
|
-
|
|
1045
|
-
const t =
|
|
1046
|
-
|
|
1047
|
-
const
|
|
1048
|
-
|
|
1049
|
-
const
|
|
1050
|
-
|
|
1051
|
-
const n =
|
|
1052
|
-
if (n
|
|
1053
|
-
const r = n.node;
|
|
1054
|
-
if (r.isComputed && this._tryPullComputed(r), r.version !== n.version)
|
|
1055
|
-
return this._hotIndex = i, !0;
|
|
1082
|
+
_isDirty() {
|
|
1083
|
+
const t = this._deps, e = t.size;
|
|
1084
|
+
if (e === 0) return !1;
|
|
1085
|
+
const s = this._hotIndex;
|
|
1086
|
+
if (s !== -1 && s < e) {
|
|
1087
|
+
const i = t.getAt(s);
|
|
1088
|
+
if (i !== null) {
|
|
1089
|
+
const n = i.node;
|
|
1090
|
+
if (!n.isComputed && n.version !== i.version) return !0;
|
|
1056
1091
|
}
|
|
1057
|
-
return !1;
|
|
1058
|
-
} finally {
|
|
1059
|
-
l.current = t;
|
|
1060
1092
|
}
|
|
1093
|
+
return this._deepDirtyCheck();
|
|
1061
1094
|
}
|
|
1062
|
-
|
|
1095
|
+
_deepDirtyCheck() {
|
|
1096
|
+
const t = this._deps, e = t.size, s = this._hotIndex, i = _.current;
|
|
1097
|
+
_.current = null;
|
|
1063
1098
|
try {
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1099
|
+
for (let n = 0; n < e; n++) {
|
|
1100
|
+
if (n === s) continue;
|
|
1101
|
+
const r = t.getAt(n);
|
|
1102
|
+
if (r === null) continue;
|
|
1103
|
+
const o = r.node;
|
|
1104
|
+
if (o.isComputed) try {
|
|
1105
|
+
o.value;
|
|
1106
|
+
} catch {
|
|
1107
|
+
f && console.warn(`[atom-effect] Dependency #${o.id} error in check`);
|
|
1108
|
+
}
|
|
1109
|
+
if (o.version !== r.version)
|
|
1110
|
+
return this._hotIndex = n, !0;
|
|
1111
|
+
}
|
|
1112
|
+
return this._hotIndex = -1, !1;
|
|
1113
|
+
} finally {
|
|
1114
|
+
_.current = i;
|
|
1067
1115
|
}
|
|
1068
1116
|
}
|
|
1069
1117
|
_execCleanup() {
|
|
@@ -1073,23 +1121,23 @@ var bt = class extends K {
|
|
|
1073
1121
|
try {
|
|
1074
1122
|
t();
|
|
1075
1123
|
} catch (e) {
|
|
1076
|
-
this._handleExecutionError(e,
|
|
1124
|
+
this._handleExecutionError(e, l.EFFECT_CLEANUP_FAILED);
|
|
1077
1125
|
}
|
|
1078
1126
|
}
|
|
1079
1127
|
}
|
|
1080
1128
|
_checkInfiniteLoops() {
|
|
1081
1129
|
const t = Tt();
|
|
1082
|
-
this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), mt() >
|
|
1130
|
+
this._lastFlushEpoch !== t && (this._lastFlushEpoch = t, this._executionsInEpoch = 0), ++this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), mt() > g.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++, f && this._checkFrequencyLimit();
|
|
1083
1131
|
}
|
|
1084
1132
|
_checkFrequencyLimit() {
|
|
1085
1133
|
if (!Number.isFinite(this._maxExecutions)) return;
|
|
1086
1134
|
const t = Date.now();
|
|
1087
|
-
if (t - this._windowStart >=
|
|
1135
|
+
if (t - this._windowStart >= W.EFFECT_FREQUENCY_WINDOW) {
|
|
1088
1136
|
this._windowStart = t, this._windowCount = 1;
|
|
1089
1137
|
return;
|
|
1090
1138
|
}
|
|
1091
1139
|
if (++this._windowCount > this._maxExecutions) {
|
|
1092
|
-
const e = new
|
|
1140
|
+
const e = new N(l.EFFECT_FREQUENCY_LIMIT_EXCEEDED);
|
|
1093
1141
|
throw this.dispose(), this._handleExecutionError(e), e;
|
|
1094
1142
|
}
|
|
1095
1143
|
}
|
|
@@ -1100,102 +1148,103 @@ var bt = class extends K {
|
|
|
1100
1148
|
return (this.flags & S.EXECUTING) !== 0;
|
|
1101
1149
|
}
|
|
1102
1150
|
_throwInfiniteLoopError(t) {
|
|
1103
|
-
const e = new
|
|
1151
|
+
const e = new N(`Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${st}`);
|
|
1104
1152
|
throw this.dispose(), console.error(e), e;
|
|
1105
1153
|
}
|
|
1106
|
-
_handleExecutionError(t, e =
|
|
1107
|
-
const s =
|
|
1154
|
+
_handleExecutionError(t, e = l.EFFECT_EXECUTION_FAILED) {
|
|
1155
|
+
const s = A(t, N, e);
|
|
1108
1156
|
if (console.error(s), this._onError) try {
|
|
1109
1157
|
this._onError(s);
|
|
1110
1158
|
} catch (i) {
|
|
1111
|
-
console.error(
|
|
1159
|
+
console.error(A(i, N, l.CALLBACK_ERROR_IN_ERROR_HANDLER));
|
|
1112
1160
|
}
|
|
1113
1161
|
}
|
|
1114
1162
|
};
|
|
1115
|
-
function
|
|
1116
|
-
if (typeof t != "function") throw new
|
|
1117
|
-
const s = new
|
|
1163
|
+
function Mt(t, e = {}) {
|
|
1164
|
+
if (typeof t != "function") throw new N(l.EFFECT_MUST_BE_FUNCTION);
|
|
1165
|
+
const s = new At(t, e);
|
|
1118
1166
|
return s.execute(), s;
|
|
1119
1167
|
}
|
|
1120
|
-
|
|
1121
|
-
function _t(t, e, s, i) {
|
|
1168
|
+
function ft(t, e, s, i) {
|
|
1122
1169
|
if (s === e.length) return i;
|
|
1123
1170
|
const n = e[s];
|
|
1124
|
-
if (
|
|
1125
|
-
const r = t != null && typeof t == "object" ? t : {}, o = r[n],
|
|
1126
|
-
if (Object.is(o,
|
|
1171
|
+
if (n === "__proto__" || n === "constructor" || n === "prototype") return t;
|
|
1172
|
+
const r = t != null && typeof t == "object" ? t : {}, o = r[n], u = ft(o, e, s + 1, i);
|
|
1173
|
+
if (Object.is(o, u)) return t;
|
|
1127
1174
|
if (Array.isArray(r)) {
|
|
1128
|
-
const
|
|
1129
|
-
return n.trim() !== "" &&
|
|
1175
|
+
const I = r.slice(), E = +n;
|
|
1176
|
+
return n.trim() !== "" && E >= 0 && E % 1 === 0 ? I[E] = u : I[n] = u, I;
|
|
1130
1177
|
}
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
[n]: c
|
|
1134
|
-
};
|
|
1178
|
+
const c = { ...r };
|
|
1179
|
+
return c[n] = u, c;
|
|
1135
1180
|
}
|
|
1136
|
-
function
|
|
1181
|
+
function k(t, e) {
|
|
1137
1182
|
let s = t;
|
|
1138
1183
|
const i = e.length;
|
|
1139
1184
|
for (let n = 0; n < i; n++) {
|
|
1140
1185
|
if (s == null) return;
|
|
1141
1186
|
const r = e[n];
|
|
1142
|
-
if (
|
|
1187
|
+
if (r === "__proto__" || r === "constructor" || r === "prototype") return;
|
|
1143
1188
|
s = s[r];
|
|
1144
1189
|
}
|
|
1145
1190
|
return s;
|
|
1146
1191
|
}
|
|
1147
1192
|
function at(t, e) {
|
|
1148
|
-
const s = e.includes(".") ? e.split(".") : [e], i = /* @__PURE__ */ new Set()
|
|
1149
|
-
i.forEach((r) => r()), i.clear();
|
|
1150
|
-
};
|
|
1193
|
+
const s = e.includes(".") ? e.split(".") : [e], i = /* @__PURE__ */ new Set();
|
|
1151
1194
|
return {
|
|
1152
1195
|
get value() {
|
|
1153
|
-
return
|
|
1196
|
+
return k(t.value, s);
|
|
1154
1197
|
},
|
|
1155
1198
|
set value(r) {
|
|
1156
|
-
const o = t.peek(),
|
|
1157
|
-
|
|
1199
|
+
const o = t.peek(), u = ft(o, s, 0, r);
|
|
1200
|
+
u !== o && (t.value = u);
|
|
1158
1201
|
},
|
|
1159
|
-
peek: () =>
|
|
1202
|
+
peek: () => k(t.peek(), s),
|
|
1160
1203
|
subscribe(r) {
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1204
|
+
let o = k(t.peek(), s);
|
|
1205
|
+
const u = t.subscribe((c) => {
|
|
1206
|
+
const I = k(c, s);
|
|
1207
|
+
if (!Object.is(I, o)) {
|
|
1208
|
+
const E = o;
|
|
1209
|
+
o = I, r(I, E);
|
|
1210
|
+
}
|
|
1164
1211
|
});
|
|
1165
|
-
return i.add(
|
|
1166
|
-
|
|
1212
|
+
return i.add(u), () => {
|
|
1213
|
+
u(), i.delete(u);
|
|
1167
1214
|
};
|
|
1168
1215
|
},
|
|
1169
1216
|
subscriberCount: () => i.size,
|
|
1170
|
-
dispose:
|
|
1171
|
-
|
|
1172
|
-
|
|
1217
|
+
dispose: () => {
|
|
1218
|
+
i.forEach((r) => r()), i.clear();
|
|
1219
|
+
},
|
|
1220
|
+
[L]: p.Atom | p.Writable
|
|
1173
1221
|
};
|
|
1174
1222
|
}
|
|
1175
|
-
var
|
|
1223
|
+
var zt = (t, e) => at(t, e), kt = (t) => (e) => at(t, e);
|
|
1176
1224
|
export {
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1225
|
+
P as AsyncState,
|
|
1226
|
+
y as AtomError,
|
|
1227
|
+
w as ComputedError,
|
|
1228
|
+
W as DEBUG_CONFIG,
|
|
1229
|
+
N as EffectError,
|
|
1230
|
+
g as SCHEDULER_CONFIG,
|
|
1231
|
+
x as SchedulerError,
|
|
1232
|
+
Lt as aeNextTick,
|
|
1233
|
+
Pt as atom,
|
|
1185
1234
|
at as atomLens,
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1235
|
+
Ut as batch,
|
|
1236
|
+
zt as composeLens,
|
|
1237
|
+
xt as computed,
|
|
1238
|
+
Mt as effect,
|
|
1239
|
+
k as getPathValue,
|
|
1240
|
+
T as globalScheduler,
|
|
1241
|
+
wt as isAtom,
|
|
1193
1242
|
Rt as isComputed,
|
|
1194
|
-
|
|
1195
|
-
|
|
1243
|
+
Ft as isEffect,
|
|
1244
|
+
kt as lensFor,
|
|
1196
1245
|
d as runtimeDebug,
|
|
1197
|
-
|
|
1198
|
-
|
|
1246
|
+
ft as setDeepValue,
|
|
1247
|
+
X as untracked
|
|
1199
1248
|
};
|
|
1200
1249
|
|
|
1201
1250
|
//# sourceMappingURL=index.mjs.map
|