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