@solidjs/signals 0.4.0 → 0.4.2
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/dev.js +505 -229
- package/dist/node.cjs +849 -573
- package/dist/prod.js +847 -571
- package/dist/types/core/core.d.ts +7 -3
- package/dist/types/core/effect.d.ts +5 -1
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/core/scheduler.d.ts +44 -3
- package/dist/types/index.d.ts +1 -1
- package/dist/types/signals.d.ts +2 -11
- package/package.json +1 -1
package/dist/node.cjs
CHANGED
|
@@ -26,33 +26,52 @@ var EFFECT_RENDER = 1;
|
|
|
26
26
|
var EFFECT_USER = 2;
|
|
27
27
|
var SUPPORTS_PROXY = typeof Proxy === "function";
|
|
28
28
|
|
|
29
|
+
// src/core/flags.ts
|
|
30
|
+
var ERROR_OFFSET = 0;
|
|
31
|
+
var ERROR_BIT = 1 << ERROR_OFFSET;
|
|
32
|
+
var LOADING_OFFSET = 1;
|
|
33
|
+
var LOADING_BIT = 1 << LOADING_OFFSET;
|
|
34
|
+
var UNINITIALIZED_OFFSET = 2;
|
|
35
|
+
var UNINITIALIZED_BIT = 1 << UNINITIALIZED_OFFSET;
|
|
36
|
+
var DEFAULT_FLAGS = ERROR_BIT;
|
|
37
|
+
|
|
29
38
|
// src/core/scheduler.ts
|
|
30
39
|
var clock = 0;
|
|
31
|
-
function getClock() {
|
|
32
|
-
return clock;
|
|
33
|
-
}
|
|
34
40
|
function incrementClock() {
|
|
35
41
|
clock++;
|
|
36
42
|
}
|
|
43
|
+
var ActiveTransition = null;
|
|
44
|
+
var unobserved = [];
|
|
37
45
|
var scheduled = false;
|
|
38
46
|
function schedule() {
|
|
39
47
|
if (scheduled)
|
|
40
48
|
return;
|
|
41
49
|
scheduled = true;
|
|
42
|
-
if (!globalQueue.
|
|
50
|
+
if (!globalQueue.x)
|
|
43
51
|
queueMicrotask(flush);
|
|
44
52
|
}
|
|
53
|
+
function notifyUnobserved() {
|
|
54
|
+
var _a, _b;
|
|
55
|
+
for (let i = 0; i < unobserved.length; i++) {
|
|
56
|
+
const source = unobserved[i];
|
|
57
|
+
if (!source.d || !source.d.length)
|
|
58
|
+
(_b = (_a = unobserved[i]).ca) == null ? void 0 : _b.call(_a);
|
|
59
|
+
}
|
|
60
|
+
unobserved = [];
|
|
61
|
+
}
|
|
45
62
|
var pureQueue = [];
|
|
46
63
|
var Queue = class {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
64
|
+
p = null;
|
|
65
|
+
x = false;
|
|
66
|
+
o = [[], []];
|
|
67
|
+
q = [];
|
|
51
68
|
created = clock;
|
|
52
69
|
enqueue(type, fn) {
|
|
70
|
+
if (ActiveTransition)
|
|
71
|
+
return ActiveTransition.enqueue(type, fn);
|
|
53
72
|
pureQueue.push(fn);
|
|
54
73
|
if (type)
|
|
55
|
-
this.
|
|
74
|
+
this.o[type - 1].push(fn);
|
|
56
75
|
schedule();
|
|
57
76
|
}
|
|
58
77
|
run(type) {
|
|
@@ -60,19 +79,19 @@ var Queue = class {
|
|
|
60
79
|
pureQueue.length && runQueue(pureQueue, type);
|
|
61
80
|
pureQueue = [];
|
|
62
81
|
return;
|
|
63
|
-
} else if (this.
|
|
64
|
-
const effects = this.
|
|
65
|
-
this.
|
|
82
|
+
} else if (this.o[type - 1].length) {
|
|
83
|
+
const effects = this.o[type - 1];
|
|
84
|
+
this.o[type - 1] = [];
|
|
66
85
|
runQueue(effects, type);
|
|
67
86
|
}
|
|
68
|
-
for (let i = 0; i < this.
|
|
69
|
-
this.
|
|
87
|
+
for (let i = 0; i < this.q.length; i++) {
|
|
88
|
+
this.q[i].run(type);
|
|
70
89
|
}
|
|
71
90
|
}
|
|
72
91
|
flush() {
|
|
73
|
-
if (this.
|
|
92
|
+
if (this.x)
|
|
74
93
|
return;
|
|
75
|
-
this.
|
|
94
|
+
this.x = true;
|
|
76
95
|
try {
|
|
77
96
|
this.run(EFFECT_PURE);
|
|
78
97
|
incrementClock();
|
|
@@ -80,21 +99,22 @@ var Queue = class {
|
|
|
80
99
|
this.run(EFFECT_RENDER);
|
|
81
100
|
this.run(EFFECT_USER);
|
|
82
101
|
} finally {
|
|
83
|
-
this.
|
|
102
|
+
this.x = false;
|
|
103
|
+
unobserved.length && notifyUnobserved();
|
|
84
104
|
}
|
|
85
105
|
}
|
|
86
106
|
addChild(child) {
|
|
87
|
-
this.
|
|
88
|
-
child.
|
|
107
|
+
this.q.push(child);
|
|
108
|
+
child.p = this;
|
|
89
109
|
}
|
|
90
110
|
removeChild(child) {
|
|
91
|
-
const index = this.
|
|
111
|
+
const index = this.q.indexOf(child);
|
|
92
112
|
if (index >= 0)
|
|
93
|
-
this.
|
|
113
|
+
this.q.splice(index, 1);
|
|
94
114
|
}
|
|
95
115
|
notify(...args) {
|
|
96
|
-
if (this.
|
|
97
|
-
return this.
|
|
116
|
+
if (this.p)
|
|
117
|
+
return this.p.notify(...args);
|
|
98
118
|
return false;
|
|
99
119
|
}
|
|
100
120
|
};
|
|
@@ -108,6 +128,200 @@ function runQueue(queue, type) {
|
|
|
108
128
|
for (let i = 0; i < queue.length; i++)
|
|
109
129
|
queue[i](type);
|
|
110
130
|
}
|
|
131
|
+
var Transition = class _Transition {
|
|
132
|
+
a = /* @__PURE__ */ new Map();
|
|
133
|
+
t = /* @__PURE__ */ new Set();
|
|
134
|
+
M = /* @__PURE__ */ new Set();
|
|
135
|
+
T = /* @__PURE__ */ new Set();
|
|
136
|
+
E = false;
|
|
137
|
+
o = [[], []];
|
|
138
|
+
F = [];
|
|
139
|
+
q = [];
|
|
140
|
+
p = null;
|
|
141
|
+
x = false;
|
|
142
|
+
U = false;
|
|
143
|
+
created = clock;
|
|
144
|
+
enqueue(type, fn) {
|
|
145
|
+
this.F.push(fn);
|
|
146
|
+
if (type)
|
|
147
|
+
this.o[type - 1].push(fn);
|
|
148
|
+
this.schedule();
|
|
149
|
+
}
|
|
150
|
+
run(type) {
|
|
151
|
+
if (type === EFFECT_PURE) {
|
|
152
|
+
this.F.length && runQueue(this.F, type);
|
|
153
|
+
this.F = [];
|
|
154
|
+
return;
|
|
155
|
+
} else if (this.o[type - 1].length) {
|
|
156
|
+
const effects = this.o[type - 1];
|
|
157
|
+
this.o[type - 1] = [];
|
|
158
|
+
runQueue(effects, type);
|
|
159
|
+
}
|
|
160
|
+
for (let i = 0; i < this.q.length; i++) {
|
|
161
|
+
this.q[i].run(type);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
flush() {
|
|
165
|
+
if (this.x)
|
|
166
|
+
return;
|
|
167
|
+
this.x = true;
|
|
168
|
+
let currentTransition = ActiveTransition;
|
|
169
|
+
ActiveTransition = this;
|
|
170
|
+
try {
|
|
171
|
+
this.run(EFFECT_PURE);
|
|
172
|
+
incrementClock();
|
|
173
|
+
this.U = false;
|
|
174
|
+
ActiveTransition = currentTransition;
|
|
175
|
+
finishTransition(this);
|
|
176
|
+
} finally {
|
|
177
|
+
this.x = false;
|
|
178
|
+
ActiveTransition = currentTransition;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
addChild(child) {
|
|
182
|
+
this.q.push(child);
|
|
183
|
+
child.p = this;
|
|
184
|
+
}
|
|
185
|
+
removeChild(child) {
|
|
186
|
+
const index = this.q.indexOf(child);
|
|
187
|
+
if (index >= 0)
|
|
188
|
+
this.q.splice(index, 1);
|
|
189
|
+
}
|
|
190
|
+
notify(node, type, flags) {
|
|
191
|
+
if (!(type & LOADING_BIT))
|
|
192
|
+
return false;
|
|
193
|
+
if (flags & LOADING_BIT) {
|
|
194
|
+
this.t.add(node);
|
|
195
|
+
} else {
|
|
196
|
+
this.t.delete(node);
|
|
197
|
+
}
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
schedule() {
|
|
201
|
+
if (this.U)
|
|
202
|
+
return;
|
|
203
|
+
this.U = true;
|
|
204
|
+
if (!this.x)
|
|
205
|
+
queueMicrotask(() => this.flush());
|
|
206
|
+
}
|
|
207
|
+
runTransition(fn, force = false) {
|
|
208
|
+
if (this.E) {
|
|
209
|
+
if (this.E instanceof _Transition)
|
|
210
|
+
return this.E.runTransition(fn, force);
|
|
211
|
+
if (!force)
|
|
212
|
+
throw new Error("Transition already completed");
|
|
213
|
+
fn();
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
ActiveTransition = this;
|
|
217
|
+
try {
|
|
218
|
+
const result = fn();
|
|
219
|
+
const transition2 = ActiveTransition;
|
|
220
|
+
if (result instanceof Promise) {
|
|
221
|
+
transition2.M.add(result);
|
|
222
|
+
result.finally(() => {
|
|
223
|
+
transition2.M.delete(result);
|
|
224
|
+
finishTransition(transition2);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
} finally {
|
|
228
|
+
const transition2 = ActiveTransition;
|
|
229
|
+
ActiveTransition = null;
|
|
230
|
+
finishTransition(transition2);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
addOptimistic(fn) {
|
|
234
|
+
if (fn.h && fn.h !== this) {
|
|
235
|
+
mergeTransitions(fn.h, this);
|
|
236
|
+
ActiveTransition = fn.h;
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
fn.h = this;
|
|
240
|
+
this.T.add(fn);
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
var Transitions = /* @__PURE__ */ new Set();
|
|
244
|
+
function transition(fn) {
|
|
245
|
+
let t = new Transition();
|
|
246
|
+
Transitions.add(t);
|
|
247
|
+
queueMicrotask(() => t.runTransition(() => fn((fn2) => t.runTransition(fn2))));
|
|
248
|
+
}
|
|
249
|
+
function cloneGraph(node) {
|
|
250
|
+
if (node.h) {
|
|
251
|
+
if (node.h !== ActiveTransition) {
|
|
252
|
+
mergeTransitions(node.h, ActiveTransition);
|
|
253
|
+
ActiveTransition = node.h;
|
|
254
|
+
}
|
|
255
|
+
return node.h.a.get(node);
|
|
256
|
+
}
|
|
257
|
+
const clone = Object.create(Object.getPrototypeOf(node));
|
|
258
|
+
Object.assign(clone, node, { j: null, r: null, N: node });
|
|
259
|
+
ActiveTransition.a.set(node, clone);
|
|
260
|
+
node.h = ActiveTransition;
|
|
261
|
+
if (node.d) {
|
|
262
|
+
for (let i = 0, length = node.d.length; i < length; i++) {
|
|
263
|
+
const o = node.d[i];
|
|
264
|
+
node.d.push(cloneGraph(o));
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return clone;
|
|
268
|
+
}
|
|
269
|
+
function removeSourceObservers(node, index) {
|
|
270
|
+
let source;
|
|
271
|
+
let swap;
|
|
272
|
+
for (let i = index; i < node.a.length; i++) {
|
|
273
|
+
source = ActiveTransition && ActiveTransition.a.get(node.a[i]) || node.a[i];
|
|
274
|
+
if (source.d) {
|
|
275
|
+
if ((swap = source.d.indexOf(node)) !== -1) {
|
|
276
|
+
source.d[swap] = source.d[source.d.length - 1];
|
|
277
|
+
source.d.pop();
|
|
278
|
+
}
|
|
279
|
+
if (!source.d.length)
|
|
280
|
+
unobserved.push(source);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
function mergeTransitions(t1, t2) {
|
|
285
|
+
t2.a.forEach((value, key) => {
|
|
286
|
+
key.h = t1;
|
|
287
|
+
t1.a.set(key, value);
|
|
288
|
+
});
|
|
289
|
+
t2.T.forEach((c) => {
|
|
290
|
+
c.h = t1;
|
|
291
|
+
t1.T.add(c);
|
|
292
|
+
});
|
|
293
|
+
t2.M.forEach((p) => t1.M.add(p));
|
|
294
|
+
t2.t.forEach((n) => t1.t.add(n));
|
|
295
|
+
t2.o[0].forEach((f) => t1.o[0].push(f));
|
|
296
|
+
t2.o[1].forEach((f) => t1.o[1].push(f));
|
|
297
|
+
t2.F.forEach((f) => t1.F.push(f));
|
|
298
|
+
t2.q.forEach((c) => t1.addChild(c));
|
|
299
|
+
t2.E = t1;
|
|
300
|
+
Transitions.delete(t2);
|
|
301
|
+
}
|
|
302
|
+
function finishTransition(transition2) {
|
|
303
|
+
if (transition2.E || transition2.U || transition2.M.size || transition2.t.size)
|
|
304
|
+
return;
|
|
305
|
+
for (const [source, clone] of transition2.a) {
|
|
306
|
+
if (source === clone || source.h !== transition2)
|
|
307
|
+
continue;
|
|
308
|
+
if (clone.a)
|
|
309
|
+
removeSourceObservers(clone, 0);
|
|
310
|
+
source.dispose(false);
|
|
311
|
+
source.emptyDisposal();
|
|
312
|
+
Object.assign(source, clone);
|
|
313
|
+
delete source.N;
|
|
314
|
+
delete source.h;
|
|
315
|
+
}
|
|
316
|
+
transition2.E = true;
|
|
317
|
+
Transitions.delete(transition2);
|
|
318
|
+
transition2.run(EFFECT_RENDER);
|
|
319
|
+
transition2.run(EFFECT_USER);
|
|
320
|
+
for (const reset of transition2.T) {
|
|
321
|
+
delete reset.h;
|
|
322
|
+
reset();
|
|
323
|
+
}
|
|
324
|
+
}
|
|
111
325
|
|
|
112
326
|
// src/core/owner.ts
|
|
113
327
|
var currentOwner = null;
|
|
@@ -124,14 +338,14 @@ var Owner = class {
|
|
|
124
338
|
// We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
|
|
125
339
|
// However, the children are actually added in reverse creation order
|
|
126
340
|
// See comment at the top of the file for an example of the _nextSibling traversal
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
341
|
+
p = null;
|
|
342
|
+
r = null;
|
|
343
|
+
z = null;
|
|
344
|
+
b = STATE_CLEAN;
|
|
345
|
+
j = null;
|
|
346
|
+
u = defaultContext;
|
|
347
|
+
i = globalQueue;
|
|
348
|
+
da = 0;
|
|
135
349
|
id = null;
|
|
136
350
|
constructor(id = null, skipAppend = false) {
|
|
137
351
|
this.id = id;
|
|
@@ -140,64 +354,64 @@ var Owner = class {
|
|
|
140
354
|
}
|
|
141
355
|
}
|
|
142
356
|
append(child) {
|
|
143
|
-
child.
|
|
144
|
-
child.
|
|
145
|
-
if (this.
|
|
146
|
-
this.
|
|
147
|
-
child.
|
|
148
|
-
this.
|
|
357
|
+
child.p = this;
|
|
358
|
+
child.z = this;
|
|
359
|
+
if (this.r)
|
|
360
|
+
this.r.z = child;
|
|
361
|
+
child.r = this.r;
|
|
362
|
+
this.r = child;
|
|
149
363
|
if (this.id != null && child.id == null)
|
|
150
364
|
child.id = this.getNextChildId();
|
|
151
|
-
if (child.
|
|
152
|
-
child.
|
|
365
|
+
if (child.u !== this.u) {
|
|
366
|
+
child.u = { ...this.u, ...child.u };
|
|
153
367
|
}
|
|
154
|
-
if (this.
|
|
155
|
-
child.
|
|
368
|
+
if (this.i)
|
|
369
|
+
child.i = this.i;
|
|
156
370
|
}
|
|
157
371
|
dispose(self = true) {
|
|
158
|
-
if (this.
|
|
372
|
+
if (this.b === STATE_DISPOSED)
|
|
159
373
|
return;
|
|
160
|
-
let head = self ? this.
|
|
161
|
-
while (current && current.
|
|
374
|
+
let head = self ? this.z || this.p : this, current = this.r, next = null;
|
|
375
|
+
while (current && current.p === this) {
|
|
162
376
|
current.dispose(true);
|
|
163
|
-
current.
|
|
164
|
-
next = current.
|
|
165
|
-
current.
|
|
377
|
+
current.G();
|
|
378
|
+
next = current.r;
|
|
379
|
+
current.r = null;
|
|
166
380
|
current = next;
|
|
167
381
|
}
|
|
168
|
-
this.
|
|
382
|
+
this.da = 0;
|
|
169
383
|
if (self)
|
|
170
|
-
this.
|
|
384
|
+
this.G();
|
|
171
385
|
if (current)
|
|
172
|
-
current.
|
|
386
|
+
current.z = !self ? this : this.z;
|
|
173
387
|
if (head)
|
|
174
|
-
head.
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (this.
|
|
178
|
-
this.
|
|
179
|
-
this.
|
|
180
|
-
this.
|
|
181
|
-
this.
|
|
182
|
-
this.
|
|
388
|
+
head.r = current;
|
|
389
|
+
}
|
|
390
|
+
G() {
|
|
391
|
+
if (this.z)
|
|
392
|
+
this.z.r = null;
|
|
393
|
+
this.p = null;
|
|
394
|
+
this.z = null;
|
|
395
|
+
this.u = defaultContext;
|
|
396
|
+
this.b = STATE_DISPOSED;
|
|
183
397
|
this.emptyDisposal();
|
|
184
398
|
}
|
|
185
399
|
emptyDisposal() {
|
|
186
|
-
if (!this.
|
|
400
|
+
if (!this.j)
|
|
187
401
|
return;
|
|
188
|
-
if (Array.isArray(this.
|
|
189
|
-
for (let i = 0; i < this.
|
|
190
|
-
const callable = this.
|
|
402
|
+
if (Array.isArray(this.j)) {
|
|
403
|
+
for (let i = 0; i < this.j.length; i++) {
|
|
404
|
+
const callable = this.j[i];
|
|
191
405
|
callable.call(callable);
|
|
192
406
|
}
|
|
193
407
|
} else {
|
|
194
|
-
this.
|
|
408
|
+
this.j.call(this.j);
|
|
195
409
|
}
|
|
196
|
-
this.
|
|
410
|
+
this.j = null;
|
|
197
411
|
}
|
|
198
412
|
getNextChildId() {
|
|
199
413
|
if (this.id != null)
|
|
200
|
-
return formatId(this.id, this.
|
|
414
|
+
return formatId(this.id, this.da++);
|
|
201
415
|
throw new Error("Cannot get child id from owner without an id");
|
|
202
416
|
}
|
|
203
417
|
};
|
|
@@ -208,7 +422,7 @@ function getContext(context, owner = currentOwner) {
|
|
|
208
422
|
if (!owner) {
|
|
209
423
|
throw new NoOwnerError();
|
|
210
424
|
}
|
|
211
|
-
const value = hasContext(context, owner) ? owner.
|
|
425
|
+
const value = hasContext(context, owner) ? owner.u[context.id] : context.defaultValue;
|
|
212
426
|
if (isUndefined(value)) {
|
|
213
427
|
throw new ContextNotFoundError();
|
|
214
428
|
}
|
|
@@ -218,24 +432,24 @@ function setContext(context, value, owner = currentOwner) {
|
|
|
218
432
|
if (!owner) {
|
|
219
433
|
throw new NoOwnerError();
|
|
220
434
|
}
|
|
221
|
-
owner.
|
|
222
|
-
...owner.
|
|
435
|
+
owner.u = {
|
|
436
|
+
...owner.u,
|
|
223
437
|
[context.id]: isUndefined(value) ? context.defaultValue : value
|
|
224
438
|
};
|
|
225
439
|
}
|
|
226
440
|
function hasContext(context, owner = currentOwner) {
|
|
227
|
-
return !isUndefined(owner == null ? void 0 : owner.
|
|
441
|
+
return !isUndefined(owner == null ? void 0 : owner.u[context.id]);
|
|
228
442
|
}
|
|
229
443
|
function onCleanup(fn) {
|
|
230
444
|
if (!currentOwner)
|
|
231
445
|
return fn;
|
|
232
446
|
const node = currentOwner;
|
|
233
|
-
if (!node.
|
|
234
|
-
node.
|
|
235
|
-
} else if (Array.isArray(node.
|
|
236
|
-
node.
|
|
447
|
+
if (!node.j) {
|
|
448
|
+
node.j = fn;
|
|
449
|
+
} else if (Array.isArray(node.j)) {
|
|
450
|
+
node.j.push(fn);
|
|
237
451
|
} else {
|
|
238
|
-
node.
|
|
452
|
+
node.j = [node.j, fn];
|
|
239
453
|
}
|
|
240
454
|
return fn;
|
|
241
455
|
}
|
|
@@ -247,22 +461,12 @@ function isUndefined(value) {
|
|
|
247
461
|
return typeof value === "undefined";
|
|
248
462
|
}
|
|
249
463
|
|
|
250
|
-
// src/core/flags.ts
|
|
251
|
-
var ERROR_OFFSET = 0;
|
|
252
|
-
var ERROR_BIT = 1 << ERROR_OFFSET;
|
|
253
|
-
var LOADING_OFFSET = 1;
|
|
254
|
-
var LOADING_BIT = 1 << LOADING_OFFSET;
|
|
255
|
-
var UNINITIALIZED_OFFSET = 2;
|
|
256
|
-
var UNINITIALIZED_BIT = 1 << UNINITIALIZED_OFFSET;
|
|
257
|
-
var DEFAULT_FLAGS = ERROR_BIT;
|
|
258
|
-
|
|
259
464
|
// src/core/core.ts
|
|
260
465
|
var currentObserver = null;
|
|
261
466
|
var currentMask = DEFAULT_FLAGS;
|
|
262
467
|
var newSources = null;
|
|
263
468
|
var newSourcesIndex = 0;
|
|
264
469
|
var newFlags = 0;
|
|
265
|
-
var unobserved = [];
|
|
266
470
|
var notStale = false;
|
|
267
471
|
var updateCheck = null;
|
|
268
472
|
var staleCheck = null;
|
|
@@ -271,48 +475,48 @@ function getObserver() {
|
|
|
271
475
|
}
|
|
272
476
|
var UNCHANGED = Symbol(0);
|
|
273
477
|
var Computation = class extends Owner {
|
|
274
|
-
|
|
478
|
+
a = null;
|
|
275
479
|
d = null;
|
|
276
480
|
g;
|
|
277
|
-
|
|
278
|
-
|
|
481
|
+
O;
|
|
482
|
+
H;
|
|
279
483
|
// Used in __DEV__ mode, hopefully removed in production
|
|
280
|
-
|
|
484
|
+
ja;
|
|
281
485
|
// Using false is an optimization as an alternative to _equals: () => false
|
|
282
486
|
// which could enable more efficient DIRTY notification
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
487
|
+
_ = isEqual;
|
|
488
|
+
ca;
|
|
489
|
+
fa = false;
|
|
286
490
|
/** Whether the computation is an error or has ancestors that are unresolved */
|
|
287
491
|
f = 0;
|
|
288
492
|
/** Which flags raised by sources are handled, vs. being passed through. */
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
493
|
+
$ = DEFAULT_FLAGS;
|
|
494
|
+
I = -1;
|
|
495
|
+
C = false;
|
|
496
|
+
h;
|
|
497
|
+
N;
|
|
292
498
|
constructor(initialValue, compute2, options) {
|
|
293
499
|
super(options == null ? void 0 : options.id, compute2 === null);
|
|
294
|
-
this.
|
|
295
|
-
this.
|
|
500
|
+
this.H = compute2;
|
|
501
|
+
this.b = compute2 ? STATE_DIRTY : STATE_CLEAN;
|
|
296
502
|
this.f = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
|
|
297
503
|
this.g = initialValue;
|
|
298
504
|
if ((options == null ? void 0 : options.equals) !== void 0)
|
|
299
|
-
this.
|
|
505
|
+
this._ = options.equals;
|
|
300
506
|
if (options == null ? void 0 : options.pureWrite)
|
|
301
|
-
this.
|
|
507
|
+
this.fa = true;
|
|
302
508
|
if (options == null ? void 0 : options.unobserved)
|
|
303
|
-
this.
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
if (this.f & ERROR_BIT && this.A <= getClock())
|
|
308
|
-
update(this);
|
|
309
|
-
else
|
|
310
|
-
this.x();
|
|
509
|
+
this.ca = options == null ? void 0 : options.unobserved;
|
|
510
|
+
if (ActiveTransition) {
|
|
511
|
+
this.h = ActiveTransition;
|
|
512
|
+
ActiveTransition.a.set(this, this);
|
|
311
513
|
}
|
|
514
|
+
}
|
|
515
|
+
ea() {
|
|
312
516
|
track(this);
|
|
313
517
|
newFlags |= this.f & ~currentMask;
|
|
314
518
|
if (this.f & ERROR_BIT) {
|
|
315
|
-
throw this.
|
|
519
|
+
throw this.O;
|
|
316
520
|
} else {
|
|
317
521
|
return this.g;
|
|
318
522
|
}
|
|
@@ -322,7 +526,18 @@ var Computation = class extends Owner {
|
|
|
322
526
|
* Automatically re-executes the surrounding computation when the value changes
|
|
323
527
|
*/
|
|
324
528
|
read() {
|
|
325
|
-
|
|
529
|
+
if (ActiveTransition && ActiveTransition.a.has(this)) {
|
|
530
|
+
const clone = ActiveTransition.a.get(this);
|
|
531
|
+
if (clone !== this)
|
|
532
|
+
return clone.read();
|
|
533
|
+
}
|
|
534
|
+
if (this.H) {
|
|
535
|
+
if (this.f & ERROR_BIT && this.I <= clock)
|
|
536
|
+
update(this);
|
|
537
|
+
else
|
|
538
|
+
this.D();
|
|
539
|
+
}
|
|
540
|
+
return this.ea();
|
|
326
541
|
}
|
|
327
542
|
/**
|
|
328
543
|
* Return the current value of this computation
|
|
@@ -332,38 +547,48 @@ var Computation = class extends Owner {
|
|
|
332
547
|
* before continuing
|
|
333
548
|
*/
|
|
334
549
|
wait() {
|
|
335
|
-
if (
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
550
|
+
if (ActiveTransition && ActiveTransition.a.has(this)) {
|
|
551
|
+
const clone = ActiveTransition.a.get(this);
|
|
552
|
+
if (clone !== this)
|
|
553
|
+
return clone.wait();
|
|
554
|
+
}
|
|
555
|
+
if (this.H) {
|
|
556
|
+
if (this.f & ERROR_BIT && this.I <= clock)
|
|
557
|
+
update(this);
|
|
558
|
+
else
|
|
559
|
+
this.D();
|
|
339
560
|
}
|
|
340
|
-
track(this);
|
|
341
561
|
if ((notStale || this.f & UNINITIALIZED_BIT) && this.f & LOADING_BIT) {
|
|
562
|
+
track(this);
|
|
342
563
|
throw new NotReadyError();
|
|
343
564
|
}
|
|
344
565
|
if (staleCheck && this.f & LOADING_BIT) {
|
|
345
566
|
staleCheck.g = true;
|
|
346
567
|
}
|
|
347
|
-
return this.
|
|
568
|
+
return this.ea();
|
|
348
569
|
}
|
|
349
570
|
/** Update the computation with a new value. */
|
|
350
571
|
write(value, flags = 0, raw = false) {
|
|
572
|
+
if (ActiveTransition && !this.N) {
|
|
573
|
+
const clone = cloneGraph(this);
|
|
574
|
+
return clone.write(value, flags, raw);
|
|
575
|
+
}
|
|
351
576
|
const newValue = !raw && typeof value === "function" ? value(this.g) : value;
|
|
352
577
|
const valueChanged = newValue !== UNCHANGED && (!!(this.f & UNINITIALIZED_BIT) || // this._stateFlags & LOADING_BIT & ~flags ||
|
|
353
|
-
this.
|
|
578
|
+
this._ === false || !this._(this.g, newValue));
|
|
354
579
|
if (valueChanged) {
|
|
355
580
|
this.g = newValue;
|
|
356
|
-
this.
|
|
581
|
+
this.O = void 0;
|
|
357
582
|
}
|
|
358
583
|
const changedFlagsMask = this.f ^ flags, changedFlags = changedFlagsMask & flags;
|
|
359
584
|
this.f = flags;
|
|
360
|
-
this.
|
|
585
|
+
this.I = clock + 1;
|
|
361
586
|
if (this.d) {
|
|
362
587
|
for (let i = 0; i < this.d.length; i++) {
|
|
363
588
|
if (valueChanged) {
|
|
364
|
-
this.d[i].
|
|
589
|
+
this.d[i].k(STATE_DIRTY);
|
|
365
590
|
} else if (changedFlagsMask) {
|
|
366
|
-
this.d[i].
|
|
591
|
+
this.d[i].V(changedFlagsMask, changedFlags);
|
|
367
592
|
}
|
|
368
593
|
}
|
|
369
594
|
}
|
|
@@ -372,14 +597,19 @@ var Computation = class extends Owner {
|
|
|
372
597
|
/**
|
|
373
598
|
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
|
374
599
|
*/
|
|
375
|
-
|
|
376
|
-
if (
|
|
600
|
+
k(state, skipQueue) {
|
|
601
|
+
if (ActiveTransition && ActiveTransition.a.has(this)) {
|
|
602
|
+
const clone = ActiveTransition.a.get(this);
|
|
603
|
+
if (clone !== this)
|
|
604
|
+
return clone.k(state, skipQueue);
|
|
605
|
+
}
|
|
606
|
+
if (this.b >= state && !this.C)
|
|
377
607
|
return;
|
|
378
|
-
this.
|
|
379
|
-
this.
|
|
608
|
+
this.C = !!skipQueue;
|
|
609
|
+
this.b = state;
|
|
380
610
|
if (this.d) {
|
|
381
611
|
for (let i = 0; i < this.d.length; i++) {
|
|
382
|
-
this.d[i].
|
|
612
|
+
this.d[i].k(STATE_CHECK, skipQueue);
|
|
383
613
|
}
|
|
384
614
|
}
|
|
385
615
|
}
|
|
@@ -389,30 +619,30 @@ var Computation = class extends Owner {
|
|
|
389
619
|
* @param mask A bitmask for which flag(s) were changed.
|
|
390
620
|
* @param newFlags The source's new flags, masked to just the changed ones.
|
|
391
621
|
*/
|
|
392
|
-
|
|
393
|
-
if (this.
|
|
622
|
+
V(mask, newFlags2) {
|
|
623
|
+
if (this.b >= STATE_DIRTY)
|
|
394
624
|
return;
|
|
395
|
-
if (mask & this
|
|
396
|
-
this.
|
|
625
|
+
if (mask & this.$) {
|
|
626
|
+
this.k(STATE_DIRTY);
|
|
397
627
|
return;
|
|
398
628
|
}
|
|
399
|
-
if (this.
|
|
629
|
+
if (this.b >= STATE_CHECK)
|
|
400
630
|
return;
|
|
401
631
|
const prevFlags = this.f & mask;
|
|
402
632
|
const deltaFlags = prevFlags ^ newFlags2;
|
|
403
633
|
if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
|
|
404
|
-
this.
|
|
634
|
+
this.k(STATE_CHECK);
|
|
405
635
|
} else {
|
|
406
636
|
this.f ^= deltaFlags;
|
|
407
637
|
if (this.d) {
|
|
408
638
|
for (let i = 0; i < this.d.length; i++) {
|
|
409
|
-
this.d[i].
|
|
639
|
+
this.d[i].V(mask, newFlags2);
|
|
410
640
|
}
|
|
411
641
|
}
|
|
412
642
|
}
|
|
413
643
|
}
|
|
414
|
-
|
|
415
|
-
this.
|
|
644
|
+
P(error) {
|
|
645
|
+
this.O = error;
|
|
416
646
|
this.write(UNCHANGED, this.f & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
|
|
417
647
|
}
|
|
418
648
|
/**
|
|
@@ -422,47 +652,50 @@ var Computation = class extends Owner {
|
|
|
422
652
|
*
|
|
423
653
|
* This function will ensure that the value and states we read from the computation are up to date
|
|
424
654
|
*/
|
|
425
|
-
|
|
426
|
-
if (!this.
|
|
655
|
+
D() {
|
|
656
|
+
if (!this.H) {
|
|
427
657
|
return;
|
|
428
658
|
}
|
|
429
|
-
if (this.
|
|
659
|
+
if (this.b === STATE_DISPOSED) {
|
|
430
660
|
return;
|
|
431
661
|
}
|
|
432
|
-
if (this.
|
|
662
|
+
if (this.b === STATE_CLEAN) {
|
|
433
663
|
return;
|
|
434
664
|
}
|
|
435
665
|
let observerFlags = 0;
|
|
436
|
-
if (this.
|
|
437
|
-
for (let i = 0; i < this.
|
|
438
|
-
this.
|
|
439
|
-
|
|
440
|
-
|
|
666
|
+
if (this.b === STATE_CHECK) {
|
|
667
|
+
for (let i = 0; i < this.a.length; i++) {
|
|
668
|
+
const source = ActiveTransition && ActiveTransition.a.get(this.a[i]) || this.a[i];
|
|
669
|
+
source.D();
|
|
670
|
+
observerFlags |= source.f;
|
|
671
|
+
if (this.b === STATE_DIRTY) {
|
|
441
672
|
break;
|
|
442
673
|
}
|
|
443
674
|
}
|
|
444
675
|
}
|
|
445
|
-
if (this.
|
|
676
|
+
if (this.b === STATE_DIRTY) {
|
|
446
677
|
update(this);
|
|
447
678
|
} else {
|
|
448
679
|
this.write(UNCHANGED, observerFlags);
|
|
449
|
-
this.
|
|
680
|
+
this.b = STATE_CLEAN;
|
|
450
681
|
}
|
|
451
682
|
}
|
|
452
683
|
/**
|
|
453
684
|
* Remove ourselves from the owner graph and the computation graph
|
|
454
685
|
*/
|
|
455
|
-
|
|
456
|
-
if (this.
|
|
686
|
+
G() {
|
|
687
|
+
if (this.b === STATE_DISPOSED)
|
|
457
688
|
return;
|
|
458
|
-
if (this.
|
|
689
|
+
if (this.a)
|
|
459
690
|
removeSourceObservers(this, 0);
|
|
460
|
-
super.
|
|
691
|
+
super.G();
|
|
461
692
|
}
|
|
462
693
|
};
|
|
463
694
|
function track(computation) {
|
|
695
|
+
if (ActiveTransition && computation.N)
|
|
696
|
+
computation = computation.N;
|
|
464
697
|
if (currentObserver) {
|
|
465
|
-
if (!newSources && currentObserver.
|
|
698
|
+
if (!newSources && currentObserver.a && currentObserver.a[newSourcesIndex] === computation) {
|
|
466
699
|
newSourcesIndex++;
|
|
467
700
|
} else if (!newSources)
|
|
468
701
|
newSources = [computation];
|
|
@@ -470,7 +703,7 @@ function track(computation) {
|
|
|
470
703
|
newSources.push(computation);
|
|
471
704
|
}
|
|
472
705
|
if (updateCheck) {
|
|
473
|
-
updateCheck.g = computation.
|
|
706
|
+
updateCheck.g = computation.I > currentObserver.I;
|
|
474
707
|
}
|
|
475
708
|
}
|
|
476
709
|
}
|
|
@@ -482,68 +715,44 @@ function update(node) {
|
|
|
482
715
|
try {
|
|
483
716
|
node.dispose(false);
|
|
484
717
|
node.emptyDisposal();
|
|
485
|
-
const result = compute(node, node.
|
|
718
|
+
const result = compute(node, node.H, node);
|
|
486
719
|
node.write(result, newFlags, true);
|
|
487
720
|
} catch (error) {
|
|
488
721
|
if (error instanceof NotReadyError) {
|
|
489
722
|
node.write(UNCHANGED, newFlags | LOADING_BIT | node.f & UNINITIALIZED_BIT);
|
|
490
723
|
} else {
|
|
491
|
-
node.
|
|
724
|
+
node.P(error);
|
|
492
725
|
}
|
|
493
726
|
} finally {
|
|
494
727
|
if (newSources) {
|
|
495
|
-
if (node.
|
|
728
|
+
if (node.a)
|
|
496
729
|
removeSourceObservers(node, newSourcesIndex);
|
|
497
|
-
if (node.
|
|
498
|
-
node.
|
|
730
|
+
if (node.a && newSourcesIndex > 0) {
|
|
731
|
+
node.a.length = newSourcesIndex + newSources.length;
|
|
499
732
|
for (let i = 0; i < newSources.length; i++) {
|
|
500
|
-
node.
|
|
733
|
+
node.a[newSourcesIndex + i] = newSources[i];
|
|
501
734
|
}
|
|
502
735
|
} else {
|
|
503
|
-
node.
|
|
736
|
+
node.a = newSources;
|
|
504
737
|
}
|
|
505
738
|
let source;
|
|
506
|
-
for (let i = newSourcesIndex; i < node.
|
|
507
|
-
source = node.
|
|
739
|
+
for (let i = newSourcesIndex; i < node.a.length; i++) {
|
|
740
|
+
source = node.a[i];
|
|
508
741
|
if (!source.d)
|
|
509
742
|
source.d = [node];
|
|
510
743
|
else
|
|
511
744
|
source.d.push(node);
|
|
512
745
|
}
|
|
513
|
-
} else if (node.
|
|
746
|
+
} else if (node.a && newSourcesIndex < node.a.length) {
|
|
514
747
|
removeSourceObservers(node, newSourcesIndex);
|
|
515
|
-
node.
|
|
748
|
+
node.a.length = newSourcesIndex;
|
|
516
749
|
}
|
|
517
|
-
unobserved.length && notifyUnobserved();
|
|
518
750
|
newSources = prevSources;
|
|
519
751
|
newSourcesIndex = prevSourcesIndex;
|
|
520
752
|
newFlags = prevFlags;
|
|
521
|
-
node.
|
|
522
|
-
node.
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
function removeSourceObservers(node, index) {
|
|
526
|
-
let source;
|
|
527
|
-
let swap;
|
|
528
|
-
for (let i = index; i < node.c.length; i++) {
|
|
529
|
-
source = node.c[i];
|
|
530
|
-
if (source.d) {
|
|
531
|
-
swap = source.d.indexOf(node);
|
|
532
|
-
source.d[swap] = source.d[source.d.length - 1];
|
|
533
|
-
source.d.pop();
|
|
534
|
-
if (!source.d.length)
|
|
535
|
-
unobserved.push(source);
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
function notifyUnobserved() {
|
|
540
|
-
var _a, _b;
|
|
541
|
-
for (let i = 0; i < unobserved.length; i++) {
|
|
542
|
-
const source = unobserved[i];
|
|
543
|
-
if (!source.d || !source.d.length)
|
|
544
|
-
(_b = (_a = unobserved[i]).X) == null ? void 0 : _b.call(_a);
|
|
753
|
+
node.I = clock + 1;
|
|
754
|
+
node.b = STATE_CLEAN;
|
|
545
755
|
}
|
|
546
|
-
unobserved = [];
|
|
547
756
|
}
|
|
548
757
|
function isEqual(a, b) {
|
|
549
758
|
return a === b;
|
|
@@ -583,7 +792,7 @@ function isPending(fn, loadingValue) {
|
|
|
583
792
|
if (!currentObserver)
|
|
584
793
|
return pendingCheck(fn, loadingValue);
|
|
585
794
|
const c = new Computation(void 0, () => pendingCheck(fn, loadingValue));
|
|
586
|
-
c
|
|
795
|
+
c.$ |= LOADING_BIT;
|
|
587
796
|
return c.read();
|
|
588
797
|
}
|
|
589
798
|
function latest(fn, fallback) {
|
|
@@ -605,7 +814,7 @@ function latest(fn, fallback) {
|
|
|
605
814
|
function runWithObserver(observer, run) {
|
|
606
815
|
const prevSources = newSources, prevSourcesIndex = newSourcesIndex, prevFlags = newFlags;
|
|
607
816
|
newSources = null;
|
|
608
|
-
newSourcesIndex = observer.
|
|
817
|
+
newSourcesIndex = observer.a ? observer.a.length : 0;
|
|
609
818
|
newFlags = 0;
|
|
610
819
|
try {
|
|
611
820
|
return compute(observer, run, observer);
|
|
@@ -616,21 +825,21 @@ function runWithObserver(observer, run) {
|
|
|
616
825
|
newFlags | LOADING_BIT | observer.f & UNINITIALIZED_BIT
|
|
617
826
|
);
|
|
618
827
|
} else {
|
|
619
|
-
observer.
|
|
828
|
+
observer.P(error);
|
|
620
829
|
}
|
|
621
830
|
} finally {
|
|
622
831
|
if (newSources) {
|
|
623
832
|
if (newSourcesIndex > 0) {
|
|
624
|
-
observer.
|
|
833
|
+
observer.a.length = newSourcesIndex + newSources.length;
|
|
625
834
|
for (let i = 0; i < newSources.length; i++) {
|
|
626
|
-
observer.
|
|
835
|
+
observer.a[newSourcesIndex + i] = newSources[i];
|
|
627
836
|
}
|
|
628
837
|
} else {
|
|
629
|
-
observer.
|
|
838
|
+
observer.a = newSources;
|
|
630
839
|
}
|
|
631
840
|
let source;
|
|
632
|
-
for (let i = newSourcesIndex; i < observer.
|
|
633
|
-
source = observer.
|
|
841
|
+
for (let i = newSourcesIndex; i < observer.a.length; i++) {
|
|
842
|
+
source = observer.a[i];
|
|
634
843
|
if (!source.d)
|
|
635
844
|
source.d = [observer];
|
|
636
845
|
else
|
|
@@ -645,7 +854,7 @@ function runWithObserver(observer, run) {
|
|
|
645
854
|
function compute(owner, fn, observer) {
|
|
646
855
|
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask, prevNotStale = notStale;
|
|
647
856
|
currentObserver = observer;
|
|
648
|
-
currentMask = (observer == null ? void 0 : observer
|
|
857
|
+
currentMask = (observer == null ? void 0 : observer.$) ?? DEFAULT_FLAGS;
|
|
649
858
|
notStale = true;
|
|
650
859
|
try {
|
|
651
860
|
return fn(observer ? observer.g : void 0);
|
|
@@ -659,107 +868,123 @@ function compute(owner, fn, observer) {
|
|
|
659
868
|
|
|
660
869
|
// src/core/effect.ts
|
|
661
870
|
var Effect = class extends Computation {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
871
|
+
aa;
|
|
872
|
+
W;
|
|
873
|
+
J;
|
|
874
|
+
ba = false;
|
|
875
|
+
X;
|
|
876
|
+
y;
|
|
668
877
|
constructor(initialValue, compute2, effect, error, options) {
|
|
669
878
|
super(initialValue, compute2, options);
|
|
670
|
-
this.
|
|
671
|
-
this.
|
|
672
|
-
this.
|
|
673
|
-
this.
|
|
674
|
-
if (this.
|
|
675
|
-
this.
|
|
879
|
+
this.aa = effect;
|
|
880
|
+
this.W = error;
|
|
881
|
+
this.X = initialValue;
|
|
882
|
+
this.y = (options == null ? void 0 : options.render) ? EFFECT_RENDER : EFFECT_USER;
|
|
883
|
+
if (this.y === EFFECT_RENDER) {
|
|
884
|
+
this.H = (p) => !ActiveTransition && clock > this.i.created && !(this.f & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
|
|
676
885
|
}
|
|
677
|
-
this.
|
|
678
|
-
!(options == null ? void 0 : options.defer) && (this.
|
|
886
|
+
this.D();
|
|
887
|
+
!(options == null ? void 0 : options.defer) && (this.y === EFFECT_USER ? (ActiveTransition || this.i).enqueue(this.y, this.A.bind(this)) : this.A(this.y));
|
|
679
888
|
}
|
|
680
889
|
write(value, flags = 0) {
|
|
681
|
-
if (this.
|
|
682
|
-
this.f;
|
|
890
|
+
if (this.b == STATE_DIRTY || flags !== this.f) {
|
|
683
891
|
this.f = flags;
|
|
684
|
-
if (this.
|
|
685
|
-
this.
|
|
892
|
+
if (this.y === EFFECT_RENDER) {
|
|
893
|
+
(ActiveTransition || this.i).notify(this, LOADING_BIT | ERROR_BIT, flags);
|
|
686
894
|
}
|
|
687
895
|
}
|
|
688
896
|
if (value === UNCHANGED)
|
|
689
897
|
return this.g;
|
|
690
898
|
this.g = value;
|
|
691
|
-
this.
|
|
899
|
+
this.ba = true;
|
|
692
900
|
return value;
|
|
693
901
|
}
|
|
694
|
-
|
|
695
|
-
if (
|
|
902
|
+
k(state, skipQueue) {
|
|
903
|
+
if (ActiveTransition && ActiveTransition.a.has(this)) {
|
|
904
|
+
return ActiveTransition.a.get(this).k(state, skipQueue);
|
|
905
|
+
}
|
|
906
|
+
if (this.b >= state || skipQueue)
|
|
696
907
|
return;
|
|
697
|
-
if (this.
|
|
698
|
-
this.
|
|
699
|
-
this.
|
|
908
|
+
if (this.b === STATE_CLEAN)
|
|
909
|
+
(ActiveTransition || this.i).enqueue(this.y, this.A.bind(this));
|
|
910
|
+
this.b = state;
|
|
700
911
|
}
|
|
701
|
-
|
|
702
|
-
this
|
|
703
|
-
|
|
912
|
+
V(mask, newFlags2) {
|
|
913
|
+
if (ActiveTransition && ActiveTransition.a.has(this)) {
|
|
914
|
+
if (this.b >= STATE_CHECK)
|
|
915
|
+
return;
|
|
916
|
+
if (mask & 3) {
|
|
917
|
+
this.k(STATE_DIRTY);
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
super.V(mask, newFlags2);
|
|
922
|
+
}
|
|
923
|
+
P(error) {
|
|
924
|
+
this.O = error;
|
|
925
|
+
(ActiveTransition || this.i).notify(this, LOADING_BIT, 0);
|
|
704
926
|
this.f = ERROR_BIT;
|
|
705
|
-
if (this.
|
|
927
|
+
if (this.y === EFFECT_USER) {
|
|
706
928
|
try {
|
|
707
|
-
return this.
|
|
929
|
+
return this.W ? this.W(error, () => {
|
|
708
930
|
var _a;
|
|
709
|
-
(_a = this.
|
|
710
|
-
this.
|
|
931
|
+
(_a = this.J) == null ? void 0 : _a.call(this);
|
|
932
|
+
this.J = void 0;
|
|
711
933
|
}) : console.error(error);
|
|
712
934
|
} catch (e) {
|
|
713
935
|
error = e;
|
|
714
936
|
}
|
|
715
937
|
}
|
|
716
|
-
if (!this.
|
|
938
|
+
if (!(ActiveTransition || this.i).notify(this, ERROR_BIT, ERROR_BIT))
|
|
717
939
|
throw error;
|
|
718
940
|
}
|
|
719
|
-
|
|
941
|
+
G() {
|
|
720
942
|
var _a;
|
|
721
|
-
if (this.
|
|
943
|
+
if (this.b === STATE_DISPOSED)
|
|
722
944
|
return;
|
|
723
|
-
this.
|
|
724
|
-
this.
|
|
725
|
-
this.
|
|
726
|
-
(_a = this.
|
|
727
|
-
this.
|
|
728
|
-
super.
|
|
729
|
-
}
|
|
730
|
-
|
|
945
|
+
this.aa = void 0;
|
|
946
|
+
this.X = void 0;
|
|
947
|
+
this.W = void 0;
|
|
948
|
+
(_a = this.J) == null ? void 0 : _a.call(this);
|
|
949
|
+
this.J = void 0;
|
|
950
|
+
super.G();
|
|
951
|
+
}
|
|
952
|
+
A(type) {
|
|
731
953
|
var _a;
|
|
732
954
|
if (type) {
|
|
733
|
-
if (this.
|
|
734
|
-
(_a = this.
|
|
955
|
+
if (this.ba && this.b !== STATE_DISPOSED) {
|
|
956
|
+
(_a = this.J) == null ? void 0 : _a.call(this);
|
|
735
957
|
try {
|
|
736
|
-
this.
|
|
958
|
+
this.J = this.aa(this.g, this.X);
|
|
737
959
|
} catch (e) {
|
|
738
|
-
if (!this.
|
|
960
|
+
if (!(ActiveTransition || this.i).notify(this, ERROR_BIT, ERROR_BIT))
|
|
739
961
|
throw e;
|
|
740
962
|
} finally {
|
|
741
|
-
this.
|
|
742
|
-
this.
|
|
963
|
+
this.X = this.g;
|
|
964
|
+
this.ba = false;
|
|
743
965
|
}
|
|
744
966
|
}
|
|
745
967
|
} else
|
|
746
|
-
this.
|
|
968
|
+
this.b !== STATE_CLEAN && runTop(this);
|
|
747
969
|
}
|
|
748
970
|
};
|
|
749
|
-
function runComputation() {
|
|
750
|
-
this.a !== STATE_CLEAN && runTop(this);
|
|
751
|
-
}
|
|
752
971
|
var EagerComputation = class extends Computation {
|
|
753
972
|
constructor(initialValue, compute2, options) {
|
|
754
973
|
super(initialValue, compute2, options);
|
|
755
|
-
!(options == null ? void 0 : options.defer) && this.
|
|
974
|
+
!(options == null ? void 0 : options.defer) && this.D();
|
|
756
975
|
}
|
|
757
|
-
|
|
758
|
-
if (
|
|
976
|
+
k(state, skipQueue) {
|
|
977
|
+
if (ActiveTransition && ActiveTransition.a.has(this)) {
|
|
978
|
+
return ActiveTransition.a.get(this).k(state, skipQueue);
|
|
979
|
+
}
|
|
980
|
+
if (this.b >= state && !this.C)
|
|
759
981
|
return;
|
|
760
|
-
if (!skipQueue && (this.
|
|
761
|
-
this.
|
|
762
|
-
super.
|
|
982
|
+
if (!skipQueue && (this.b === STATE_CLEAN || this.b === STATE_CHECK && this.C))
|
|
983
|
+
(ActiveTransition || this.i).enqueue(EFFECT_PURE, this.A.bind(this));
|
|
984
|
+
super.k(state, skipQueue);
|
|
985
|
+
}
|
|
986
|
+
A() {
|
|
987
|
+
this.b !== STATE_CLEAN && runTop(this);
|
|
763
988
|
}
|
|
764
989
|
};
|
|
765
990
|
var FirewallComputation = class extends Computation {
|
|
@@ -767,191 +992,34 @@ var FirewallComputation = class extends Computation {
|
|
|
767
992
|
constructor(compute2) {
|
|
768
993
|
super(void 0, compute2);
|
|
769
994
|
}
|
|
770
|
-
|
|
771
|
-
if (
|
|
995
|
+
k(state, skipQueue) {
|
|
996
|
+
if (ActiveTransition && ActiveTransition.a.has(this)) {
|
|
997
|
+
return ActiveTransition.a.get(this).k(state, skipQueue);
|
|
998
|
+
}
|
|
999
|
+
if (this.b >= state && !this.C)
|
|
772
1000
|
return;
|
|
773
|
-
if (!skipQueue && (this.
|
|
774
|
-
this.
|
|
775
|
-
super.
|
|
776
|
-
this.
|
|
1001
|
+
if (!skipQueue && (this.b === STATE_CLEAN || this.b === STATE_CHECK && this.C))
|
|
1002
|
+
(ActiveTransition || this.i).enqueue(EFFECT_PURE, this.A.bind(this));
|
|
1003
|
+
super.k(state, true);
|
|
1004
|
+
this.C = !!skipQueue;
|
|
1005
|
+
}
|
|
1006
|
+
A() {
|
|
1007
|
+
this.b !== STATE_CLEAN && runTop(this);
|
|
777
1008
|
}
|
|
778
1009
|
};
|
|
779
1010
|
function runTop(node) {
|
|
780
1011
|
const ancestors = [];
|
|
781
|
-
for (let current = node; current !== null; current = current.
|
|
782
|
-
if (current.
|
|
1012
|
+
for (let current = node; current !== null; current = current.p) {
|
|
1013
|
+
if (current.b !== STATE_CLEAN) {
|
|
783
1014
|
ancestors.push(current);
|
|
784
1015
|
}
|
|
785
1016
|
}
|
|
786
1017
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
787
|
-
if (ancestors[i].
|
|
788
|
-
ancestors[i].
|
|
1018
|
+
if (ancestors[i].b !== STATE_DISPOSED)
|
|
1019
|
+
ancestors[i].D();
|
|
789
1020
|
}
|
|
790
1021
|
}
|
|
791
1022
|
|
|
792
|
-
// src/signals.ts
|
|
793
|
-
function createSignal(first, second, third) {
|
|
794
|
-
if (typeof first === "function") {
|
|
795
|
-
const memo = createMemo((p) => {
|
|
796
|
-
const node2 = new Computation(
|
|
797
|
-
first(p ? untrack(p[0]) : second),
|
|
798
|
-
null,
|
|
799
|
-
third
|
|
800
|
-
);
|
|
801
|
-
return [node2.read.bind(node2), node2.write.bind(node2)];
|
|
802
|
-
});
|
|
803
|
-
return [() => memo()[0](), (value) => memo()[1](value)];
|
|
804
|
-
}
|
|
805
|
-
const o = getOwner();
|
|
806
|
-
const needsId = (o == null ? void 0 : o.id) != null;
|
|
807
|
-
const node = new Computation(
|
|
808
|
-
first,
|
|
809
|
-
null,
|
|
810
|
-
needsId ? { id: o.getNextChildId(), ...second } : second
|
|
811
|
-
);
|
|
812
|
-
return [node.read.bind(node), node.write.bind(node)];
|
|
813
|
-
}
|
|
814
|
-
function createMemo(compute2, value, options) {
|
|
815
|
-
let node = new Computation(
|
|
816
|
-
value,
|
|
817
|
-
compute2,
|
|
818
|
-
options
|
|
819
|
-
);
|
|
820
|
-
let resolvedValue;
|
|
821
|
-
return () => {
|
|
822
|
-
var _a, _b;
|
|
823
|
-
if (node) {
|
|
824
|
-
if (node.a === STATE_DISPOSED) {
|
|
825
|
-
node = void 0;
|
|
826
|
-
return resolvedValue;
|
|
827
|
-
}
|
|
828
|
-
resolvedValue = node.wait();
|
|
829
|
-
if (!((_a = node.c) == null ? void 0 : _a.length) && ((_b = node.m) == null ? void 0 : _b.o) !== node) {
|
|
830
|
-
node.dispose();
|
|
831
|
-
node = void 0;
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
return resolvedValue;
|
|
835
|
-
};
|
|
836
|
-
}
|
|
837
|
-
function createAsync(compute2, value, options) {
|
|
838
|
-
let refreshing = false;
|
|
839
|
-
const node = new EagerComputation(
|
|
840
|
-
value,
|
|
841
|
-
(p) => {
|
|
842
|
-
const source = compute2(p, refreshing);
|
|
843
|
-
refreshing = false;
|
|
844
|
-
const isPromise = source instanceof Promise;
|
|
845
|
-
const iterator = source[Symbol.asyncIterator];
|
|
846
|
-
if (!isPromise && !iterator) {
|
|
847
|
-
return source;
|
|
848
|
-
}
|
|
849
|
-
let abort = false;
|
|
850
|
-
onCleanup(() => abort = true);
|
|
851
|
-
if (isPromise) {
|
|
852
|
-
source.then(
|
|
853
|
-
(value3) => {
|
|
854
|
-
if (abort)
|
|
855
|
-
return;
|
|
856
|
-
node.write(value3, 0, true);
|
|
857
|
-
},
|
|
858
|
-
(error) => {
|
|
859
|
-
if (abort)
|
|
860
|
-
return;
|
|
861
|
-
node.L(error);
|
|
862
|
-
}
|
|
863
|
-
);
|
|
864
|
-
} else {
|
|
865
|
-
(async () => {
|
|
866
|
-
try {
|
|
867
|
-
for await (let value3 of source) {
|
|
868
|
-
if (abort)
|
|
869
|
-
return;
|
|
870
|
-
node.write(value3, 0, true);
|
|
871
|
-
}
|
|
872
|
-
} catch (error) {
|
|
873
|
-
if (abort)
|
|
874
|
-
return;
|
|
875
|
-
node.write(error, ERROR_BIT);
|
|
876
|
-
}
|
|
877
|
-
})();
|
|
878
|
-
}
|
|
879
|
-
throw new NotReadyError();
|
|
880
|
-
},
|
|
881
|
-
options
|
|
882
|
-
);
|
|
883
|
-
const read = node.wait.bind(node);
|
|
884
|
-
read.refresh = () => {
|
|
885
|
-
node.a = STATE_DIRTY;
|
|
886
|
-
refreshing = true;
|
|
887
|
-
node.x();
|
|
888
|
-
};
|
|
889
|
-
return read;
|
|
890
|
-
}
|
|
891
|
-
function createEffect(compute2, effect, value, options) {
|
|
892
|
-
void new Effect(
|
|
893
|
-
value,
|
|
894
|
-
compute2,
|
|
895
|
-
effect.effect ? effect.effect : effect,
|
|
896
|
-
effect.error,
|
|
897
|
-
options
|
|
898
|
-
);
|
|
899
|
-
}
|
|
900
|
-
function createRenderEffect(compute2, effect, value, options) {
|
|
901
|
-
void new Effect(value, compute2, effect, void 0, {
|
|
902
|
-
render: true,
|
|
903
|
-
...options
|
|
904
|
-
});
|
|
905
|
-
}
|
|
906
|
-
function createRoot(init, options) {
|
|
907
|
-
const owner = new Owner(options == null ? void 0 : options.id);
|
|
908
|
-
return compute(owner, !init.length ? init : () => init(() => owner.dispose()), null);
|
|
909
|
-
}
|
|
910
|
-
function runWithOwner(owner, run) {
|
|
911
|
-
return compute(owner, run, null);
|
|
912
|
-
}
|
|
913
|
-
function resolve(fn) {
|
|
914
|
-
return new Promise((res, rej) => {
|
|
915
|
-
createRoot((dispose) => {
|
|
916
|
-
new EagerComputation(void 0, () => {
|
|
917
|
-
try {
|
|
918
|
-
res(fn());
|
|
919
|
-
} catch (err) {
|
|
920
|
-
if (err instanceof NotReadyError)
|
|
921
|
-
throw err;
|
|
922
|
-
rej(err);
|
|
923
|
-
}
|
|
924
|
-
dispose();
|
|
925
|
-
});
|
|
926
|
-
});
|
|
927
|
-
});
|
|
928
|
-
}
|
|
929
|
-
function tryCatch(fn) {
|
|
930
|
-
try {
|
|
931
|
-
const v = fn();
|
|
932
|
-
if (v instanceof Promise) {
|
|
933
|
-
return v.then(
|
|
934
|
-
(v2) => [void 0, v2],
|
|
935
|
-
(e) => {
|
|
936
|
-
if (e instanceof NotReadyError)
|
|
937
|
-
throw e;
|
|
938
|
-
return [e];
|
|
939
|
-
}
|
|
940
|
-
);
|
|
941
|
-
}
|
|
942
|
-
return [void 0, v];
|
|
943
|
-
} catch (e) {
|
|
944
|
-
if (e instanceof NotReadyError)
|
|
945
|
-
throw e;
|
|
946
|
-
return [e];
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
function transition(fn) {
|
|
950
|
-
}
|
|
951
|
-
function createOptimistic(initial, compute2, options) {
|
|
952
|
-
return [];
|
|
953
|
-
}
|
|
954
|
-
|
|
955
1023
|
// src/store/projection.ts
|
|
956
1024
|
function createProjection(fn, initialValue = {}) {
|
|
957
1025
|
let wrappedStore;
|
|
@@ -1589,199 +1657,407 @@ function omit(props, ...keys) {
|
|
|
1589
1657
|
return result;
|
|
1590
1658
|
}
|
|
1591
1659
|
|
|
1660
|
+
// src/signals.ts
|
|
1661
|
+
function createSignal(first, second, third) {
|
|
1662
|
+
if (typeof first === "function") {
|
|
1663
|
+
const memo = createMemo((p) => {
|
|
1664
|
+
const node2 = new Computation(
|
|
1665
|
+
first(p ? untrack(p[0]) : second),
|
|
1666
|
+
null,
|
|
1667
|
+
third
|
|
1668
|
+
);
|
|
1669
|
+
return [node2.read.bind(node2), node2.write.bind(node2)];
|
|
1670
|
+
});
|
|
1671
|
+
return [() => memo()[0](), (value) => memo()[1](value)];
|
|
1672
|
+
}
|
|
1673
|
+
const o = getOwner();
|
|
1674
|
+
const needsId = (o == null ? void 0 : o.id) != null;
|
|
1675
|
+
const node = new Computation(
|
|
1676
|
+
first,
|
|
1677
|
+
null,
|
|
1678
|
+
needsId ? { id: o.getNextChildId(), ...second } : second
|
|
1679
|
+
);
|
|
1680
|
+
return [node.read.bind(node), node.write.bind(node)];
|
|
1681
|
+
}
|
|
1682
|
+
function createMemo(compute2, value, options) {
|
|
1683
|
+
let node = new Computation(
|
|
1684
|
+
value,
|
|
1685
|
+
compute2,
|
|
1686
|
+
options
|
|
1687
|
+
);
|
|
1688
|
+
let resolvedValue;
|
|
1689
|
+
return () => {
|
|
1690
|
+
var _a, _b;
|
|
1691
|
+
if (node) {
|
|
1692
|
+
if (node.b === STATE_DISPOSED) {
|
|
1693
|
+
node = void 0;
|
|
1694
|
+
return resolvedValue;
|
|
1695
|
+
}
|
|
1696
|
+
resolvedValue = node.wait();
|
|
1697
|
+
if (!((_a = node.a) == null ? void 0 : _a.length) && ((_b = node.r) == null ? void 0 : _b.p) !== node) {
|
|
1698
|
+
node.dispose();
|
|
1699
|
+
node = void 0;
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
return resolvedValue;
|
|
1703
|
+
};
|
|
1704
|
+
}
|
|
1705
|
+
function createAsync(compute2, value, options) {
|
|
1706
|
+
let refreshing = false;
|
|
1707
|
+
const node = new EagerComputation(
|
|
1708
|
+
value,
|
|
1709
|
+
(p) => {
|
|
1710
|
+
const source = compute2(p, refreshing);
|
|
1711
|
+
refreshing = false;
|
|
1712
|
+
const isPromise = source instanceof Promise;
|
|
1713
|
+
const iterator = source[Symbol.asyncIterator];
|
|
1714
|
+
if (!isPromise && !iterator) {
|
|
1715
|
+
return source;
|
|
1716
|
+
}
|
|
1717
|
+
let abort = false;
|
|
1718
|
+
onCleanup(() => abort = true);
|
|
1719
|
+
const transition2 = ActiveTransition;
|
|
1720
|
+
if (isPromise) {
|
|
1721
|
+
source.then(
|
|
1722
|
+
(value3) => {
|
|
1723
|
+
if (abort)
|
|
1724
|
+
return;
|
|
1725
|
+
if (transition2)
|
|
1726
|
+
return transition2.runTransition(() => node.write(value3, 0, true), true);
|
|
1727
|
+
node.write(value3, 0, true);
|
|
1728
|
+
},
|
|
1729
|
+
(error) => {
|
|
1730
|
+
if (abort)
|
|
1731
|
+
return;
|
|
1732
|
+
if (transition2)
|
|
1733
|
+
return transition2.runTransition(() => node.P(error), true);
|
|
1734
|
+
node.P(error);
|
|
1735
|
+
}
|
|
1736
|
+
);
|
|
1737
|
+
} else {
|
|
1738
|
+
(async () => {
|
|
1739
|
+
try {
|
|
1740
|
+
for await (let value3 of source) {
|
|
1741
|
+
if (abort)
|
|
1742
|
+
return;
|
|
1743
|
+
node.write(value3, 0, true);
|
|
1744
|
+
}
|
|
1745
|
+
} catch (error) {
|
|
1746
|
+
if (abort)
|
|
1747
|
+
return;
|
|
1748
|
+
node.write(error, ERROR_BIT);
|
|
1749
|
+
}
|
|
1750
|
+
})();
|
|
1751
|
+
}
|
|
1752
|
+
throw new NotReadyError();
|
|
1753
|
+
},
|
|
1754
|
+
options
|
|
1755
|
+
);
|
|
1756
|
+
const read = node.wait.bind(node);
|
|
1757
|
+
read.refresh = () => {
|
|
1758
|
+
node.b = STATE_DIRTY;
|
|
1759
|
+
refreshing = true;
|
|
1760
|
+
node.D();
|
|
1761
|
+
};
|
|
1762
|
+
return read;
|
|
1763
|
+
}
|
|
1764
|
+
function createEffect(compute2, effect, value, options) {
|
|
1765
|
+
void new Effect(
|
|
1766
|
+
value,
|
|
1767
|
+
compute2,
|
|
1768
|
+
effect.effect ? effect.effect : effect,
|
|
1769
|
+
effect.error,
|
|
1770
|
+
options
|
|
1771
|
+
);
|
|
1772
|
+
}
|
|
1773
|
+
function createRenderEffect(compute2, effect, value, options) {
|
|
1774
|
+
void new Effect(value, compute2, effect, void 0, {
|
|
1775
|
+
render: true,
|
|
1776
|
+
...options
|
|
1777
|
+
});
|
|
1778
|
+
}
|
|
1779
|
+
function createRoot(init, options) {
|
|
1780
|
+
const owner = new Owner(options == null ? void 0 : options.id);
|
|
1781
|
+
return compute(owner, !init.length ? init : () => init(() => owner.dispose()), null);
|
|
1782
|
+
}
|
|
1783
|
+
function runWithOwner(owner, run) {
|
|
1784
|
+
return compute(owner, run, null);
|
|
1785
|
+
}
|
|
1786
|
+
function resolve(fn) {
|
|
1787
|
+
return new Promise((res, rej) => {
|
|
1788
|
+
createRoot((dispose) => {
|
|
1789
|
+
new EagerComputation(void 0, () => {
|
|
1790
|
+
try {
|
|
1791
|
+
res(fn());
|
|
1792
|
+
} catch (err) {
|
|
1793
|
+
if (err instanceof NotReadyError)
|
|
1794
|
+
throw err;
|
|
1795
|
+
rej(err);
|
|
1796
|
+
}
|
|
1797
|
+
dispose();
|
|
1798
|
+
});
|
|
1799
|
+
});
|
|
1800
|
+
});
|
|
1801
|
+
}
|
|
1802
|
+
function tryCatch(fn) {
|
|
1803
|
+
try {
|
|
1804
|
+
const v = fn();
|
|
1805
|
+
if (v instanceof Promise) {
|
|
1806
|
+
return v.then(
|
|
1807
|
+
(v2) => [void 0, v2],
|
|
1808
|
+
(e) => {
|
|
1809
|
+
if (e instanceof NotReadyError)
|
|
1810
|
+
throw e;
|
|
1811
|
+
return [e];
|
|
1812
|
+
}
|
|
1813
|
+
);
|
|
1814
|
+
}
|
|
1815
|
+
return [void 0, v];
|
|
1816
|
+
} catch (e) {
|
|
1817
|
+
if (e instanceof NotReadyError)
|
|
1818
|
+
throw e;
|
|
1819
|
+
return [e];
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
function createOptimistic(initial, compute2, key) {
|
|
1823
|
+
if (!compute2) {
|
|
1824
|
+
let write2 = function(v) {
|
|
1825
|
+
if (!ActiveTransition)
|
|
1826
|
+
throw new Error("createOptimistic can only be updated inside a transition");
|
|
1827
|
+
ActiveTransition.addOptimistic(reset2);
|
|
1828
|
+
queueMicrotask(() => node.write(v));
|
|
1829
|
+
};
|
|
1830
|
+
var write = write2;
|
|
1831
|
+
const node = new Computation(initial, null);
|
|
1832
|
+
const reset2 = () => node.write(initial);
|
|
1833
|
+
return [node.read.bind(node), write2];
|
|
1834
|
+
}
|
|
1835
|
+
let store, setStore;
|
|
1836
|
+
if (typeof initial === "function") {
|
|
1837
|
+
[store, setStore] = createStore(
|
|
1838
|
+
(s) => {
|
|
1839
|
+
const value = initial();
|
|
1840
|
+
if (!ActiveTransition)
|
|
1841
|
+
s.value = value;
|
|
1842
|
+
},
|
|
1843
|
+
{ value: void 0 }
|
|
1844
|
+
);
|
|
1845
|
+
} else
|
|
1846
|
+
[store, setStore] = createStore({ value: initial });
|
|
1847
|
+
const reset = () => setStore(
|
|
1848
|
+
(s) => reconcile(
|
|
1849
|
+
typeof initial === "function" ? initial() : initial,
|
|
1850
|
+
key
|
|
1851
|
+
)(s.value)
|
|
1852
|
+
);
|
|
1853
|
+
let lastChange = void 0;
|
|
1854
|
+
function write(v) {
|
|
1855
|
+
if (!ActiveTransition)
|
|
1856
|
+
throw new Error("createOptimistic can only be updated inside a transition");
|
|
1857
|
+
ActiveTransition.addOptimistic(reset);
|
|
1858
|
+
queueMicrotask(
|
|
1859
|
+
() => setStore((s) => {
|
|
1860
|
+
lastChange = typeof v === "function" ? v(lastChange) : v;
|
|
1861
|
+
compute2(s.value, lastChange);
|
|
1862
|
+
})
|
|
1863
|
+
);
|
|
1864
|
+
}
|
|
1865
|
+
return [() => store.value, write];
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1592
1868
|
// src/map.ts
|
|
1593
1869
|
function mapArray(list, map, options) {
|
|
1594
1870
|
const keyFn = typeof (options == null ? void 0 : options.keyed) === "function" ? options.keyed : void 0;
|
|
1595
1871
|
return updateKeyedMap.bind({
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1872
|
+
Q: new Owner(),
|
|
1873
|
+
l: 0,
|
|
1874
|
+
ga: list,
|
|
1875
|
+
B: [],
|
|
1876
|
+
K: map,
|
|
1601
1877
|
e: [],
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1878
|
+
c: [],
|
|
1879
|
+
L: keyFn,
|
|
1880
|
+
m: keyFn || (options == null ? void 0 : options.keyed) === false ? [] : void 0,
|
|
1881
|
+
n: map.length > 1 ? [] : void 0,
|
|
1882
|
+
R: options == null ? void 0 : options.fallback
|
|
1607
1883
|
});
|
|
1608
1884
|
}
|
|
1609
1885
|
var pureOptions = { pureWrite: true };
|
|
1610
1886
|
function updateKeyedMap() {
|
|
1611
|
-
const newItems = this
|
|
1887
|
+
const newItems = this.ga() || [], newLen = newItems.length;
|
|
1612
1888
|
newItems[$TRACK];
|
|
1613
|
-
runWithOwner(this.
|
|
1614
|
-
let i, j, mapper = this.
|
|
1615
|
-
this.
|
|
1616
|
-
this.
|
|
1617
|
-
return this.
|
|
1618
|
-
Computation.prototype.read.bind(this.
|
|
1619
|
-
this.
|
|
1889
|
+
runWithOwner(this.Q, () => {
|
|
1890
|
+
let i, j, mapper = this.m ? () => {
|
|
1891
|
+
this.m[j] = new Computation(newItems[j], null, pureOptions);
|
|
1892
|
+
this.n && (this.n[j] = new Computation(j, null, pureOptions));
|
|
1893
|
+
return this.K(
|
|
1894
|
+
Computation.prototype.read.bind(this.m[j]),
|
|
1895
|
+
this.n ? Computation.prototype.read.bind(this.n[j]) : void 0
|
|
1620
1896
|
);
|
|
1621
|
-
} : this.
|
|
1897
|
+
} : this.n ? () => {
|
|
1622
1898
|
const item = newItems[j];
|
|
1623
|
-
this.
|
|
1624
|
-
return this.
|
|
1899
|
+
this.n[j] = new Computation(j, null, pureOptions);
|
|
1900
|
+
return this.K(() => item, Computation.prototype.read.bind(this.n[j]));
|
|
1625
1901
|
} : () => {
|
|
1626
1902
|
const item = newItems[j];
|
|
1627
|
-
return this.
|
|
1903
|
+
return this.K(() => item);
|
|
1628
1904
|
};
|
|
1629
1905
|
if (newLen === 0) {
|
|
1630
|
-
if (this.
|
|
1631
|
-
this.
|
|
1632
|
-
this.
|
|
1633
|
-
this.
|
|
1906
|
+
if (this.l !== 0) {
|
|
1907
|
+
this.Q.dispose(false);
|
|
1908
|
+
this.c = [];
|
|
1909
|
+
this.B = [];
|
|
1634
1910
|
this.e = [];
|
|
1635
|
-
this.
|
|
1636
|
-
this.
|
|
1637
|
-
this.
|
|
1911
|
+
this.l = 0;
|
|
1912
|
+
this.m && (this.m = []);
|
|
1913
|
+
this.n && (this.n = []);
|
|
1638
1914
|
}
|
|
1639
|
-
if (this.
|
|
1915
|
+
if (this.R && !this.e[0]) {
|
|
1640
1916
|
this.e[0] = compute(
|
|
1641
|
-
this.
|
|
1642
|
-
this.
|
|
1917
|
+
this.c[0] = new Owner(),
|
|
1918
|
+
this.R,
|
|
1643
1919
|
null
|
|
1644
1920
|
);
|
|
1645
1921
|
}
|
|
1646
|
-
} else if (this.
|
|
1647
|
-
if (this.
|
|
1648
|
-
this.
|
|
1922
|
+
} else if (this.l === 0) {
|
|
1923
|
+
if (this.c[0])
|
|
1924
|
+
this.c[0].dispose();
|
|
1649
1925
|
this.e = new Array(newLen);
|
|
1650
1926
|
for (j = 0; j < newLen; j++) {
|
|
1651
|
-
this.
|
|
1652
|
-
this.e[j] = compute(this.
|
|
1927
|
+
this.B[j] = newItems[j];
|
|
1928
|
+
this.e[j] = compute(this.c[j] = new Owner(), mapper, null);
|
|
1653
1929
|
}
|
|
1654
|
-
this.
|
|
1930
|
+
this.l = newLen;
|
|
1655
1931
|
} else {
|
|
1656
|
-
let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.
|
|
1657
|
-
for (start = 0, end = Math.min(this.
|
|
1658
|
-
if (this.
|
|
1659
|
-
this.
|
|
1932
|
+
let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.m ? new Array(newLen) : void 0, tempIndexes = this.n ? new Array(newLen) : void 0;
|
|
1933
|
+
for (start = 0, end = Math.min(this.l, newLen); start < end && (this.B[start] === newItems[start] || this.m && compare(this.L, this.B[start], newItems[start])); start++) {
|
|
1934
|
+
if (this.m)
|
|
1935
|
+
this.m[start].write(newItems[start]);
|
|
1660
1936
|
}
|
|
1661
|
-
for (end = this.
|
|
1937
|
+
for (end = this.l - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.B[end] === newItems[newEnd] || this.m && compare(this.L, this.B[end], newItems[newEnd])); end--, newEnd--) {
|
|
1662
1938
|
temp[newEnd] = this.e[end];
|
|
1663
|
-
tempNodes[newEnd] = this.
|
|
1664
|
-
tempRows && (tempRows[newEnd] = this.
|
|
1665
|
-
tempIndexes && (tempIndexes[newEnd] = this.
|
|
1939
|
+
tempNodes[newEnd] = this.c[end];
|
|
1940
|
+
tempRows && (tempRows[newEnd] = this.m[end]);
|
|
1941
|
+
tempIndexes && (tempIndexes[newEnd] = this.n[end]);
|
|
1666
1942
|
}
|
|
1667
1943
|
newIndices = /* @__PURE__ */ new Map();
|
|
1668
1944
|
newIndicesNext = new Array(newEnd + 1);
|
|
1669
1945
|
for (j = newEnd; j >= start; j--) {
|
|
1670
1946
|
item = newItems[j];
|
|
1671
|
-
key = this.
|
|
1947
|
+
key = this.L ? this.L(item) : item;
|
|
1672
1948
|
i = newIndices.get(key);
|
|
1673
1949
|
newIndicesNext[j] = i === void 0 ? -1 : i;
|
|
1674
1950
|
newIndices.set(key, j);
|
|
1675
1951
|
}
|
|
1676
1952
|
for (i = start; i <= end; i++) {
|
|
1677
|
-
item = this.
|
|
1678
|
-
key = this.
|
|
1953
|
+
item = this.B[i];
|
|
1954
|
+
key = this.L ? this.L(item) : item;
|
|
1679
1955
|
j = newIndices.get(key);
|
|
1680
1956
|
if (j !== void 0 && j !== -1) {
|
|
1681
1957
|
temp[j] = this.e[i];
|
|
1682
|
-
tempNodes[j] = this.
|
|
1683
|
-
tempRows && (tempRows[j] = this.
|
|
1684
|
-
tempIndexes && (tempIndexes[j] = this.
|
|
1958
|
+
tempNodes[j] = this.c[i];
|
|
1959
|
+
tempRows && (tempRows[j] = this.m[i]);
|
|
1960
|
+
tempIndexes && (tempIndexes[j] = this.n[i]);
|
|
1685
1961
|
j = newIndicesNext[j];
|
|
1686
1962
|
newIndices.set(key, j);
|
|
1687
1963
|
} else
|
|
1688
|
-
this.
|
|
1964
|
+
this.c[i].dispose();
|
|
1689
1965
|
}
|
|
1690
1966
|
for (j = start; j < newLen; j++) {
|
|
1691
1967
|
if (j in temp) {
|
|
1692
1968
|
this.e[j] = temp[j];
|
|
1693
|
-
this.
|
|
1969
|
+
this.c[j] = tempNodes[j];
|
|
1694
1970
|
if (tempRows) {
|
|
1695
|
-
this.
|
|
1696
|
-
this.
|
|
1971
|
+
this.m[j] = tempRows[j];
|
|
1972
|
+
this.m[j].write(newItems[j]);
|
|
1697
1973
|
}
|
|
1698
1974
|
if (tempIndexes) {
|
|
1699
|
-
this.
|
|
1700
|
-
this.
|
|
1975
|
+
this.n[j] = tempIndexes[j];
|
|
1976
|
+
this.n[j].write(j);
|
|
1701
1977
|
}
|
|
1702
1978
|
} else {
|
|
1703
|
-
this.e[j] = compute(this.
|
|
1979
|
+
this.e[j] = compute(this.c[j] = new Owner(), mapper, null);
|
|
1704
1980
|
}
|
|
1705
1981
|
}
|
|
1706
|
-
this.e = this.e.slice(0, this.
|
|
1707
|
-
this.
|
|
1982
|
+
this.e = this.e.slice(0, this.l = newLen);
|
|
1983
|
+
this.B = newItems.slice(0);
|
|
1708
1984
|
}
|
|
1709
1985
|
});
|
|
1710
1986
|
return this.e;
|
|
1711
1987
|
}
|
|
1712
1988
|
function repeat(count, map, options) {
|
|
1713
1989
|
return updateRepeat.bind({
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1990
|
+
Q: new Owner(),
|
|
1991
|
+
l: 0,
|
|
1992
|
+
w: 0,
|
|
1993
|
+
ha: count,
|
|
1994
|
+
K: map,
|
|
1995
|
+
c: [],
|
|
1720
1996
|
e: [],
|
|
1721
|
-
|
|
1722
|
-
|
|
1997
|
+
ia: options == null ? void 0 : options.from,
|
|
1998
|
+
R: options == null ? void 0 : options.fallback
|
|
1723
1999
|
});
|
|
1724
2000
|
}
|
|
1725
2001
|
function updateRepeat() {
|
|
1726
2002
|
var _a;
|
|
1727
|
-
const newLen = this.
|
|
1728
|
-
const from = ((_a = this.
|
|
1729
|
-
runWithOwner(this.
|
|
2003
|
+
const newLen = this.ha();
|
|
2004
|
+
const from = ((_a = this.ia) == null ? void 0 : _a.call(this)) || 0;
|
|
2005
|
+
runWithOwner(this.Q, () => {
|
|
1730
2006
|
if (newLen === 0) {
|
|
1731
|
-
if (this.
|
|
1732
|
-
this.
|
|
1733
|
-
this.
|
|
2007
|
+
if (this.l !== 0) {
|
|
2008
|
+
this.Q.dispose(false);
|
|
2009
|
+
this.c = [];
|
|
1734
2010
|
this.e = [];
|
|
1735
|
-
this.
|
|
2011
|
+
this.l = 0;
|
|
1736
2012
|
}
|
|
1737
|
-
if (this.
|
|
2013
|
+
if (this.R && !this.e[0]) {
|
|
1738
2014
|
this.e[0] = compute(
|
|
1739
|
-
this.
|
|
1740
|
-
this.
|
|
2015
|
+
this.c[0] = new Owner(),
|
|
2016
|
+
this.R,
|
|
1741
2017
|
null
|
|
1742
2018
|
);
|
|
1743
2019
|
}
|
|
1744
2020
|
return;
|
|
1745
2021
|
}
|
|
1746
2022
|
const to = from + newLen;
|
|
1747
|
-
const prevTo = this.
|
|
1748
|
-
if (this.
|
|
1749
|
-
this.
|
|
2023
|
+
const prevTo = this.w + this.l;
|
|
2024
|
+
if (this.l === 0 && this.c[0])
|
|
2025
|
+
this.c[0].dispose();
|
|
1750
2026
|
for (let i = to; i < prevTo; i++)
|
|
1751
|
-
this.
|
|
1752
|
-
if (this.
|
|
1753
|
-
let i = this.
|
|
1754
|
-
while (i < from && i < this.
|
|
1755
|
-
this.
|
|
1756
|
-
this.
|
|
1757
|
-
this.e.splice(0, from - this.
|
|
1758
|
-
} else if (this.
|
|
1759
|
-
let i = prevTo - this.
|
|
1760
|
-
let difference = this.
|
|
1761
|
-
this.
|
|
2027
|
+
this.c[i - this.w].dispose();
|
|
2028
|
+
if (this.w < from) {
|
|
2029
|
+
let i = this.w;
|
|
2030
|
+
while (i < from && i < this.l)
|
|
2031
|
+
this.c[i++].dispose();
|
|
2032
|
+
this.c.splice(0, from - this.w);
|
|
2033
|
+
this.e.splice(0, from - this.w);
|
|
2034
|
+
} else if (this.w > from) {
|
|
2035
|
+
let i = prevTo - this.w - 1;
|
|
2036
|
+
let difference = this.w - from;
|
|
2037
|
+
this.c.length = this.e.length = newLen;
|
|
1762
2038
|
while (i >= difference) {
|
|
1763
|
-
this.
|
|
2039
|
+
this.c[i] = this.c[i - difference];
|
|
1764
2040
|
this.e[i] = this.e[i - difference];
|
|
1765
2041
|
i--;
|
|
1766
2042
|
}
|
|
1767
2043
|
for (let i2 = 0; i2 < difference; i2++) {
|
|
1768
2044
|
this.e[i2] = compute(
|
|
1769
|
-
this.
|
|
1770
|
-
() => this.
|
|
2045
|
+
this.c[i2] = new Owner(),
|
|
2046
|
+
() => this.K(i2 + from),
|
|
1771
2047
|
null
|
|
1772
2048
|
);
|
|
1773
2049
|
}
|
|
1774
2050
|
}
|
|
1775
2051
|
for (let i = prevTo; i < to; i++) {
|
|
1776
2052
|
this.e[i - from] = compute(
|
|
1777
|
-
this.
|
|
1778
|
-
() => this.
|
|
2053
|
+
this.c[i - from] = new Owner(),
|
|
2054
|
+
() => this.K(i),
|
|
1779
2055
|
null
|
|
1780
2056
|
);
|
|
1781
2057
|
}
|
|
1782
2058
|
this.e = this.e.slice(0, newLen);
|
|
1783
|
-
this.
|
|
1784
|
-
this.
|
|
2059
|
+
this.w = from;
|
|
2060
|
+
this.l = newLen;
|
|
1785
2061
|
});
|
|
1786
2062
|
return this.e;
|
|
1787
2063
|
}
|
|
@@ -1791,24 +2067,24 @@ function compare(key, a, b) {
|
|
|
1791
2067
|
|
|
1792
2068
|
// src/boundaries.ts
|
|
1793
2069
|
var BoundaryComputation = class extends EagerComputation {
|
|
1794
|
-
|
|
2070
|
+
S;
|
|
1795
2071
|
constructor(compute2, propagationMask) {
|
|
1796
2072
|
super(void 0, compute2, { defer: true });
|
|
1797
|
-
this.
|
|
2073
|
+
this.S = propagationMask;
|
|
1798
2074
|
}
|
|
1799
2075
|
write(value, flags) {
|
|
1800
|
-
super.write(value, flags & ~this.
|
|
1801
|
-
if (this.
|
|
2076
|
+
super.write(value, flags & ~this.S);
|
|
2077
|
+
if (this.S & LOADING_BIT && !(this.f & UNINITIALIZED_BIT)) {
|
|
1802
2078
|
flags &= ~LOADING_BIT;
|
|
1803
2079
|
}
|
|
1804
|
-
this.
|
|
2080
|
+
this.i.notify(this, this.S, flags);
|
|
1805
2081
|
return this.g;
|
|
1806
2082
|
}
|
|
1807
2083
|
};
|
|
1808
2084
|
function createBoundChildren(owner, fn, queue, mask) {
|
|
1809
|
-
const parentQueue = owner.
|
|
1810
|
-
parentQueue.addChild(owner.
|
|
1811
|
-
onCleanup(() => parentQueue.removeChild(owner.
|
|
2085
|
+
const parentQueue = owner.i;
|
|
2086
|
+
parentQueue.addChild(owner.i = queue);
|
|
2087
|
+
onCleanup(() => parentQueue.removeChild(owner.i));
|
|
1812
2088
|
return compute(
|
|
1813
2089
|
owner,
|
|
1814
2090
|
() => {
|
|
@@ -1819,32 +2095,32 @@ function createBoundChildren(owner, fn, queue, mask) {
|
|
|
1819
2095
|
);
|
|
1820
2096
|
}
|
|
1821
2097
|
var ConditionalQueue = class extends Queue {
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
2098
|
+
s;
|
|
2099
|
+
Y = /* @__PURE__ */ new Set();
|
|
2100
|
+
t = /* @__PURE__ */ new Set();
|
|
1825
2101
|
constructor(disabled) {
|
|
1826
2102
|
super();
|
|
1827
|
-
this.
|
|
2103
|
+
this.s = disabled;
|
|
1828
2104
|
}
|
|
1829
2105
|
run(type) {
|
|
1830
|
-
if (!type || this.
|
|
2106
|
+
if (!type || this.s.read())
|
|
1831
2107
|
return;
|
|
1832
2108
|
return super.run(type);
|
|
1833
2109
|
}
|
|
1834
2110
|
notify(node, type, flags) {
|
|
1835
|
-
if (this.
|
|
2111
|
+
if (this.s.read()) {
|
|
1836
2112
|
if (type & LOADING_BIT) {
|
|
1837
2113
|
if (flags & LOADING_BIT) {
|
|
1838
|
-
this.
|
|
2114
|
+
this.t.add(node);
|
|
1839
2115
|
type &= ~LOADING_BIT;
|
|
1840
|
-
} else if (this.
|
|
2116
|
+
} else if (this.t.delete(node))
|
|
1841
2117
|
type &= ~LOADING_BIT;
|
|
1842
2118
|
}
|
|
1843
2119
|
if (type & ERROR_BIT) {
|
|
1844
2120
|
if (flags & ERROR_BIT) {
|
|
1845
|
-
this.
|
|
2121
|
+
this.Y.add(node);
|
|
1846
2122
|
type &= ~ERROR_BIT;
|
|
1847
|
-
} else if (this.
|
|
2123
|
+
} else if (this.Y.delete(node))
|
|
1848
2124
|
type &= ~ERROR_BIT;
|
|
1849
2125
|
}
|
|
1850
2126
|
}
|
|
@@ -1852,31 +2128,31 @@ var ConditionalQueue = class extends Queue {
|
|
|
1852
2128
|
}
|
|
1853
2129
|
};
|
|
1854
2130
|
var CollectionQueue = class extends Queue {
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
2131
|
+
Z;
|
|
2132
|
+
c = /* @__PURE__ */ new Set();
|
|
2133
|
+
s = new Computation(false, null, { pureWrite: true });
|
|
1858
2134
|
constructor(type) {
|
|
1859
2135
|
super();
|
|
1860
|
-
this.
|
|
2136
|
+
this.Z = type;
|
|
1861
2137
|
}
|
|
1862
2138
|
run(type) {
|
|
1863
|
-
if (!type || this.
|
|
2139
|
+
if (!type || this.s.read())
|
|
1864
2140
|
return;
|
|
1865
2141
|
return super.run(type);
|
|
1866
2142
|
}
|
|
1867
2143
|
notify(node, type, flags) {
|
|
1868
|
-
if (!(type & this.
|
|
2144
|
+
if (!(type & this.Z))
|
|
1869
2145
|
return super.notify(node, type, flags);
|
|
1870
|
-
if (flags & this.
|
|
1871
|
-
this.
|
|
1872
|
-
if (this.
|
|
1873
|
-
this.
|
|
2146
|
+
if (flags & this.Z) {
|
|
2147
|
+
this.c.add(node);
|
|
2148
|
+
if (this.c.size === 1)
|
|
2149
|
+
this.s.write(true);
|
|
1874
2150
|
} else {
|
|
1875
|
-
this.
|
|
1876
|
-
if (this.
|
|
1877
|
-
this.
|
|
2151
|
+
this.c.delete(node);
|
|
2152
|
+
if (this.c.size === 0)
|
|
2153
|
+
this.s.write(false);
|
|
1878
2154
|
}
|
|
1879
|
-
type &= ~this.
|
|
2155
|
+
type &= ~this.Z;
|
|
1880
2156
|
return type ? super.notify(node, type, flags) : true;
|
|
1881
2157
|
}
|
|
1882
2158
|
};
|
|
@@ -1887,25 +2163,25 @@ function createBoundary(fn, condition) {
|
|
|
1887
2163
|
);
|
|
1888
2164
|
const tree = createBoundChildren(owner, fn, queue, 0);
|
|
1889
2165
|
new EagerComputation(void 0, () => {
|
|
1890
|
-
const disabled = queue.
|
|
1891
|
-
tree.
|
|
2166
|
+
const disabled = queue.s.read();
|
|
2167
|
+
tree.S = disabled ? ERROR_BIT | LOADING_BIT : 0;
|
|
1892
2168
|
if (!disabled) {
|
|
1893
|
-
queue.
|
|
1894
|
-
queue.
|
|
1895
|
-
queue.
|
|
1896
|
-
queue.
|
|
2169
|
+
queue.t.forEach((node) => queue.notify(node, LOADING_BIT, LOADING_BIT));
|
|
2170
|
+
queue.Y.forEach((node) => queue.notify(node, ERROR_BIT, ERROR_BIT));
|
|
2171
|
+
queue.t.clear();
|
|
2172
|
+
queue.Y.clear();
|
|
1897
2173
|
}
|
|
1898
2174
|
});
|
|
1899
|
-
return () => queue.
|
|
2175
|
+
return () => queue.s.read() ? void 0 : tree.read();
|
|
1900
2176
|
}
|
|
1901
2177
|
function createCollectionBoundary(type, fn, fallback) {
|
|
1902
2178
|
const owner = new Owner();
|
|
1903
2179
|
const queue = new CollectionQueue(type);
|
|
1904
2180
|
const tree = createBoundChildren(owner, fn, queue, type);
|
|
1905
2181
|
const decision = new Computation(void 0, () => {
|
|
1906
|
-
if (!queue.
|
|
2182
|
+
if (!queue.s.read()) {
|
|
1907
2183
|
const resolved = tree.read();
|
|
1908
|
-
if (!queue.
|
|
2184
|
+
if (!queue.s.read())
|
|
1909
2185
|
return resolved;
|
|
1910
2186
|
}
|
|
1911
2187
|
return fallback(queue);
|
|
@@ -1919,12 +2195,12 @@ function createErrorBoundary(fn, fallback) {
|
|
|
1919
2195
|
return createCollectionBoundary(
|
|
1920
2196
|
ERROR_BIT,
|
|
1921
2197
|
fn,
|
|
1922
|
-
(queue) => fallback(queue.
|
|
2198
|
+
(queue) => fallback(queue.c.values().next().value.O, () => {
|
|
1923
2199
|
var _a;
|
|
1924
2200
|
incrementClock();
|
|
1925
|
-
for (let node of queue.
|
|
1926
|
-
node.
|
|
1927
|
-
(_a = node.
|
|
2201
|
+
for (let node of queue.c) {
|
|
2202
|
+
node.b = STATE_DIRTY;
|
|
2203
|
+
(_a = node.i) == null ? void 0 : _a.enqueue(node.y, node.A.bind(node));
|
|
1928
2204
|
}
|
|
1929
2205
|
})
|
|
1930
2206
|
);
|