@solidjs/signals 0.0.8 → 0.0.10
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 +224 -175
- package/dist/node.cjs +424 -378
- package/dist/prod.js +422 -375
- package/dist/types/core/constants.d.ts +1 -2
- package/dist/types/core/core.d.ts +8 -11
- package/dist/types/core/effect.d.ts +9 -6
- package/dist/types/core/error.d.ts +2 -1
- package/dist/types/core/flags.d.ts +3 -0
- package/dist/types/core/index.d.ts +2 -2
- package/dist/types/core/owner.d.ts +2 -2
- package/dist/types/core/scheduler.d.ts +3 -2
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/node.cjs
CHANGED
|
@@ -26,13 +26,109 @@ var EffectError = class extends Error {
|
|
|
26
26
|
var STATE_CLEAN = 0;
|
|
27
27
|
var STATE_CHECK = 1;
|
|
28
28
|
var STATE_DIRTY = 2;
|
|
29
|
-
var
|
|
30
|
-
var STATE_DISPOSED = 4;
|
|
29
|
+
var STATE_DISPOSED = 3;
|
|
31
30
|
var EFFECT_PURE = 0;
|
|
32
31
|
var EFFECT_RENDER = 1;
|
|
33
32
|
var EFFECT_USER = 2;
|
|
34
33
|
var SUPPORTS_PROXY = typeof Proxy === "function";
|
|
35
34
|
|
|
35
|
+
// src/core/scheduler.ts
|
|
36
|
+
var clock = 0;
|
|
37
|
+
function getClock() {
|
|
38
|
+
return clock;
|
|
39
|
+
}
|
|
40
|
+
function incrementClock() {
|
|
41
|
+
clock++;
|
|
42
|
+
}
|
|
43
|
+
var scheduled = false;
|
|
44
|
+
function schedule() {
|
|
45
|
+
if (scheduled)
|
|
46
|
+
return;
|
|
47
|
+
scheduled = true;
|
|
48
|
+
if (!globalQueue.H)
|
|
49
|
+
queueMicrotask(flushSync);
|
|
50
|
+
}
|
|
51
|
+
var Queue = class {
|
|
52
|
+
H = false;
|
|
53
|
+
r = [[], [], []];
|
|
54
|
+
D = [];
|
|
55
|
+
enqueue(type, node) {
|
|
56
|
+
this.r[0].push(node);
|
|
57
|
+
if (type)
|
|
58
|
+
this.r[type].push(node);
|
|
59
|
+
schedule();
|
|
60
|
+
}
|
|
61
|
+
run(type) {
|
|
62
|
+
if (this.r[type].length) {
|
|
63
|
+
if (type === EFFECT_PURE) {
|
|
64
|
+
runPureQueue(this.r[type]);
|
|
65
|
+
this.r[type] = [];
|
|
66
|
+
} else {
|
|
67
|
+
const effects = this.r[type];
|
|
68
|
+
this.r[type] = [];
|
|
69
|
+
runEffectQueue(effects);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
let rerun = false;
|
|
73
|
+
for (let i = 0; i < this.D.length; i++) {
|
|
74
|
+
rerun = this.D[i].run(type) || rerun;
|
|
75
|
+
}
|
|
76
|
+
if (type === EFFECT_PURE && this.r[type].length)
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
flush() {
|
|
80
|
+
if (this.H)
|
|
81
|
+
return;
|
|
82
|
+
this.H = true;
|
|
83
|
+
try {
|
|
84
|
+
while (this.run(EFFECT_PURE)) {
|
|
85
|
+
}
|
|
86
|
+
incrementClock();
|
|
87
|
+
scheduled = false;
|
|
88
|
+
this.run(EFFECT_RENDER);
|
|
89
|
+
this.run(EFFECT_USER);
|
|
90
|
+
} finally {
|
|
91
|
+
this.H = false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
addChild(child) {
|
|
95
|
+
this.D.push(child);
|
|
96
|
+
}
|
|
97
|
+
removeChild(child) {
|
|
98
|
+
const index = this.D.indexOf(child);
|
|
99
|
+
if (index >= 0)
|
|
100
|
+
this.D.splice(index, 1);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var globalQueue = new Queue();
|
|
104
|
+
function flushSync() {
|
|
105
|
+
while (scheduled) {
|
|
106
|
+
globalQueue.flush();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function runTop(node) {
|
|
110
|
+
const ancestors = [];
|
|
111
|
+
for (let current = node; current !== null; current = current.s) {
|
|
112
|
+
if (current.a !== STATE_CLEAN) {
|
|
113
|
+
ancestors.push(current);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
117
|
+
if (ancestors[i].a !== STATE_DISPOSED)
|
|
118
|
+
ancestors[i].y();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function runPureQueue(queue) {
|
|
122
|
+
for (let i = 0; i < queue.length; i++) {
|
|
123
|
+
if (queue[i].a !== STATE_CLEAN)
|
|
124
|
+
runTop(queue[i]);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function runEffectQueue(queue) {
|
|
128
|
+
for (let i = 0; i < queue.length; i++)
|
|
129
|
+
queue[i].T();
|
|
130
|
+
}
|
|
131
|
+
|
|
36
132
|
// src/core/utils.ts
|
|
37
133
|
function isUndefined(value) {
|
|
38
134
|
return typeof value === "undefined";
|
|
@@ -107,23 +203,23 @@ var Owner = class {
|
|
|
107
203
|
// We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
|
|
108
204
|
// However, the children are actually added in reverse creation order
|
|
109
205
|
// See comment at the top of the file for an example of the _nextSibling traversal
|
|
110
|
-
r = null;
|
|
111
|
-
n = null;
|
|
112
206
|
s = null;
|
|
207
|
+
n = null;
|
|
208
|
+
t = null;
|
|
113
209
|
a = STATE_CLEAN;
|
|
114
210
|
l = null;
|
|
115
211
|
p = defaultContext;
|
|
116
212
|
m = null;
|
|
117
|
-
|
|
213
|
+
h = globalQueue;
|
|
118
214
|
constructor(signal = false) {
|
|
119
215
|
if (currentOwner && !signal)
|
|
120
216
|
currentOwner.append(this);
|
|
121
217
|
}
|
|
122
218
|
append(child) {
|
|
123
|
-
child.r = this;
|
|
124
219
|
child.s = this;
|
|
220
|
+
child.t = this;
|
|
125
221
|
if (this.n)
|
|
126
|
-
this.n.
|
|
222
|
+
this.n.t = child;
|
|
127
223
|
child.n = this.n;
|
|
128
224
|
this.n = child;
|
|
129
225
|
if (child.p !== this.p) {
|
|
@@ -132,32 +228,32 @@ var Owner = class {
|
|
|
132
228
|
if (this.m) {
|
|
133
229
|
child.m = !child.m ? this.m : [...child.m, ...this.m];
|
|
134
230
|
}
|
|
135
|
-
if (this.
|
|
136
|
-
child.
|
|
231
|
+
if (this.h)
|
|
232
|
+
child.h = this.h;
|
|
137
233
|
}
|
|
138
234
|
dispose(self = true) {
|
|
139
235
|
if (this.a === STATE_DISPOSED)
|
|
140
236
|
return;
|
|
141
|
-
let head = self ? this.
|
|
142
|
-
while (current && current.
|
|
237
|
+
let head = self ? this.t || this.s : this, current = this.n, next = null;
|
|
238
|
+
while (current && current.s === this) {
|
|
143
239
|
current.dispose(true);
|
|
144
|
-
current.
|
|
240
|
+
current.A();
|
|
145
241
|
next = current.n;
|
|
146
242
|
current.n = null;
|
|
147
243
|
current = next;
|
|
148
244
|
}
|
|
149
245
|
if (self)
|
|
150
|
-
this.
|
|
246
|
+
this.A();
|
|
151
247
|
if (current)
|
|
152
|
-
current.
|
|
248
|
+
current.t = !self ? this : this.t;
|
|
153
249
|
if (head)
|
|
154
250
|
head.n = current;
|
|
155
251
|
}
|
|
156
|
-
|
|
157
|
-
if (this.
|
|
158
|
-
this.
|
|
159
|
-
this.r = null;
|
|
252
|
+
A() {
|
|
253
|
+
if (this.t)
|
|
254
|
+
this.t.n = null;
|
|
160
255
|
this.s = null;
|
|
256
|
+
this.t = null;
|
|
161
257
|
this.p = defaultContext;
|
|
162
258
|
this.m = null;
|
|
163
259
|
this.a = STATE_DISPOSED;
|
|
@@ -182,7 +278,7 @@ var Owner = class {
|
|
|
182
278
|
let i = 0, len = this.m.length;
|
|
183
279
|
for (i = 0; i < len; i++) {
|
|
184
280
|
try {
|
|
185
|
-
this.m[i](error);
|
|
281
|
+
this.m[i](error, this);
|
|
186
282
|
break;
|
|
187
283
|
} catch (e) {
|
|
188
284
|
error = e;
|
|
@@ -236,6 +332,8 @@ var ERROR_OFFSET = 0;
|
|
|
236
332
|
var ERROR_BIT = 1 << ERROR_OFFSET;
|
|
237
333
|
var LOADING_OFFSET = 1;
|
|
238
334
|
var LOADING_BIT = 1 << LOADING_OFFSET;
|
|
335
|
+
var UNINITIALIZED_OFFSET = 2;
|
|
336
|
+
var UNINITIALIZED_BIT = 1 << UNINITIALIZED_OFFSET;
|
|
239
337
|
var DEFAULT_FLAGS = ERROR_BIT;
|
|
240
338
|
|
|
241
339
|
// src/core/core.ts
|
|
@@ -244,58 +342,58 @@ var currentMask = DEFAULT_FLAGS;
|
|
|
244
342
|
var newSources = null;
|
|
245
343
|
var newSourcesIndex = 0;
|
|
246
344
|
var newFlags = 0;
|
|
247
|
-
var
|
|
248
|
-
var syncResolve = false;
|
|
345
|
+
var notStale = false;
|
|
249
346
|
var updateCheck = null;
|
|
347
|
+
var staleCheck = null;
|
|
250
348
|
function getObserver() {
|
|
251
349
|
return currentObserver;
|
|
252
350
|
}
|
|
253
|
-
function getClock() {
|
|
254
|
-
return clock;
|
|
255
|
-
}
|
|
256
|
-
function incrementClock() {
|
|
257
|
-
clock++;
|
|
258
|
-
}
|
|
259
351
|
var UNCHANGED = Symbol(0);
|
|
260
352
|
var Computation = class extends Owner {
|
|
353
|
+
f = null;
|
|
261
354
|
d = null;
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
355
|
+
c;
|
|
356
|
+
E;
|
|
357
|
+
u;
|
|
265
358
|
// Used in __DEV__ mode, hopefully removed in production
|
|
266
|
-
|
|
359
|
+
Z;
|
|
267
360
|
// Using false is an optimization as an alternative to _equals: () => false
|
|
268
361
|
// which could enable more efficient DIRTY notification
|
|
269
|
-
|
|
270
|
-
|
|
362
|
+
N = isEqual;
|
|
363
|
+
U;
|
|
271
364
|
/** Whether the computation is an error or has ancestors that are unresolved */
|
|
272
|
-
|
|
365
|
+
b = 0;
|
|
273
366
|
/** Which flags raised by sources are handled, vs. being passed through. */
|
|
274
|
-
|
|
275
|
-
|
|
367
|
+
O = DEFAULT_FLAGS;
|
|
368
|
+
P = null;
|
|
276
369
|
z = -1;
|
|
277
|
-
|
|
370
|
+
I = false;
|
|
278
371
|
constructor(initialValue, compute2, options) {
|
|
279
372
|
super(compute2 === null);
|
|
280
|
-
this.
|
|
281
|
-
this.a = compute2 ?
|
|
282
|
-
this.
|
|
373
|
+
this.u = compute2;
|
|
374
|
+
this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
|
|
375
|
+
this.b = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
|
|
376
|
+
this.c = initialValue;
|
|
283
377
|
if ((options == null ? void 0 : options.equals) !== void 0)
|
|
284
|
-
this.
|
|
378
|
+
this.N = options.equals;
|
|
285
379
|
if (options == null ? void 0 : options.unobserved)
|
|
286
|
-
this.
|
|
380
|
+
this.U = options == null ? void 0 : options.unobserved;
|
|
287
381
|
}
|
|
288
|
-
|
|
382
|
+
V() {
|
|
289
383
|
var _a;
|
|
290
|
-
if (this.
|
|
291
|
-
this.
|
|
292
|
-
|
|
384
|
+
if (this.u) {
|
|
385
|
+
if (this.b & ERROR_BIT && this.z <= getClock())
|
|
386
|
+
update(this);
|
|
387
|
+
else
|
|
388
|
+
this.y();
|
|
389
|
+
}
|
|
390
|
+
if (!this.u || ((_a = this.f) == null ? void 0 : _a.length))
|
|
293
391
|
track(this);
|
|
294
|
-
newFlags |= this.
|
|
295
|
-
if (this.
|
|
296
|
-
throw this.
|
|
392
|
+
newFlags |= this.b & ~currentMask;
|
|
393
|
+
if (this.b & ERROR_BIT) {
|
|
394
|
+
throw this.E;
|
|
297
395
|
} else {
|
|
298
|
-
return this.
|
|
396
|
+
return this.c;
|
|
299
397
|
}
|
|
300
398
|
}
|
|
301
399
|
/**
|
|
@@ -303,7 +401,7 @@ var Computation = class extends Owner {
|
|
|
303
401
|
* Automatically re-executes the surrounding computation when the value changes
|
|
304
402
|
*/
|
|
305
403
|
read() {
|
|
306
|
-
return this.
|
|
404
|
+
return this.V();
|
|
307
405
|
}
|
|
308
406
|
/**
|
|
309
407
|
* Return the current value of this computation
|
|
@@ -313,13 +411,15 @@ var Computation = class extends Owner {
|
|
|
313
411
|
* before continuing
|
|
314
412
|
*/
|
|
315
413
|
wait() {
|
|
316
|
-
if (this.
|
|
414
|
+
if (this.u && this.b & ERROR_BIT && this.z <= getClock()) {
|
|
317
415
|
update(this);
|
|
318
416
|
}
|
|
319
|
-
if (
|
|
417
|
+
if ((notStale || this.b & UNINITIALIZED_BIT) && this.loading()) {
|
|
320
418
|
throw new NotReadyError();
|
|
321
419
|
}
|
|
322
|
-
|
|
420
|
+
if (staleCheck && this.b & LOADING_BIT)
|
|
421
|
+
staleCheck.c = true;
|
|
422
|
+
return this.V();
|
|
323
423
|
}
|
|
324
424
|
/**
|
|
325
425
|
* Return true if the computation is the value is dependent on an unresolved promise
|
|
@@ -329,42 +429,44 @@ var Computation = class extends Owner {
|
|
|
329
429
|
* loading state changes
|
|
330
430
|
*/
|
|
331
431
|
loading() {
|
|
332
|
-
if (this.
|
|
333
|
-
this.
|
|
432
|
+
if (this.P === null) {
|
|
433
|
+
this.P = loadingState(this);
|
|
334
434
|
}
|
|
335
|
-
return this.
|
|
435
|
+
return this.P.read();
|
|
336
436
|
}
|
|
337
437
|
/** Update the computation with a new value. */
|
|
338
438
|
write(value, flags = 0, raw = false) {
|
|
339
|
-
const newValue = !raw && typeof value === "function" ? value(this.
|
|
340
|
-
const valueChanged = newValue !== UNCHANGED && (!!(
|
|
341
|
-
if (valueChanged)
|
|
342
|
-
this.
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
this.
|
|
346
|
-
|
|
347
|
-
|
|
439
|
+
const newValue = !raw && typeof value === "function" ? value(this.c) : value;
|
|
440
|
+
const valueChanged = newValue !== UNCHANGED && (!!(this.b & UNINITIALIZED_BIT) || this.N === false || !this.N(this.c, newValue));
|
|
441
|
+
if (valueChanged) {
|
|
442
|
+
this.c = newValue;
|
|
443
|
+
this.E = void 0;
|
|
444
|
+
}
|
|
445
|
+
const changedFlagsMask = this.b ^ flags, changedFlags = changedFlagsMask & flags;
|
|
446
|
+
this.b = flags;
|
|
447
|
+
this.z = getClock() + 1;
|
|
448
|
+
if (this.d) {
|
|
449
|
+
for (let i = 0; i < this.d.length; i++) {
|
|
348
450
|
if (valueChanged) {
|
|
349
|
-
this.
|
|
451
|
+
this.d[i].q(STATE_DIRTY);
|
|
350
452
|
} else if (changedFlagsMask) {
|
|
351
|
-
this.
|
|
453
|
+
this.d[i].W(changedFlagsMask, changedFlags);
|
|
352
454
|
}
|
|
353
455
|
}
|
|
354
456
|
}
|
|
355
|
-
return this.
|
|
457
|
+
return this.c;
|
|
356
458
|
}
|
|
357
459
|
/**
|
|
358
460
|
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
|
359
461
|
*/
|
|
360
462
|
q(state, skipQueue) {
|
|
361
|
-
if (this.a >= state && !this.
|
|
463
|
+
if (this.a >= state && !this.I)
|
|
362
464
|
return;
|
|
363
|
-
this.
|
|
465
|
+
this.I = !!skipQueue;
|
|
364
466
|
this.a = state;
|
|
365
|
-
if (this.
|
|
366
|
-
for (let i = 0; i < this.
|
|
367
|
-
this.
|
|
467
|
+
if (this.d) {
|
|
468
|
+
for (let i = 0; i < this.d.length; i++) {
|
|
469
|
+
this.d[i].q(STATE_CHECK, skipQueue);
|
|
368
470
|
}
|
|
369
471
|
}
|
|
370
472
|
}
|
|
@@ -374,30 +476,31 @@ var Computation = class extends Owner {
|
|
|
374
476
|
* @param mask A bitmask for which flag(s) were changed.
|
|
375
477
|
* @param newFlags The source's new flags, masked to just the changed ones.
|
|
376
478
|
*/
|
|
377
|
-
|
|
479
|
+
W(mask, newFlags2) {
|
|
378
480
|
if (this.a >= STATE_DIRTY)
|
|
379
481
|
return;
|
|
380
|
-
if (mask & this.
|
|
482
|
+
if (mask & this.O) {
|
|
381
483
|
this.q(STATE_DIRTY);
|
|
382
484
|
return;
|
|
383
485
|
}
|
|
384
486
|
if (this.a >= STATE_CHECK)
|
|
385
487
|
return;
|
|
386
|
-
const prevFlags = this.
|
|
488
|
+
const prevFlags = this.b & mask;
|
|
387
489
|
const deltaFlags = prevFlags ^ newFlags2;
|
|
388
490
|
if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
|
|
389
491
|
this.q(STATE_CHECK);
|
|
390
492
|
} else {
|
|
391
|
-
this.
|
|
392
|
-
if (this.
|
|
393
|
-
for (let i = 0; i < this.
|
|
394
|
-
this.
|
|
493
|
+
this.b ^= deltaFlags;
|
|
494
|
+
if (this.d) {
|
|
495
|
+
for (let i = 0; i < this.d.length; i++) {
|
|
496
|
+
this.d[i].W(mask, newFlags2);
|
|
395
497
|
}
|
|
396
498
|
}
|
|
397
499
|
}
|
|
398
500
|
}
|
|
399
|
-
|
|
400
|
-
this.
|
|
501
|
+
J(error) {
|
|
502
|
+
this.E = error;
|
|
503
|
+
this.write(UNCHANGED, this.b & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
|
|
401
504
|
}
|
|
402
505
|
/**
|
|
403
506
|
* This is the core part of the reactivity system, which makes sure that the values are updated
|
|
@@ -406,7 +509,7 @@ var Computation = class extends Owner {
|
|
|
406
509
|
*
|
|
407
510
|
* This function will ensure that the value and states we read from the computation are up to date
|
|
408
511
|
*/
|
|
409
|
-
|
|
512
|
+
y() {
|
|
410
513
|
if (this.a === STATE_DISPOSED) {
|
|
411
514
|
throw new Error("Tried to read a disposed computation");
|
|
412
515
|
}
|
|
@@ -415,15 +518,15 @@ var Computation = class extends Owner {
|
|
|
415
518
|
}
|
|
416
519
|
let observerFlags = 0;
|
|
417
520
|
if (this.a === STATE_CHECK) {
|
|
418
|
-
for (let i = 0; i < this.
|
|
419
|
-
this.
|
|
420
|
-
observerFlags |= this.
|
|
521
|
+
for (let i = 0; i < this.f.length; i++) {
|
|
522
|
+
this.f[i].y();
|
|
523
|
+
observerFlags |= this.f[i].b;
|
|
421
524
|
if (this.a === STATE_DIRTY) {
|
|
422
525
|
break;
|
|
423
526
|
}
|
|
424
527
|
}
|
|
425
528
|
}
|
|
426
|
-
if (this.a === STATE_DIRTY
|
|
529
|
+
if (this.a === STATE_DIRTY) {
|
|
427
530
|
update(this);
|
|
428
531
|
} else {
|
|
429
532
|
this.write(UNCHANGED, observerFlags);
|
|
@@ -433,33 +536,33 @@ var Computation = class extends Owner {
|
|
|
433
536
|
/**
|
|
434
537
|
* Remove ourselves from the owner graph and the computation graph
|
|
435
538
|
*/
|
|
436
|
-
|
|
539
|
+
A() {
|
|
437
540
|
if (this.a === STATE_DISPOSED)
|
|
438
541
|
return;
|
|
439
|
-
if (this.
|
|
542
|
+
if (this.f)
|
|
440
543
|
removeSourceObservers(this, 0);
|
|
441
|
-
super.
|
|
544
|
+
super.A();
|
|
442
545
|
}
|
|
443
546
|
};
|
|
444
547
|
function loadingState(node) {
|
|
445
|
-
const prevOwner = setOwner(node.
|
|
548
|
+
const prevOwner = setOwner(node.s);
|
|
446
549
|
const options = void 0;
|
|
447
550
|
const computation = new Computation(
|
|
448
551
|
void 0,
|
|
449
552
|
() => {
|
|
450
553
|
track(node);
|
|
451
|
-
node.
|
|
452
|
-
return !!(node.
|
|
554
|
+
node.y();
|
|
555
|
+
return !!(node.b & LOADING_BIT);
|
|
453
556
|
},
|
|
454
557
|
options
|
|
455
558
|
);
|
|
456
|
-
computation.
|
|
559
|
+
computation.O = ERROR_BIT | LOADING_BIT;
|
|
457
560
|
setOwner(prevOwner);
|
|
458
561
|
return computation;
|
|
459
562
|
}
|
|
460
563
|
function track(computation) {
|
|
461
564
|
if (currentObserver) {
|
|
462
|
-
if (!newSources && currentObserver.
|
|
565
|
+
if (!newSources && currentObserver.f && currentObserver.f[newSourcesIndex] === computation) {
|
|
463
566
|
newSourcesIndex++;
|
|
464
567
|
} else if (!newSources)
|
|
465
568
|
newSources = [computation];
|
|
@@ -467,7 +570,7 @@ function track(computation) {
|
|
|
467
570
|
newSources.push(computation);
|
|
468
571
|
}
|
|
469
572
|
if (updateCheck) {
|
|
470
|
-
updateCheck.
|
|
573
|
+
updateCheck.c = computation.z > currentObserver.z;
|
|
471
574
|
}
|
|
472
575
|
}
|
|
473
576
|
}
|
|
@@ -479,42 +582,42 @@ function update(node) {
|
|
|
479
582
|
try {
|
|
480
583
|
node.dispose(false);
|
|
481
584
|
node.emptyDisposal();
|
|
482
|
-
const result = compute(node, node.
|
|
585
|
+
const result = compute(node, node.u, node);
|
|
483
586
|
node.write(result, newFlags, true);
|
|
484
587
|
} catch (error) {
|
|
485
588
|
if (error instanceof NotReadyError) {
|
|
486
|
-
node.write(UNCHANGED, newFlags | LOADING_BIT);
|
|
589
|
+
node.write(UNCHANGED, newFlags | LOADING_BIT | node.b & UNINITIALIZED_BIT);
|
|
487
590
|
} else {
|
|
488
|
-
node.
|
|
591
|
+
node.J(error);
|
|
489
592
|
}
|
|
490
593
|
} finally {
|
|
491
594
|
if (newSources) {
|
|
492
|
-
if (node.
|
|
595
|
+
if (node.f)
|
|
493
596
|
removeSourceObservers(node, newSourcesIndex);
|
|
494
|
-
if (node.
|
|
495
|
-
node.
|
|
597
|
+
if (node.f && newSourcesIndex > 0) {
|
|
598
|
+
node.f.length = newSourcesIndex + newSources.length;
|
|
496
599
|
for (let i = 0; i < newSources.length; i++) {
|
|
497
|
-
node.
|
|
600
|
+
node.f[newSourcesIndex + i] = newSources[i];
|
|
498
601
|
}
|
|
499
602
|
} else {
|
|
500
|
-
node.
|
|
603
|
+
node.f = newSources;
|
|
501
604
|
}
|
|
502
605
|
let source;
|
|
503
|
-
for (let i = newSourcesIndex; i < node.
|
|
504
|
-
source = node.
|
|
505
|
-
if (!source.
|
|
506
|
-
source.
|
|
606
|
+
for (let i = newSourcesIndex; i < node.f.length; i++) {
|
|
607
|
+
source = node.f[i];
|
|
608
|
+
if (!source.d)
|
|
609
|
+
source.d = [node];
|
|
507
610
|
else
|
|
508
|
-
source.
|
|
611
|
+
source.d.push(node);
|
|
509
612
|
}
|
|
510
|
-
} else if (node.
|
|
613
|
+
} else if (node.f && newSourcesIndex < node.f.length) {
|
|
511
614
|
removeSourceObservers(node, newSourcesIndex);
|
|
512
|
-
node.
|
|
615
|
+
node.f.length = newSourcesIndex;
|
|
513
616
|
}
|
|
514
617
|
newSources = prevSources;
|
|
515
618
|
newSourcesIndex = prevSourcesIndex;
|
|
516
619
|
newFlags = prevFlags;
|
|
517
|
-
node.z =
|
|
620
|
+
node.z = getClock() + 1;
|
|
518
621
|
node.a = STATE_CLEAN;
|
|
519
622
|
}
|
|
520
623
|
}
|
|
@@ -522,14 +625,14 @@ function removeSourceObservers(node, index) {
|
|
|
522
625
|
var _a;
|
|
523
626
|
let source;
|
|
524
627
|
let swap;
|
|
525
|
-
for (let i = index; i < node.
|
|
526
|
-
source = node.
|
|
527
|
-
if (source.
|
|
528
|
-
swap = source.
|
|
529
|
-
source.
|
|
530
|
-
source.
|
|
531
|
-
if (!source.
|
|
532
|
-
(_a = source.
|
|
628
|
+
for (let i = index; i < node.f.length; i++) {
|
|
629
|
+
source = node.f[i];
|
|
630
|
+
if (source.d) {
|
|
631
|
+
swap = source.d.indexOf(node);
|
|
632
|
+
source.d[swap] = source.d[source.d.length - 1];
|
|
633
|
+
source.d.pop();
|
|
634
|
+
if (!source.d.length)
|
|
635
|
+
(_a = source.U) == null ? void 0 : _a.call(source);
|
|
533
636
|
}
|
|
534
637
|
}
|
|
535
638
|
}
|
|
@@ -543,31 +646,35 @@ function untrack(fn) {
|
|
|
543
646
|
}
|
|
544
647
|
function hasUpdated(fn) {
|
|
545
648
|
const current = updateCheck;
|
|
546
|
-
updateCheck = {
|
|
649
|
+
updateCheck = { c: false };
|
|
547
650
|
try {
|
|
548
651
|
fn();
|
|
549
|
-
return updateCheck.
|
|
652
|
+
return updateCheck.c;
|
|
550
653
|
} finally {
|
|
551
654
|
updateCheck = current;
|
|
552
655
|
}
|
|
553
656
|
}
|
|
554
|
-
function
|
|
657
|
+
function isStale(fn) {
|
|
658
|
+
const current = staleCheck;
|
|
659
|
+
staleCheck = { c: false };
|
|
555
660
|
try {
|
|
556
|
-
fn
|
|
557
|
-
return
|
|
558
|
-
} catch
|
|
559
|
-
|
|
661
|
+
latest(fn);
|
|
662
|
+
return staleCheck.c;
|
|
663
|
+
} catch {
|
|
664
|
+
} finally {
|
|
665
|
+
staleCheck = current;
|
|
560
666
|
}
|
|
667
|
+
return false;
|
|
561
668
|
}
|
|
562
|
-
function
|
|
669
|
+
function latest(fn) {
|
|
563
670
|
const prevFlags = newFlags;
|
|
564
|
-
|
|
671
|
+
const prevNotStale = notStale;
|
|
672
|
+
notStale = false;
|
|
565
673
|
try {
|
|
566
674
|
return fn();
|
|
567
|
-
} catch {
|
|
568
675
|
} finally {
|
|
569
676
|
newFlags = prevFlags;
|
|
570
|
-
|
|
677
|
+
notStale = prevNotStale;
|
|
571
678
|
}
|
|
572
679
|
}
|
|
573
680
|
function catchError(fn) {
|
|
@@ -579,239 +686,162 @@ function catchError(fn) {
|
|
|
579
686
|
return e;
|
|
580
687
|
}
|
|
581
688
|
}
|
|
582
|
-
function compute(owner,
|
|
583
|
-
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask;
|
|
689
|
+
function compute(owner, fn, observer) {
|
|
690
|
+
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask, prevNotStale = notStale;
|
|
584
691
|
currentObserver = observer;
|
|
585
|
-
currentMask = (observer == null ? void 0 : observer.
|
|
692
|
+
currentMask = (observer == null ? void 0 : observer.O) ?? DEFAULT_FLAGS;
|
|
693
|
+
notStale = true;
|
|
586
694
|
try {
|
|
587
|
-
return
|
|
695
|
+
return fn(observer ? observer.c : void 0);
|
|
588
696
|
} finally {
|
|
589
697
|
setOwner(prevOwner);
|
|
590
698
|
currentObserver = prevObserver;
|
|
591
699
|
currentMask = prevMask;
|
|
592
|
-
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
// src/core/scheduler.ts
|
|
596
|
-
var scheduled = false;
|
|
597
|
-
function schedule() {
|
|
598
|
-
if (scheduled)
|
|
599
|
-
return;
|
|
600
|
-
scheduled = true;
|
|
601
|
-
if (!globalQueue.I)
|
|
602
|
-
queueMicrotask(flushSync);
|
|
603
|
-
}
|
|
604
|
-
var Queue = class {
|
|
605
|
-
I = false;
|
|
606
|
-
t = [[], [], []];
|
|
607
|
-
E = [];
|
|
608
|
-
enqueue(type, node) {
|
|
609
|
-
this.t[0].push(node);
|
|
610
|
-
if (type)
|
|
611
|
-
this.t[type].push(node);
|
|
612
|
-
schedule();
|
|
613
|
-
}
|
|
614
|
-
run(type) {
|
|
615
|
-
if (this.t[type].length) {
|
|
616
|
-
if (type === EFFECT_PURE) {
|
|
617
|
-
runPureQueue(this.t[type]);
|
|
618
|
-
this.t[type] = [];
|
|
619
|
-
} else {
|
|
620
|
-
const effects = this.t[type];
|
|
621
|
-
this.t[type] = [];
|
|
622
|
-
runEffectQueue(effects);
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
let rerun = false;
|
|
626
|
-
for (let i = 0; i < this.E.length; i++) {
|
|
627
|
-
rerun = this.E[i].run(type) || rerun;
|
|
628
|
-
}
|
|
629
|
-
if (type === EFFECT_PURE && this.t[type].length)
|
|
630
|
-
return true;
|
|
631
|
-
}
|
|
632
|
-
flush() {
|
|
633
|
-
if (this.I)
|
|
634
|
-
return;
|
|
635
|
-
this.I = true;
|
|
636
|
-
try {
|
|
637
|
-
while (this.run(EFFECT_PURE)) {
|
|
638
|
-
}
|
|
639
|
-
incrementClock();
|
|
640
|
-
scheduled = false;
|
|
641
|
-
this.run(EFFECT_RENDER);
|
|
642
|
-
this.run(EFFECT_USER);
|
|
643
|
-
} finally {
|
|
644
|
-
this.I = false;
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
addChild(child) {
|
|
648
|
-
this.E.push(child);
|
|
649
|
-
}
|
|
650
|
-
removeChild(child) {
|
|
651
|
-
const index = this.E.indexOf(child);
|
|
652
|
-
if (index >= 0)
|
|
653
|
-
this.E.splice(index, 1);
|
|
654
|
-
}
|
|
655
|
-
};
|
|
656
|
-
var globalQueue = new Queue();
|
|
657
|
-
function flushSync() {
|
|
658
|
-
while (scheduled) {
|
|
659
|
-
globalQueue.flush();
|
|
700
|
+
notStale = prevNotStale;
|
|
660
701
|
}
|
|
661
702
|
}
|
|
662
703
|
function createBoundary(fn, queue) {
|
|
663
704
|
const owner = new Owner();
|
|
664
|
-
const parentQueue = owner.
|
|
665
|
-
parentQueue.addChild(owner.
|
|
666
|
-
onCleanup(() => parentQueue.removeChild(owner.
|
|
705
|
+
const parentQueue = owner.h;
|
|
706
|
+
parentQueue.addChild(owner.h = queue);
|
|
707
|
+
onCleanup(() => parentQueue.removeChild(owner.h));
|
|
667
708
|
return compute(owner, fn, null);
|
|
668
709
|
}
|
|
669
|
-
function runTop(node) {
|
|
670
|
-
const ancestors = [];
|
|
671
|
-
for (let current = node; current !== null; current = current.r) {
|
|
672
|
-
if (current.a !== STATE_CLEAN) {
|
|
673
|
-
ancestors.push(current);
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
677
|
-
if (ancestors[i].a !== STATE_DISPOSED)
|
|
678
|
-
ancestors[i].x();
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
function runPureQueue(queue) {
|
|
682
|
-
for (let i = 0; i < queue.length; i++) {
|
|
683
|
-
if (queue[i].a !== STATE_CLEAN)
|
|
684
|
-
runTop(queue[i]);
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
function runEffectQueue(queue) {
|
|
688
|
-
for (let i = 0; i < queue.length; i++)
|
|
689
|
-
queue[i].V();
|
|
690
|
-
}
|
|
691
710
|
|
|
692
711
|
// src/core/effect.ts
|
|
693
712
|
var Effect = class extends Computation {
|
|
694
|
-
J;
|
|
695
|
-
A;
|
|
696
|
-
B;
|
|
697
|
-
P = false;
|
|
698
713
|
K;
|
|
699
|
-
|
|
700
|
-
|
|
714
|
+
L;
|
|
715
|
+
B;
|
|
716
|
+
Q = false;
|
|
717
|
+
M;
|
|
718
|
+
w;
|
|
701
719
|
constructor(initialValue, compute2, effect, error, options) {
|
|
702
|
-
var _a;
|
|
703
720
|
super(initialValue, compute2, options);
|
|
704
|
-
this.
|
|
705
|
-
this.
|
|
706
|
-
this.
|
|
707
|
-
this.
|
|
708
|
-
this.
|
|
721
|
+
this.K = effect;
|
|
722
|
+
this.L = error;
|
|
723
|
+
this.M = initialValue;
|
|
724
|
+
this.w = (options == null ? void 0 : options.render) ? EFFECT_RENDER : EFFECT_USER;
|
|
725
|
+
if (this.w === EFFECT_RENDER) {
|
|
726
|
+
this.u = (p) => latest(() => compute2(p));
|
|
727
|
+
}
|
|
709
728
|
if (!(options == null ? void 0 : options.defer)) {
|
|
710
|
-
this.
|
|
711
|
-
this.
|
|
729
|
+
this.y();
|
|
730
|
+
this.w === EFFECT_USER ? this.h.enqueue(this.w, this) : this.T();
|
|
712
731
|
}
|
|
713
732
|
}
|
|
714
733
|
write(value, flags = 0) {
|
|
715
734
|
var _a, _b;
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
735
|
+
if (this.a == STATE_DIRTY) {
|
|
736
|
+
const currentFlags = this.b;
|
|
737
|
+
this.b = flags;
|
|
738
|
+
if (this.w === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
739
|
+
(_b = (_a = this.h).R) == null ? void 0 : _b.call(_a, this);
|
|
740
|
+
}
|
|
720
741
|
}
|
|
721
742
|
if (value === UNCHANGED)
|
|
722
|
-
return this.
|
|
723
|
-
this.
|
|
724
|
-
this.
|
|
743
|
+
return this.c;
|
|
744
|
+
this.c = value;
|
|
745
|
+
this.Q = true;
|
|
725
746
|
return value;
|
|
726
747
|
}
|
|
727
748
|
q(state, skipQueue) {
|
|
728
749
|
if (this.a >= state || skipQueue)
|
|
729
750
|
return;
|
|
730
751
|
if (this.a === STATE_CLEAN)
|
|
731
|
-
this.
|
|
752
|
+
this.h.enqueue(this.w, this);
|
|
732
753
|
this.a = state;
|
|
733
754
|
}
|
|
734
|
-
|
|
755
|
+
J(error) {
|
|
735
756
|
var _a, _b, _c;
|
|
736
757
|
(_a = this.B) == null ? void 0 : _a.call(this);
|
|
737
|
-
if (this.
|
|
738
|
-
this.
|
|
739
|
-
(_c = (_b = this.
|
|
758
|
+
if (this.b & LOADING_BIT) {
|
|
759
|
+
this.b = 0;
|
|
760
|
+
(_c = (_b = this.h).R) == null ? void 0 : _c.call(_b, this);
|
|
740
761
|
}
|
|
741
|
-
if (this.
|
|
762
|
+
if (this.w === EFFECT_USER) {
|
|
742
763
|
try {
|
|
743
|
-
return this.
|
|
764
|
+
return this.L ? this.B = this.L(error) : console.error(new EffectError(this.K, error));
|
|
744
765
|
} catch (e) {
|
|
745
766
|
error = e;
|
|
746
767
|
}
|
|
747
768
|
}
|
|
748
769
|
this.handleError(error);
|
|
749
770
|
}
|
|
750
|
-
|
|
771
|
+
A() {
|
|
751
772
|
var _a;
|
|
752
773
|
if (this.a === STATE_DISPOSED)
|
|
753
774
|
return;
|
|
754
|
-
this.J = void 0;
|
|
755
775
|
this.K = void 0;
|
|
756
|
-
this.
|
|
776
|
+
this.M = void 0;
|
|
777
|
+
this.L = void 0;
|
|
757
778
|
(_a = this.B) == null ? void 0 : _a.call(this);
|
|
758
779
|
this.B = void 0;
|
|
759
|
-
super.
|
|
780
|
+
super.A();
|
|
760
781
|
}
|
|
761
|
-
|
|
782
|
+
T() {
|
|
762
783
|
var _a;
|
|
763
|
-
if (this.
|
|
784
|
+
if (this.Q && this.a !== STATE_DISPOSED) {
|
|
764
785
|
(_a = this.B) == null ? void 0 : _a.call(this);
|
|
765
786
|
try {
|
|
766
|
-
this.B = this.
|
|
787
|
+
this.B = this.K(this.c, this.M);
|
|
767
788
|
} catch (e) {
|
|
768
789
|
this.handleError(e);
|
|
769
790
|
} finally {
|
|
770
|
-
this.
|
|
771
|
-
this.
|
|
791
|
+
this.M = this.c;
|
|
792
|
+
this.Q = false;
|
|
772
793
|
}
|
|
773
794
|
}
|
|
774
795
|
}
|
|
775
796
|
};
|
|
776
797
|
var EagerComputation = class extends Computation {
|
|
777
|
-
g;
|
|
778
798
|
constructor(initialValue, compute2, options) {
|
|
779
|
-
var _a;
|
|
780
799
|
super(initialValue, compute2, options);
|
|
781
|
-
|
|
782
|
-
this.x();
|
|
800
|
+
!(options == null ? void 0 : options.defer) && this.y();
|
|
783
801
|
}
|
|
784
802
|
q(state, skipQueue) {
|
|
785
|
-
if (this.a >= state && !this.
|
|
803
|
+
if (this.a >= state && !this.I)
|
|
786
804
|
return;
|
|
787
805
|
if (this.a === STATE_CLEAN && !skipQueue)
|
|
788
|
-
this.
|
|
806
|
+
this.h.enqueue(EFFECT_PURE, this);
|
|
789
807
|
super.q(state, skipQueue);
|
|
790
808
|
}
|
|
791
809
|
};
|
|
810
|
+
var ProjectionComputation = class extends Computation {
|
|
811
|
+
constructor(compute2) {
|
|
812
|
+
super(null, compute2);
|
|
813
|
+
}
|
|
814
|
+
q(state, skipQueue) {
|
|
815
|
+
if (this.a >= state && !this.I)
|
|
816
|
+
return;
|
|
817
|
+
if (this.a === STATE_CLEAN && !skipQueue)
|
|
818
|
+
this.h.enqueue(EFFECT_PURE, this);
|
|
819
|
+
super.q(state, true);
|
|
820
|
+
}
|
|
821
|
+
};
|
|
792
822
|
|
|
793
823
|
// src/core/suspense.ts
|
|
794
824
|
var SuspenseQueue = class extends Queue {
|
|
795
|
-
|
|
825
|
+
e = /* @__PURE__ */ new Set();
|
|
796
826
|
o = false;
|
|
797
|
-
|
|
827
|
+
S = new Computation(false, null);
|
|
798
828
|
run(type) {
|
|
799
829
|
if (type && this.o)
|
|
800
830
|
return;
|
|
801
831
|
return super.run(type);
|
|
802
832
|
}
|
|
803
|
-
|
|
804
|
-
if (node.
|
|
805
|
-
this.
|
|
833
|
+
R(node) {
|
|
834
|
+
if (node.b & LOADING_BIT) {
|
|
835
|
+
this.e.add(node);
|
|
806
836
|
if (!this.o) {
|
|
807
837
|
this.o = true;
|
|
808
|
-
this.
|
|
838
|
+
this.S.write(true);
|
|
809
839
|
}
|
|
810
840
|
} else {
|
|
811
|
-
this.
|
|
812
|
-
if (this.
|
|
841
|
+
this.e.delete(node);
|
|
842
|
+
if (this.e.size === 0) {
|
|
813
843
|
this.o = false;
|
|
814
|
-
this.
|
|
844
|
+
this.S.write(false);
|
|
815
845
|
}
|
|
816
846
|
}
|
|
817
847
|
}
|
|
@@ -819,12 +849,13 @@ var SuspenseQueue = class extends Queue {
|
|
|
819
849
|
var LiveComputation = class extends EagerComputation {
|
|
820
850
|
write(value, flags = 0) {
|
|
821
851
|
var _a, _b;
|
|
822
|
-
const currentFlags = this.
|
|
852
|
+
const currentFlags = this.b;
|
|
853
|
+
const dirty = this.a === STATE_DIRTY;
|
|
823
854
|
super.write(value, flags);
|
|
824
|
-
if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
825
|
-
(_b = (_a = this.
|
|
855
|
+
if (dirty && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
856
|
+
(_b = (_a = this.h).R) == null ? void 0 : _b.call(_a, this);
|
|
826
857
|
}
|
|
827
|
-
return this.
|
|
858
|
+
return this.c;
|
|
828
859
|
}
|
|
829
860
|
};
|
|
830
861
|
function createSuspense(fn, fallback) {
|
|
@@ -833,7 +864,7 @@ function createSuspense(fn, fallback) {
|
|
|
833
864
|
const child = new Computation(null, fn);
|
|
834
865
|
return new LiveComputation(null, () => flatten(child.wait()));
|
|
835
866
|
}, queue);
|
|
836
|
-
const equality = new Computation(null, () => queue.
|
|
867
|
+
const equality = new Computation(null, () => queue.S.read() || queue.o);
|
|
837
868
|
const comp = new Computation(null, () => equality.read() ? fallback() : tree.read());
|
|
838
869
|
return comp.read.bind(comp);
|
|
839
870
|
}
|
|
@@ -865,24 +896,25 @@ function createMemo(compute2, value, options) {
|
|
|
865
896
|
var _a, _b, _c;
|
|
866
897
|
if (node) {
|
|
867
898
|
resolvedValue = node.wait();
|
|
868
|
-
if (!((_a = node.
|
|
899
|
+
if (!((_a = node.f) == null ? void 0 : _a.length) && ((_b = node.n) == null ? void 0 : _b.s) !== node) {
|
|
869
900
|
node.dispose();
|
|
870
901
|
node = void 0;
|
|
871
|
-
} else if (!node.
|
|
902
|
+
} else if (!node.s && !((_c = node.d) == null ? void 0 : _c.length)) {
|
|
872
903
|
node.dispose();
|
|
873
|
-
node.a =
|
|
904
|
+
node.a = STATE_DIRTY;
|
|
874
905
|
}
|
|
875
906
|
}
|
|
876
907
|
return resolvedValue;
|
|
877
908
|
};
|
|
878
909
|
}
|
|
879
910
|
function createAsync(compute2, value, options) {
|
|
911
|
+
let uninitialized = value === void 0;
|
|
880
912
|
const lhs = new EagerComputation(
|
|
881
913
|
{
|
|
882
|
-
|
|
914
|
+
c: value
|
|
883
915
|
},
|
|
884
916
|
(p) => {
|
|
885
|
-
const value2 = p == null ? void 0 : p.
|
|
917
|
+
const value2 = p == null ? void 0 : p.c;
|
|
886
918
|
const source = compute2(value2);
|
|
887
919
|
const isPromise = source instanceof Promise;
|
|
888
920
|
const iterator = source[Symbol.asyncIterator];
|
|
@@ -891,26 +923,28 @@ function createAsync(compute2, value, options) {
|
|
|
891
923
|
wait() {
|
|
892
924
|
return source;
|
|
893
925
|
},
|
|
894
|
-
|
|
926
|
+
c: source
|
|
895
927
|
};
|
|
896
928
|
}
|
|
897
929
|
const signal = new Computation(value2, null, options);
|
|
898
930
|
const w = signal.wait;
|
|
899
931
|
signal.wait = function() {
|
|
900
|
-
if (signal.
|
|
932
|
+
if (signal.b & ERROR_BIT && signal.z <= getClock()) {
|
|
901
933
|
lhs.q(STATE_DIRTY);
|
|
902
934
|
throw new NotReadyError();
|
|
903
935
|
}
|
|
904
936
|
return w.call(this);
|
|
905
937
|
};
|
|
906
|
-
signal.write(UNCHANGED, LOADING_BIT);
|
|
938
|
+
signal.write(UNCHANGED, LOADING_BIT | (uninitialized ? UNINITIALIZED_BIT : 0));
|
|
907
939
|
if (isPromise) {
|
|
908
940
|
source.then(
|
|
909
941
|
(value3) => {
|
|
942
|
+
uninitialized = false;
|
|
910
943
|
signal.write(value3, 0, true);
|
|
911
944
|
},
|
|
912
945
|
(error) => {
|
|
913
|
-
|
|
946
|
+
uninitialized = true;
|
|
947
|
+
signal.J(error);
|
|
914
948
|
}
|
|
915
949
|
);
|
|
916
950
|
} else {
|
|
@@ -962,16 +996,31 @@ function runWithOwner(owner, run) {
|
|
|
962
996
|
}
|
|
963
997
|
function createErrorBoundary(fn, fallback) {
|
|
964
998
|
const owner = new Owner();
|
|
965
|
-
const error = new Computation(
|
|
966
|
-
const
|
|
967
|
-
|
|
999
|
+
const error = new Computation(void 0, null);
|
|
1000
|
+
const nodes = /* @__PURE__ */ new Set();
|
|
1001
|
+
function handler(err, node) {
|
|
1002
|
+
if (nodes.has(node))
|
|
1003
|
+
return;
|
|
1004
|
+
compute(
|
|
1005
|
+
node,
|
|
1006
|
+
() => onCleanup(() => {
|
|
1007
|
+
nodes.delete(node);
|
|
1008
|
+
if (!nodes.size)
|
|
1009
|
+
error.write(void 0);
|
|
1010
|
+
}),
|
|
1011
|
+
null
|
|
1012
|
+
);
|
|
1013
|
+
nodes.add(node);
|
|
1014
|
+
if (nodes.size === 1)
|
|
1015
|
+
error.write({ E: err });
|
|
1016
|
+
}
|
|
968
1017
|
owner.m = owner.m ? [handler, ...owner.m] : [handler];
|
|
969
1018
|
const guarded = compute(
|
|
970
1019
|
owner,
|
|
971
1020
|
() => {
|
|
972
|
-
const c = new Computation(
|
|
973
|
-
const f = new
|
|
974
|
-
f.
|
|
1021
|
+
const c = new Computation(void 0, fn);
|
|
1022
|
+
const f = new EagerComputation(void 0, () => flatten(c.read()), { defer: true });
|
|
1023
|
+
f.J = function(error2) {
|
|
975
1024
|
this.handleError(error2);
|
|
976
1025
|
};
|
|
977
1026
|
return f;
|
|
@@ -984,24 +1033,30 @@ function createErrorBoundary(fn, fallback) {
|
|
|
984
1033
|
if (!error.read())
|
|
985
1034
|
return resolved;
|
|
986
1035
|
}
|
|
987
|
-
return fallback(error.read().
|
|
988
|
-
|
|
989
|
-
|
|
1036
|
+
return fallback(error.read().E, () => {
|
|
1037
|
+
var _a;
|
|
1038
|
+
incrementClock();
|
|
1039
|
+
for (let node of nodes) {
|
|
1040
|
+
node.a = STATE_DIRTY;
|
|
1041
|
+
(_a = node.h) == null ? void 0 : _a.enqueue(node.w, node);
|
|
1042
|
+
}
|
|
990
1043
|
});
|
|
991
1044
|
});
|
|
992
1045
|
return decision.read.bind(decision);
|
|
993
1046
|
}
|
|
994
1047
|
function resolve(fn) {
|
|
995
1048
|
return new Promise((res, rej) => {
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1049
|
+
createRoot((dispose) => {
|
|
1050
|
+
new EagerComputation(void 0, () => {
|
|
1051
|
+
try {
|
|
1052
|
+
res(fn());
|
|
1053
|
+
} catch (err) {
|
|
1054
|
+
if (err instanceof NotReadyError)
|
|
1055
|
+
throw err;
|
|
1056
|
+
rej(err);
|
|
1057
|
+
}
|
|
1058
|
+
dispose();
|
|
1059
|
+
});
|
|
1005
1060
|
});
|
|
1006
1061
|
});
|
|
1007
1062
|
}
|
|
@@ -1012,26 +1067,17 @@ function createReaction(effect, error, options) {
|
|
|
1012
1067
|
...void 0
|
|
1013
1068
|
});
|
|
1014
1069
|
return (tracking) => {
|
|
1015
|
-
node.
|
|
1070
|
+
node.u = tracking;
|
|
1016
1071
|
node.a = STATE_DIRTY;
|
|
1017
|
-
node.
|
|
1018
|
-
node.
|
|
1072
|
+
node.y();
|
|
1073
|
+
node.u = null;
|
|
1019
1074
|
};
|
|
1020
1075
|
}
|
|
1021
1076
|
|
|
1022
1077
|
// src/store/projection.ts
|
|
1023
|
-
var ProjectionComputation = class extends EagerComputation {
|
|
1024
|
-
q(state, skipQueue) {
|
|
1025
|
-
if (this.a >= state && !this.H)
|
|
1026
|
-
return;
|
|
1027
|
-
if (this.a === STATE_CLEAN && !skipQueue)
|
|
1028
|
-
this.g.enqueue(EFFECT_PURE, this);
|
|
1029
|
-
super.q(state, true);
|
|
1030
|
-
}
|
|
1031
|
-
};
|
|
1032
1078
|
function createProjection(fn, initialValue = {}) {
|
|
1033
1079
|
const [store, setStore] = createStore(initialValue);
|
|
1034
|
-
const node = new ProjectionComputation(
|
|
1080
|
+
const node = new ProjectionComputation(() => {
|
|
1035
1081
|
setStore(fn);
|
|
1036
1082
|
});
|
|
1037
1083
|
const wrapped = /* @__PURE__ */ new WeakMap();
|
|
@@ -1173,7 +1219,7 @@ var proxyTraps = {
|
|
|
1173
1219
|
return desc.get.call(receiver);
|
|
1174
1220
|
}
|
|
1175
1221
|
if (Writing.has(storeValue)) {
|
|
1176
|
-
const value2 = tracked ? tracked.
|
|
1222
|
+
const value2 = tracked ? tracked.c : storeValue[property];
|
|
1177
1223
|
return isWrappable(value2) ? (Writing.add(value2[$RAW] || value2), wrap2(value2)) : value2;
|
|
1178
1224
|
}
|
|
1179
1225
|
let value = tracked ? nodes[property].read() : storeValue[property];
|
|
@@ -1516,19 +1562,19 @@ function mapArray(list, map, options) {
|
|
|
1516
1562
|
return updateKeyedMap.bind({
|
|
1517
1563
|
F: new Owner(),
|
|
1518
1564
|
i: 0,
|
|
1519
|
-
|
|
1520
|
-
|
|
1565
|
+
X: list,
|
|
1566
|
+
x: [],
|
|
1521
1567
|
G: map,
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1568
|
+
g: [],
|
|
1569
|
+
e: [],
|
|
1570
|
+
C: keyFn,
|
|
1525
1571
|
j: keyFn || (options == null ? void 0 : options.keyed) === false ? [] : void 0,
|
|
1526
1572
|
k: map.length > 1 ? [] : void 0,
|
|
1527
1573
|
o: options == null ? void 0 : options.fallback
|
|
1528
1574
|
});
|
|
1529
1575
|
}
|
|
1530
1576
|
function updateKeyedMap() {
|
|
1531
|
-
const newItems = this.
|
|
1577
|
+
const newItems = this.X() || [], newLen = newItems.length;
|
|
1532
1578
|
newItems[$TRACK];
|
|
1533
1579
|
runWithOwner(this.F, () => {
|
|
1534
1580
|
let i, j, mapper = this.j ? () => {
|
|
@@ -1549,38 +1595,38 @@ function updateKeyedMap() {
|
|
|
1549
1595
|
if (newLen === 0) {
|
|
1550
1596
|
if (this.i !== 0) {
|
|
1551
1597
|
this.F.dispose(false);
|
|
1552
|
-
this.
|
|
1553
|
-
this.
|
|
1554
|
-
this.
|
|
1598
|
+
this.e = [];
|
|
1599
|
+
this.x = [];
|
|
1600
|
+
this.g = [];
|
|
1555
1601
|
this.i = 0;
|
|
1556
1602
|
this.j && (this.j = []);
|
|
1557
1603
|
this.k && (this.k = []);
|
|
1558
1604
|
}
|
|
1559
|
-
if (this.o && !this.
|
|
1560
|
-
this.
|
|
1561
|
-
this.
|
|
1605
|
+
if (this.o && !this.g[0]) {
|
|
1606
|
+
this.g[0] = compute(
|
|
1607
|
+
this.e[0] = new Owner(),
|
|
1562
1608
|
this.o,
|
|
1563
1609
|
null
|
|
1564
1610
|
);
|
|
1565
1611
|
}
|
|
1566
1612
|
} else if (this.i === 0) {
|
|
1567
|
-
if (this.
|
|
1568
|
-
this.
|
|
1569
|
-
this.
|
|
1613
|
+
if (this.e[0])
|
|
1614
|
+
this.e[0].dispose();
|
|
1615
|
+
this.g = new Array(newLen);
|
|
1570
1616
|
for (j = 0; j < newLen; j++) {
|
|
1571
|
-
this.
|
|
1572
|
-
this.
|
|
1617
|
+
this.x[j] = newItems[j];
|
|
1618
|
+
this.g[j] = compute(this.e[j] = new Owner(), mapper, null);
|
|
1573
1619
|
}
|
|
1574
1620
|
this.i = newLen;
|
|
1575
1621
|
} else {
|
|
1576
1622
|
let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.j ? new Array(newLen) : void 0, tempIndexes = this.k ? new Array(newLen) : void 0;
|
|
1577
|
-
for (start = 0, end = Math.min(this.i, newLen); start < end && (this.
|
|
1623
|
+
for (start = 0, end = Math.min(this.i, newLen); start < end && (this.x[start] === newItems[start] || this.j && compare(this.C, this.x[start], newItems[start])); start++) {
|
|
1578
1624
|
if (this.j)
|
|
1579
1625
|
this.j[start].write(newItems[start]);
|
|
1580
1626
|
}
|
|
1581
|
-
for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.
|
|
1582
|
-
temp[newEnd] = this.
|
|
1583
|
-
tempNodes[newEnd] = this.
|
|
1627
|
+
for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.x[end] === newItems[newEnd] || this.j && compare(this.C, this.x[end], newItems[newEnd])); end--, newEnd--) {
|
|
1628
|
+
temp[newEnd] = this.g[end];
|
|
1629
|
+
tempNodes[newEnd] = this.e[end];
|
|
1584
1630
|
tempRows && (tempRows[newEnd] = this.j[end]);
|
|
1585
1631
|
tempIndexes && (tempIndexes[newEnd] = this.k[end]);
|
|
1586
1632
|
}
|
|
@@ -1588,29 +1634,29 @@ function updateKeyedMap() {
|
|
|
1588
1634
|
newIndicesNext = new Array(newEnd + 1);
|
|
1589
1635
|
for (j = newEnd; j >= start; j--) {
|
|
1590
1636
|
item = newItems[j];
|
|
1591
|
-
key = this.
|
|
1637
|
+
key = this.C ? this.C(item) : item;
|
|
1592
1638
|
i = newIndices.get(key);
|
|
1593
1639
|
newIndicesNext[j] = i === void 0 ? -1 : i;
|
|
1594
1640
|
newIndices.set(key, j);
|
|
1595
1641
|
}
|
|
1596
1642
|
for (i = start; i <= end; i++) {
|
|
1597
|
-
item = this.
|
|
1598
|
-
key = this.
|
|
1643
|
+
item = this.x[i];
|
|
1644
|
+
key = this.C ? this.C(item) : item;
|
|
1599
1645
|
j = newIndices.get(key);
|
|
1600
1646
|
if (j !== void 0 && j !== -1) {
|
|
1601
|
-
temp[j] = this.
|
|
1602
|
-
tempNodes[j] = this.
|
|
1647
|
+
temp[j] = this.g[i];
|
|
1648
|
+
tempNodes[j] = this.e[i];
|
|
1603
1649
|
tempRows && (tempRows[j] = this.j[i]);
|
|
1604
1650
|
tempIndexes && (tempIndexes[j] = this.k[i]);
|
|
1605
1651
|
j = newIndicesNext[j];
|
|
1606
1652
|
newIndices.set(key, j);
|
|
1607
1653
|
} else
|
|
1608
|
-
this.
|
|
1654
|
+
this.e[i].dispose();
|
|
1609
1655
|
}
|
|
1610
1656
|
for (j = start; j < newLen; j++) {
|
|
1611
1657
|
if (j in temp) {
|
|
1612
|
-
this.
|
|
1613
|
-
this.
|
|
1658
|
+
this.g[j] = temp[j];
|
|
1659
|
+
this.e[j] = tempNodes[j];
|
|
1614
1660
|
if (tempRows) {
|
|
1615
1661
|
this.j[j] = tempRows[j];
|
|
1616
1662
|
this.j[j].write(newItems[j]);
|
|
@@ -1620,60 +1666,60 @@ function updateKeyedMap() {
|
|
|
1620
1666
|
this.k[j].write(j);
|
|
1621
1667
|
}
|
|
1622
1668
|
} else {
|
|
1623
|
-
this.
|
|
1669
|
+
this.g[j] = compute(this.e[j] = new Owner(), mapper, null);
|
|
1624
1670
|
}
|
|
1625
1671
|
}
|
|
1626
|
-
this.
|
|
1627
|
-
this.
|
|
1672
|
+
this.g = this.g.slice(0, this.i = newLen);
|
|
1673
|
+
this.x = newItems.slice(0);
|
|
1628
1674
|
}
|
|
1629
1675
|
});
|
|
1630
|
-
return this.
|
|
1676
|
+
return this.g;
|
|
1631
1677
|
}
|
|
1632
1678
|
function repeat(count, map, options) {
|
|
1633
1679
|
return updateRepeat.bind({
|
|
1634
1680
|
F: new Owner(),
|
|
1635
1681
|
i: 0,
|
|
1636
|
-
|
|
1682
|
+
Y: count,
|
|
1637
1683
|
G: map,
|
|
1638
|
-
|
|
1639
|
-
|
|
1684
|
+
e: [],
|
|
1685
|
+
g: [],
|
|
1640
1686
|
o: options == null ? void 0 : options.fallback
|
|
1641
1687
|
});
|
|
1642
1688
|
}
|
|
1643
1689
|
function updateRepeat() {
|
|
1644
|
-
const newLen = this.
|
|
1690
|
+
const newLen = this.Y();
|
|
1645
1691
|
runWithOwner(this.F, () => {
|
|
1646
1692
|
if (newLen === 0) {
|
|
1647
1693
|
if (this.i !== 0) {
|
|
1648
1694
|
this.F.dispose(false);
|
|
1649
|
-
this.
|
|
1650
|
-
this.
|
|
1695
|
+
this.e = [];
|
|
1696
|
+
this.g = [];
|
|
1651
1697
|
this.i = 0;
|
|
1652
1698
|
}
|
|
1653
|
-
if (this.o && !this.
|
|
1654
|
-
this.
|
|
1655
|
-
this.
|
|
1699
|
+
if (this.o && !this.g[0]) {
|
|
1700
|
+
this.g[0] = compute(
|
|
1701
|
+
this.e[0] = new Owner(),
|
|
1656
1702
|
this.o,
|
|
1657
1703
|
null
|
|
1658
1704
|
);
|
|
1659
1705
|
}
|
|
1660
1706
|
} else {
|
|
1661
|
-
if (this.i === 0 && this.
|
|
1662
|
-
this.
|
|
1707
|
+
if (this.i === 0 && this.e[0])
|
|
1708
|
+
this.e[0].dispose();
|
|
1663
1709
|
for (let i = this.i; i < newLen; i++) {
|
|
1664
|
-
this.
|
|
1665
|
-
this.
|
|
1710
|
+
this.g[i] = compute(
|
|
1711
|
+
this.e[i] = new Owner(),
|
|
1666
1712
|
() => this.G(i),
|
|
1667
1713
|
null
|
|
1668
1714
|
);
|
|
1669
1715
|
}
|
|
1670
1716
|
for (let i = newLen; i < this.i; i++)
|
|
1671
|
-
this.
|
|
1672
|
-
this.
|
|
1717
|
+
this.e[i].dispose();
|
|
1718
|
+
this.g = this.g.slice(0, newLen);
|
|
1673
1719
|
this.i = newLen;
|
|
1674
1720
|
}
|
|
1675
1721
|
});
|
|
1676
|
-
return this.
|
|
1722
|
+
return this.g;
|
|
1677
1723
|
}
|
|
1678
1724
|
function compare(key, a, b) {
|
|
1679
1725
|
return key ? key(a) === key(b) : true;
|
|
@@ -1712,8 +1758,9 @@ exports.getOwner = getOwner;
|
|
|
1712
1758
|
exports.hasContext = hasContext;
|
|
1713
1759
|
exports.hasUpdated = hasUpdated;
|
|
1714
1760
|
exports.isEqual = isEqual;
|
|
1715
|
-
exports.
|
|
1761
|
+
exports.isStale = isStale;
|
|
1716
1762
|
exports.isWrappable = isWrappable;
|
|
1763
|
+
exports.latest = latest;
|
|
1717
1764
|
exports.mapArray = mapArray;
|
|
1718
1765
|
exports.merge = merge;
|
|
1719
1766
|
exports.omit = omit;
|
|
@@ -1721,7 +1768,6 @@ exports.onCleanup = onCleanup;
|
|
|
1721
1768
|
exports.reconcile = reconcile;
|
|
1722
1769
|
exports.repeat = repeat;
|
|
1723
1770
|
exports.resolve = resolve;
|
|
1724
|
-
exports.resolveSync = resolveSync;
|
|
1725
1771
|
exports.runWithOwner = runWithOwner;
|
|
1726
1772
|
exports.setContext = setContext;
|
|
1727
1773
|
exports.untrack = untrack;
|