@solidjs/signals 0.0.4 → 0.0.5
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 +92 -19
- package/dist/node.cjs +221 -145
- package/dist/prod.js +218 -145
- package/dist/types/core/index.d.ts +1 -0
- package/dist/types/core/scheduler.d.ts +1 -0
- package/dist/types/core/suspense.d.ts +1 -1
- package/dist/types/core/utils.d.ts +5 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/signals.d.ts +8 -3
- package/package.json +1 -1
- package/dist/types/utils.d.ts +0 -1
package/dist/prod.js
CHANGED
|
@@ -3,9 +3,7 @@ var NotReadyError = class extends Error {
|
|
|
3
3
|
};
|
|
4
4
|
var NoOwnerError = class extends Error {
|
|
5
5
|
constructor() {
|
|
6
|
-
super(
|
|
7
|
-
""
|
|
8
|
-
);
|
|
6
|
+
super("");
|
|
9
7
|
}
|
|
10
8
|
};
|
|
11
9
|
var ContextNotFoundError = class extends Error {
|
|
@@ -16,11 +14,6 @@ var ContextNotFoundError = class extends Error {
|
|
|
16
14
|
}
|
|
17
15
|
};
|
|
18
16
|
|
|
19
|
-
// src/utils.ts
|
|
20
|
-
function isUndefined(value) {
|
|
21
|
-
return typeof value === "undefined";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
17
|
// src/core/constants.ts
|
|
25
18
|
var STATE_CLEAN = 0;
|
|
26
19
|
var STATE_CHECK = 1;
|
|
@@ -32,6 +25,65 @@ var EFFECT_RENDER = 1;
|
|
|
32
25
|
var EFFECT_USER = 2;
|
|
33
26
|
var SUPPORTS_PROXY = typeof Proxy === "function";
|
|
34
27
|
|
|
28
|
+
// src/core/utils.ts
|
|
29
|
+
function isUndefined(value) {
|
|
30
|
+
return typeof value === "undefined";
|
|
31
|
+
}
|
|
32
|
+
function flatten(children, options) {
|
|
33
|
+
if (typeof children === "function" && !children.length) {
|
|
34
|
+
if (options?.doNotUnwrap)
|
|
35
|
+
return children;
|
|
36
|
+
do {
|
|
37
|
+
children = children();
|
|
38
|
+
} while (typeof children === "function" && !children.length);
|
|
39
|
+
}
|
|
40
|
+
if (options?.skipNonRendered && (children == null || children === true || children === false || children === ""))
|
|
41
|
+
return;
|
|
42
|
+
if (Array.isArray(children)) {
|
|
43
|
+
let results = [];
|
|
44
|
+
if (flattenArray(children, results, options)) {
|
|
45
|
+
return () => {
|
|
46
|
+
let nested = [];
|
|
47
|
+
flattenArray(results, nested, { ...options, doNotUnwrap: false });
|
|
48
|
+
return nested;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return results;
|
|
52
|
+
}
|
|
53
|
+
return children;
|
|
54
|
+
}
|
|
55
|
+
function flattenArray(children, results = [], options) {
|
|
56
|
+
let notReady = null;
|
|
57
|
+
let needsUnwrap = false;
|
|
58
|
+
for (let i = 0; i < children.length; i++) {
|
|
59
|
+
try {
|
|
60
|
+
let child = children[i];
|
|
61
|
+
if (typeof child === "function" && !child.length) {
|
|
62
|
+
if (options?.doNotUnwrap) {
|
|
63
|
+
results.push(child);
|
|
64
|
+
needsUnwrap = true;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
do {
|
|
68
|
+
child = child();
|
|
69
|
+
} while (typeof child === "function" && !child.length);
|
|
70
|
+
}
|
|
71
|
+
if (Array.isArray(child)) {
|
|
72
|
+
needsUnwrap = flattenArray(child, results, options);
|
|
73
|
+
} else if (options?.skipNonRendered && (child == null || child === true || child === false || child === "")) {
|
|
74
|
+
} else
|
|
75
|
+
results.push(child);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
if (!(e instanceof NotReadyError))
|
|
78
|
+
throw e;
|
|
79
|
+
notReady = e;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (notReady)
|
|
83
|
+
throw notReady;
|
|
84
|
+
return needsUnwrap;
|
|
85
|
+
}
|
|
86
|
+
|
|
35
87
|
// src/core/owner.ts
|
|
36
88
|
var currentOwner = null;
|
|
37
89
|
var defaultContext = {};
|
|
@@ -51,9 +103,9 @@ var Owner = class {
|
|
|
51
103
|
m = null;
|
|
52
104
|
p = null;
|
|
53
105
|
a = STATE_CLEAN;
|
|
54
|
-
h = null;
|
|
55
|
-
n = defaultContext;
|
|
56
106
|
i = null;
|
|
107
|
+
n = defaultContext;
|
|
108
|
+
j = null;
|
|
57
109
|
e = null;
|
|
58
110
|
constructor(signal = false) {
|
|
59
111
|
if (currentOwner && !signal)
|
|
@@ -69,8 +121,8 @@ var Owner = class {
|
|
|
69
121
|
if (child.n !== this.n) {
|
|
70
122
|
child.n = { ...this.n, ...child.n };
|
|
71
123
|
}
|
|
72
|
-
if (this.
|
|
73
|
-
child.
|
|
124
|
+
if (this.j) {
|
|
125
|
+
child.j = !child.j ? this.j : [...child.j, ...this.j];
|
|
74
126
|
}
|
|
75
127
|
if (this.e)
|
|
76
128
|
child.e = this.e;
|
|
@@ -99,30 +151,30 @@ var Owner = class {
|
|
|
99
151
|
this.o = null;
|
|
100
152
|
this.p = null;
|
|
101
153
|
this.n = defaultContext;
|
|
102
|
-
this.
|
|
154
|
+
this.j = null;
|
|
103
155
|
this.a = STATE_DISPOSED;
|
|
104
156
|
this.emptyDisposal();
|
|
105
157
|
}
|
|
106
158
|
emptyDisposal() {
|
|
107
|
-
if (!this.
|
|
159
|
+
if (!this.i)
|
|
108
160
|
return;
|
|
109
|
-
if (Array.isArray(this.
|
|
110
|
-
for (let i = 0; i < this.
|
|
111
|
-
const callable = this.
|
|
161
|
+
if (Array.isArray(this.i)) {
|
|
162
|
+
for (let i = 0; i < this.i.length; i++) {
|
|
163
|
+
const callable = this.i[i];
|
|
112
164
|
callable.call(callable);
|
|
113
165
|
}
|
|
114
166
|
} else {
|
|
115
|
-
this.
|
|
167
|
+
this.i.call(this.i);
|
|
116
168
|
}
|
|
117
|
-
this.
|
|
169
|
+
this.i = null;
|
|
118
170
|
}
|
|
119
171
|
handleError(error) {
|
|
120
|
-
if (!this.
|
|
172
|
+
if (!this.j)
|
|
121
173
|
throw error;
|
|
122
|
-
let i = 0, len = this.
|
|
174
|
+
let i = 0, len = this.j.length;
|
|
123
175
|
for (i = 0; i < len; i++) {
|
|
124
176
|
try {
|
|
125
|
-
this.
|
|
177
|
+
this.j[i](error);
|
|
126
178
|
break;
|
|
127
179
|
} catch (e) {
|
|
128
180
|
error = e;
|
|
@@ -161,12 +213,12 @@ function onCleanup(fn) {
|
|
|
161
213
|
if (!currentOwner)
|
|
162
214
|
return fn;
|
|
163
215
|
const node = currentOwner;
|
|
164
|
-
if (!node.
|
|
165
|
-
node.
|
|
166
|
-
} else if (Array.isArray(node.
|
|
167
|
-
node.
|
|
216
|
+
if (!node.i) {
|
|
217
|
+
node.i = fn;
|
|
218
|
+
} else if (Array.isArray(node.i)) {
|
|
219
|
+
node.i.push(fn);
|
|
168
220
|
} else {
|
|
169
|
-
node.
|
|
221
|
+
node.i = [node.i, fn];
|
|
170
222
|
}
|
|
171
223
|
return fn;
|
|
172
224
|
}
|
|
@@ -195,10 +247,10 @@ function incrementClock() {
|
|
|
195
247
|
}
|
|
196
248
|
var UNCHANGED = Symbol(0);
|
|
197
249
|
var Computation = class extends Owner {
|
|
198
|
-
b = null;
|
|
199
250
|
c = null;
|
|
251
|
+
b = null;
|
|
200
252
|
d;
|
|
201
|
-
|
|
253
|
+
B;
|
|
202
254
|
// Used in __DEV__ mode, hopefully removed in production
|
|
203
255
|
V;
|
|
204
256
|
// Using false is an optimization as an alternative to _equals: () => false
|
|
@@ -206,15 +258,15 @@ var Computation = class extends Owner {
|
|
|
206
258
|
F = isEqual;
|
|
207
259
|
N;
|
|
208
260
|
/** Whether the computation is an error or has ancestors that are unresolved */
|
|
209
|
-
|
|
261
|
+
f = 0;
|
|
210
262
|
/** Which flags raised by sources are handled, vs. being passed through. */
|
|
211
|
-
|
|
263
|
+
C = DEFAULT_FLAGS;
|
|
212
264
|
G = null;
|
|
213
265
|
H = null;
|
|
214
266
|
I = -1;
|
|
215
267
|
constructor(initialValue, compute2, options) {
|
|
216
268
|
super(compute2 === null);
|
|
217
|
-
this.
|
|
269
|
+
this.B = compute2;
|
|
218
270
|
this.a = compute2 ? STATE_UNINITIALIZED : STATE_CLEAN;
|
|
219
271
|
this.d = initialValue;
|
|
220
272
|
if (options?.equals !== void 0)
|
|
@@ -223,12 +275,12 @@ var Computation = class extends Owner {
|
|
|
223
275
|
this.N = options?.unobserved;
|
|
224
276
|
}
|
|
225
277
|
O() {
|
|
226
|
-
if (this.
|
|
278
|
+
if (this.B)
|
|
227
279
|
this.s();
|
|
228
|
-
if (!this.
|
|
280
|
+
if (!this.B || this.c?.length)
|
|
229
281
|
track(this);
|
|
230
|
-
newFlags |= this.
|
|
231
|
-
if (this.
|
|
282
|
+
newFlags |= this.f & ~currentMask;
|
|
283
|
+
if (this.f & ERROR_BIT) {
|
|
232
284
|
throw this.d;
|
|
233
285
|
} else {
|
|
234
286
|
return this.d;
|
|
@@ -283,15 +335,15 @@ var Computation = class extends Owner {
|
|
|
283
335
|
const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.a === STATE_UNINITIALIZED || this.F === false || !this.F(this.d, newValue));
|
|
284
336
|
if (valueChanged)
|
|
285
337
|
this.d = newValue;
|
|
286
|
-
const changedFlagsMask = this.
|
|
287
|
-
this.
|
|
338
|
+
const changedFlagsMask = this.f ^ flags, changedFlags = changedFlagsMask & flags;
|
|
339
|
+
this.f = flags;
|
|
288
340
|
this.I = clock + 1;
|
|
289
|
-
if (this.
|
|
290
|
-
for (let i = 0; i < this.
|
|
341
|
+
if (this.b) {
|
|
342
|
+
for (let i = 0; i < this.b.length; i++) {
|
|
291
343
|
if (valueChanged) {
|
|
292
|
-
this.
|
|
344
|
+
this.b[i].t(STATE_DIRTY);
|
|
293
345
|
} else if (changedFlagsMask) {
|
|
294
|
-
this.
|
|
346
|
+
this.b[i].P(changedFlagsMask, changedFlags);
|
|
295
347
|
}
|
|
296
348
|
}
|
|
297
349
|
}
|
|
@@ -304,9 +356,9 @@ var Computation = class extends Owner {
|
|
|
304
356
|
if (this.a >= state)
|
|
305
357
|
return;
|
|
306
358
|
this.a = state;
|
|
307
|
-
if (this.
|
|
308
|
-
for (let i = 0; i < this.
|
|
309
|
-
this.
|
|
359
|
+
if (this.b) {
|
|
360
|
+
for (let i = 0; i < this.b.length; i++) {
|
|
361
|
+
this.b[i].t(STATE_CHECK);
|
|
310
362
|
}
|
|
311
363
|
}
|
|
312
364
|
}
|
|
@@ -319,27 +371,27 @@ var Computation = class extends Owner {
|
|
|
319
371
|
P(mask, newFlags2) {
|
|
320
372
|
if (this.a >= STATE_DIRTY)
|
|
321
373
|
return;
|
|
322
|
-
if (mask & this.
|
|
374
|
+
if (mask & this.C) {
|
|
323
375
|
this.t(STATE_DIRTY);
|
|
324
376
|
return;
|
|
325
377
|
}
|
|
326
378
|
if (this.a >= STATE_CHECK)
|
|
327
379
|
return;
|
|
328
|
-
const prevFlags = this.
|
|
380
|
+
const prevFlags = this.f & mask;
|
|
329
381
|
const deltaFlags = prevFlags ^ newFlags2;
|
|
330
382
|
if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
|
|
331
383
|
this.t(STATE_CHECK);
|
|
332
384
|
} else {
|
|
333
|
-
this.
|
|
334
|
-
if (this.
|
|
335
|
-
for (let i = 0; i < this.
|
|
336
|
-
this.
|
|
385
|
+
this.f ^= deltaFlags;
|
|
386
|
+
if (this.b) {
|
|
387
|
+
for (let i = 0; i < this.b.length; i++) {
|
|
388
|
+
this.b[i].P(mask, newFlags2);
|
|
337
389
|
}
|
|
338
390
|
}
|
|
339
391
|
}
|
|
340
392
|
}
|
|
341
393
|
Q(error) {
|
|
342
|
-
this.write(error, this.
|
|
394
|
+
this.write(error, this.f | ERROR_BIT);
|
|
343
395
|
}
|
|
344
396
|
/**
|
|
345
397
|
* This is the core part of the reactivity system, which makes sure that the values are updated
|
|
@@ -357,9 +409,9 @@ var Computation = class extends Owner {
|
|
|
357
409
|
}
|
|
358
410
|
let observerFlags = 0;
|
|
359
411
|
if (this.a === STATE_CHECK) {
|
|
360
|
-
for (let i = 0; i < this.
|
|
361
|
-
this.
|
|
362
|
-
observerFlags |= this.
|
|
412
|
+
for (let i = 0; i < this.c.length; i++) {
|
|
413
|
+
this.c[i].s();
|
|
414
|
+
observerFlags |= this.c[i].f;
|
|
363
415
|
if (this.a === STATE_DIRTY) {
|
|
364
416
|
break;
|
|
365
417
|
}
|
|
@@ -378,7 +430,7 @@ var Computation = class extends Owner {
|
|
|
378
430
|
x() {
|
|
379
431
|
if (this.a === STATE_DISPOSED)
|
|
380
432
|
return;
|
|
381
|
-
if (this.
|
|
433
|
+
if (this.c)
|
|
382
434
|
removeSourceObservers(this, 0);
|
|
383
435
|
super.x();
|
|
384
436
|
}
|
|
@@ -391,11 +443,11 @@ function loadingState(node) {
|
|
|
391
443
|
() => {
|
|
392
444
|
track(node);
|
|
393
445
|
node.s();
|
|
394
|
-
return !!(node.
|
|
446
|
+
return !!(node.f & LOADING_BIT);
|
|
395
447
|
},
|
|
396
448
|
options
|
|
397
449
|
);
|
|
398
|
-
computation.
|
|
450
|
+
computation.C = ERROR_BIT | LOADING_BIT;
|
|
399
451
|
setOwner(prevOwner);
|
|
400
452
|
return computation;
|
|
401
453
|
}
|
|
@@ -407,17 +459,17 @@ function errorState(node) {
|
|
|
407
459
|
() => {
|
|
408
460
|
track(node);
|
|
409
461
|
node.s();
|
|
410
|
-
return !!(node.
|
|
462
|
+
return !!(node.f & ERROR_BIT);
|
|
411
463
|
},
|
|
412
464
|
options
|
|
413
465
|
);
|
|
414
|
-
computation.
|
|
466
|
+
computation.C = ERROR_BIT;
|
|
415
467
|
setOwner(prevOwner);
|
|
416
468
|
return computation;
|
|
417
469
|
}
|
|
418
470
|
function track(computation) {
|
|
419
471
|
if (currentObserver) {
|
|
420
|
-
if (!newSources && currentObserver.
|
|
472
|
+
if (!newSources && currentObserver.c && currentObserver.c[newSourcesIndex] === computation) {
|
|
421
473
|
newSourcesIndex++;
|
|
422
474
|
} else if (!newSources)
|
|
423
475
|
newSources = [computation];
|
|
@@ -437,7 +489,7 @@ function update(node) {
|
|
|
437
489
|
try {
|
|
438
490
|
node.dispose(false);
|
|
439
491
|
node.emptyDisposal();
|
|
440
|
-
const result = compute(node, node.
|
|
492
|
+
const result = compute(node, node.B, node);
|
|
441
493
|
node.write(result, newFlags, true);
|
|
442
494
|
} catch (error) {
|
|
443
495
|
if (error instanceof NotReadyError) {
|
|
@@ -447,27 +499,27 @@ function update(node) {
|
|
|
447
499
|
}
|
|
448
500
|
} finally {
|
|
449
501
|
if (newSources) {
|
|
450
|
-
if (node.
|
|
502
|
+
if (node.c)
|
|
451
503
|
removeSourceObservers(node, newSourcesIndex);
|
|
452
|
-
if (node.
|
|
453
|
-
node.
|
|
504
|
+
if (node.c && newSourcesIndex > 0) {
|
|
505
|
+
node.c.length = newSourcesIndex + newSources.length;
|
|
454
506
|
for (let i = 0; i < newSources.length; i++) {
|
|
455
|
-
node.
|
|
507
|
+
node.c[newSourcesIndex + i] = newSources[i];
|
|
456
508
|
}
|
|
457
509
|
} else {
|
|
458
|
-
node.
|
|
510
|
+
node.c = newSources;
|
|
459
511
|
}
|
|
460
512
|
let source;
|
|
461
|
-
for (let i = newSourcesIndex; i < node.
|
|
462
|
-
source = node.
|
|
463
|
-
if (!source.
|
|
464
|
-
source.
|
|
513
|
+
for (let i = newSourcesIndex; i < node.c.length; i++) {
|
|
514
|
+
source = node.c[i];
|
|
515
|
+
if (!source.b)
|
|
516
|
+
source.b = [node];
|
|
465
517
|
else
|
|
466
|
-
source.
|
|
518
|
+
source.b.push(node);
|
|
467
519
|
}
|
|
468
|
-
} else if (node.
|
|
520
|
+
} else if (node.c && newSourcesIndex < node.c.length) {
|
|
469
521
|
removeSourceObservers(node, newSourcesIndex);
|
|
470
|
-
node.
|
|
522
|
+
node.c.length = newSourcesIndex;
|
|
471
523
|
}
|
|
472
524
|
newSources = prevSources;
|
|
473
525
|
newSourcesIndex = prevSourcesIndex;
|
|
@@ -478,13 +530,13 @@ function update(node) {
|
|
|
478
530
|
function removeSourceObservers(node, index) {
|
|
479
531
|
let source;
|
|
480
532
|
let swap;
|
|
481
|
-
for (let i = index; i < node.
|
|
482
|
-
source = node.
|
|
483
|
-
if (source.
|
|
484
|
-
swap = source.
|
|
485
|
-
source.
|
|
486
|
-
source.
|
|
487
|
-
if (!source.
|
|
533
|
+
for (let i = index; i < node.c.length; i++) {
|
|
534
|
+
source = node.c[i];
|
|
535
|
+
if (source.b) {
|
|
536
|
+
swap = source.b.indexOf(node);
|
|
537
|
+
source.b[swap] = source.b[source.b.length - 1];
|
|
538
|
+
source.b.pop();
|
|
539
|
+
if (!source.b.length)
|
|
488
540
|
source.N?.();
|
|
489
541
|
}
|
|
490
542
|
}
|
|
@@ -529,7 +581,7 @@ function latest(fn) {
|
|
|
529
581
|
function compute(owner, compute2, observer) {
|
|
530
582
|
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask;
|
|
531
583
|
currentObserver = observer;
|
|
532
|
-
currentMask = observer?.
|
|
584
|
+
currentMask = observer?.C ?? DEFAULT_FLAGS;
|
|
533
585
|
try {
|
|
534
586
|
return compute2(observer ? observer.d : void 0);
|
|
535
587
|
} finally {
|
|
@@ -545,11 +597,11 @@ function schedule() {
|
|
|
545
597
|
if (scheduled)
|
|
546
598
|
return;
|
|
547
599
|
scheduled = true;
|
|
548
|
-
if (!globalQueue.
|
|
600
|
+
if (!globalQueue.D)
|
|
549
601
|
queueMicrotask(flushSync);
|
|
550
602
|
}
|
|
551
603
|
var Queue = class {
|
|
552
|
-
|
|
604
|
+
D = false;
|
|
553
605
|
u = [[], [], []];
|
|
554
606
|
z = [];
|
|
555
607
|
enqueue(type, node) {
|
|
@@ -574,9 +626,9 @@ var Queue = class {
|
|
|
574
626
|
}
|
|
575
627
|
}
|
|
576
628
|
flush() {
|
|
577
|
-
if (this.
|
|
629
|
+
if (this.D)
|
|
578
630
|
return;
|
|
579
|
-
this.
|
|
631
|
+
this.D = true;
|
|
580
632
|
try {
|
|
581
633
|
this.run(EFFECT_PURE);
|
|
582
634
|
incrementClock();
|
|
@@ -584,7 +636,7 @@ var Queue = class {
|
|
|
584
636
|
this.run(EFFECT_RENDER);
|
|
585
637
|
this.run(EFFECT_USER);
|
|
586
638
|
} finally {
|
|
587
|
-
this.
|
|
639
|
+
this.D = false;
|
|
588
640
|
}
|
|
589
641
|
}
|
|
590
642
|
addChild(child) {
|
|
@@ -597,11 +649,19 @@ var Queue = class {
|
|
|
597
649
|
}
|
|
598
650
|
};
|
|
599
651
|
var globalQueue = new Queue();
|
|
652
|
+
var globalTasks = [];
|
|
600
653
|
function flushSync() {
|
|
601
654
|
while (scheduled) {
|
|
602
655
|
globalQueue.flush();
|
|
656
|
+
for (let i = 0; i < globalTasks.length; i++)
|
|
657
|
+
globalTasks[i]();
|
|
658
|
+
globalTasks.length = 0;
|
|
603
659
|
}
|
|
604
660
|
}
|
|
661
|
+
function queueTask(fn) {
|
|
662
|
+
globalTasks.push(fn);
|
|
663
|
+
schedule();
|
|
664
|
+
}
|
|
605
665
|
function createBoundary(fn, queue) {
|
|
606
666
|
const owner = new Owner();
|
|
607
667
|
const parentQueue = owner.e || globalQueue;
|
|
@@ -636,23 +696,23 @@ function runEffectQueue(queue) {
|
|
|
636
696
|
var Effect = class extends Computation {
|
|
637
697
|
J;
|
|
638
698
|
K = false;
|
|
639
|
-
|
|
640
|
-
|
|
699
|
+
E;
|
|
700
|
+
A;
|
|
641
701
|
e;
|
|
642
702
|
constructor(initialValue, compute2, effect, options) {
|
|
643
703
|
super(initialValue, compute2, options);
|
|
644
704
|
this.J = effect;
|
|
645
|
-
this.
|
|
646
|
-
this.
|
|
705
|
+
this.E = initialValue;
|
|
706
|
+
this.A = options?.render ? EFFECT_RENDER : EFFECT_USER;
|
|
647
707
|
this.e = getOwner()?.e || globalQueue;
|
|
648
708
|
this.s();
|
|
649
|
-
this.
|
|
709
|
+
this.A === EFFECT_USER ? this.e.enqueue(this.A, this) : this.R();
|
|
650
710
|
}
|
|
651
711
|
write(value, flags = 0) {
|
|
652
|
-
const currentFlags = this.
|
|
653
|
-
this.
|
|
654
|
-
if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
655
|
-
this.e.
|
|
712
|
+
const currentFlags = this.f;
|
|
713
|
+
this.f = flags;
|
|
714
|
+
if (this.A === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
715
|
+
this.e.S?.(this);
|
|
656
716
|
}
|
|
657
717
|
if (value === UNCHANGED)
|
|
658
718
|
return this.d;
|
|
@@ -664,7 +724,7 @@ var Effect = class extends Computation {
|
|
|
664
724
|
if (this.a >= state)
|
|
665
725
|
return;
|
|
666
726
|
if (this.a === STATE_CLEAN)
|
|
667
|
-
this.e.enqueue(this.
|
|
727
|
+
this.e.enqueue(this.A, this);
|
|
668
728
|
this.a = state;
|
|
669
729
|
}
|
|
670
730
|
Q(error) {
|
|
@@ -672,13 +732,13 @@ var Effect = class extends Computation {
|
|
|
672
732
|
}
|
|
673
733
|
x() {
|
|
674
734
|
this.J = void 0;
|
|
675
|
-
this.
|
|
735
|
+
this.E = void 0;
|
|
676
736
|
super.x();
|
|
677
737
|
}
|
|
678
738
|
R() {
|
|
679
739
|
if (this.K && this.a !== STATE_DISPOSED) {
|
|
680
|
-
this.J(this.d, this.
|
|
681
|
-
this.
|
|
740
|
+
this.J(this.d, this.E);
|
|
741
|
+
this.E = this.d;
|
|
682
742
|
this.K = false;
|
|
683
743
|
}
|
|
684
744
|
}
|
|
@@ -701,7 +761,7 @@ var EagerComputation = class extends Computation {
|
|
|
701
761
|
|
|
702
762
|
// src/core/suspense.ts
|
|
703
763
|
var SuspenseQueue = class extends Queue {
|
|
704
|
-
|
|
764
|
+
g = /* @__PURE__ */ new Set();
|
|
705
765
|
q = false;
|
|
706
766
|
L = new Computation(false, null);
|
|
707
767
|
run(type) {
|
|
@@ -709,27 +769,40 @@ var SuspenseQueue = class extends Queue {
|
|
|
709
769
|
return;
|
|
710
770
|
super.run(type);
|
|
711
771
|
}
|
|
712
|
-
|
|
713
|
-
if (node.
|
|
714
|
-
this.
|
|
772
|
+
S(node) {
|
|
773
|
+
if (node.f & LOADING_BIT) {
|
|
774
|
+
this.g.add(node);
|
|
715
775
|
if (!this.q) {
|
|
716
776
|
this.q = true;
|
|
717
|
-
|
|
777
|
+
queueTask(() => this.L.write(true));
|
|
718
778
|
}
|
|
719
779
|
} else {
|
|
720
|
-
this.
|
|
721
|
-
if (this.
|
|
780
|
+
this.g.delete(node);
|
|
781
|
+
if (this.g.size === 0) {
|
|
722
782
|
this.q = false;
|
|
723
|
-
|
|
783
|
+
queueTask(() => this.L.write(false));
|
|
724
784
|
}
|
|
725
785
|
}
|
|
726
786
|
}
|
|
727
787
|
};
|
|
788
|
+
var LiveComputation = class extends EagerComputation {
|
|
789
|
+
write(value, flags = 0) {
|
|
790
|
+
const currentFlags = this.f;
|
|
791
|
+
super.write(value, flags);
|
|
792
|
+
if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
793
|
+
this.e.S?.(this);
|
|
794
|
+
}
|
|
795
|
+
return this.d;
|
|
796
|
+
}
|
|
797
|
+
};
|
|
728
798
|
function createSuspense(fn, fallbackFn) {
|
|
729
799
|
const queue = new SuspenseQueue();
|
|
730
|
-
const tree = createBoundary(
|
|
800
|
+
const tree = createBoundary(() => {
|
|
801
|
+
const child = new Computation(null, fn);
|
|
802
|
+
return new LiveComputation(null, () => flatten(child.wait()));
|
|
803
|
+
}, queue);
|
|
731
804
|
const equality = new Computation(null, () => queue.L.read() || queue.q);
|
|
732
|
-
const comp = new Computation(null, () => equality.read() ? untrack(fallbackFn) : tree);
|
|
805
|
+
const comp = new Computation(null, () => equality.read() ? untrack(fallbackFn) : tree.read());
|
|
733
806
|
return comp.read.bind(comp);
|
|
734
807
|
}
|
|
735
808
|
|
|
@@ -759,10 +832,10 @@ function createMemo(compute2, value, options) {
|
|
|
759
832
|
return () => {
|
|
760
833
|
if (node) {
|
|
761
834
|
resolvedValue = node.wait();
|
|
762
|
-
if (!node.
|
|
835
|
+
if (!node.c?.length && node.m?.o !== node) {
|
|
763
836
|
node.dispose();
|
|
764
837
|
node = void 0;
|
|
765
|
-
} else if (!node.o && !node.
|
|
838
|
+
} else if (!node.o && !node.b?.length) {
|
|
766
839
|
node.dispose();
|
|
767
840
|
node.a = STATE_UNINITIALIZED;
|
|
768
841
|
}
|
|
@@ -793,7 +866,7 @@ function createAsync(compute2, value, options) {
|
|
|
793
866
|
if (isPromise) {
|
|
794
867
|
source.then(
|
|
795
868
|
(value3) => {
|
|
796
|
-
signal.write(value3, 0);
|
|
869
|
+
signal.write(value3, 0, true);
|
|
797
870
|
},
|
|
798
871
|
(error) => {
|
|
799
872
|
signal.write(error, ERROR_BIT);
|
|
@@ -807,7 +880,7 @@ function createAsync(compute2, value, options) {
|
|
|
807
880
|
for await (let value3 of source) {
|
|
808
881
|
if (abort)
|
|
809
882
|
return;
|
|
810
|
-
signal.write(value3, 0);
|
|
883
|
+
signal.write(value3, 0, true);
|
|
811
884
|
}
|
|
812
885
|
} catch (error) {
|
|
813
886
|
signal.write(error, ERROR_BIT);
|
|
@@ -847,9 +920,9 @@ function runWithOwner(owner, run) {
|
|
|
847
920
|
}
|
|
848
921
|
function catchError(fn, handler) {
|
|
849
922
|
const owner = new Owner();
|
|
850
|
-
owner.
|
|
923
|
+
owner.j = owner.j ? [handler, ...owner.j] : [handler];
|
|
851
924
|
try {
|
|
852
|
-
compute(owner, fn, null);
|
|
925
|
+
return compute(owner, fn, null);
|
|
853
926
|
} catch (error) {
|
|
854
927
|
owner.handleError(error);
|
|
855
928
|
}
|
|
@@ -1314,15 +1387,15 @@ function omit(props, ...keys) {
|
|
|
1314
1387
|
function mapArray(list, map, options) {
|
|
1315
1388
|
const keyFn = typeof options?.keyed === "function" ? options.keyed : void 0;
|
|
1316
1389
|
return updateKeyedMap.bind({
|
|
1317
|
-
|
|
1390
|
+
T: new Owner(),
|
|
1318
1391
|
w: 0,
|
|
1319
1392
|
U: list,
|
|
1320
1393
|
r: [],
|
|
1321
1394
|
M: map,
|
|
1322
1395
|
k: [],
|
|
1323
|
-
|
|
1396
|
+
g: [],
|
|
1324
1397
|
y: keyFn,
|
|
1325
|
-
|
|
1398
|
+
h: keyFn || options?.keyed === false ? [] : void 0,
|
|
1326
1399
|
l: map.length > 1 ? [] : void 0,
|
|
1327
1400
|
q: options?.fallback
|
|
1328
1401
|
});
|
|
@@ -1330,12 +1403,12 @@ function mapArray(list, map, options) {
|
|
|
1330
1403
|
function updateKeyedMap() {
|
|
1331
1404
|
const newItems = this.U() || [], newLen = newItems.length;
|
|
1332
1405
|
newItems[$TRACK];
|
|
1333
|
-
runWithOwner(this.
|
|
1334
|
-
let i, j, mapper = this.
|
|
1335
|
-
this.
|
|
1406
|
+
runWithOwner(this.T, () => {
|
|
1407
|
+
let i, j, mapper = this.h ? () => {
|
|
1408
|
+
this.h[j] = new Computation(newItems[j], null);
|
|
1336
1409
|
this.l[j] = new Computation(j, null);
|
|
1337
1410
|
return this.M(
|
|
1338
|
-
Computation.prototype.read.bind(this.
|
|
1411
|
+
Computation.prototype.read.bind(this.h[j]),
|
|
1339
1412
|
Computation.prototype.read.bind(this.l[j])
|
|
1340
1413
|
);
|
|
1341
1414
|
} : this.l ? () => {
|
|
@@ -1348,40 +1421,40 @@ function updateKeyedMap() {
|
|
|
1348
1421
|
};
|
|
1349
1422
|
if (newLen === 0) {
|
|
1350
1423
|
if (this.w !== 0) {
|
|
1351
|
-
this.
|
|
1352
|
-
this.
|
|
1424
|
+
this.T.dispose(false);
|
|
1425
|
+
this.g = [];
|
|
1353
1426
|
this.r = [];
|
|
1354
1427
|
this.k = [];
|
|
1355
1428
|
this.w = 0;
|
|
1356
|
-
this.
|
|
1429
|
+
this.h && (this.h = []);
|
|
1357
1430
|
this.l && (this.l = []);
|
|
1358
1431
|
}
|
|
1359
1432
|
if (this.q && !this.k[0]) {
|
|
1360
1433
|
this.k[0] = compute(
|
|
1361
|
-
this.
|
|
1434
|
+
this.g[0] = new Owner(),
|
|
1362
1435
|
this.q,
|
|
1363
1436
|
null
|
|
1364
1437
|
);
|
|
1365
1438
|
}
|
|
1366
1439
|
} else if (this.w === 0) {
|
|
1367
|
-
if (this.
|
|
1368
|
-
this.
|
|
1440
|
+
if (this.g[0])
|
|
1441
|
+
this.g[0].dispose();
|
|
1369
1442
|
this.k = new Array(newLen);
|
|
1370
1443
|
for (j = 0; j < newLen; j++) {
|
|
1371
1444
|
this.r[j] = newItems[j];
|
|
1372
|
-
this.k[j] = compute(this.
|
|
1445
|
+
this.k[j] = compute(this.g[j] = new Owner(), mapper, null);
|
|
1373
1446
|
}
|
|
1374
1447
|
this.w = newLen;
|
|
1375
1448
|
} else {
|
|
1376
|
-
let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.
|
|
1377
|
-
for (start = 0, end = Math.min(this.w, newLen); start < end && (this.r[start] === newItems[start] || this.
|
|
1378
|
-
if (this.
|
|
1379
|
-
this.
|
|
1449
|
+
let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.h ? new Array(newLen) : void 0, tempIndexes = this.l ? new Array(newLen) : void 0;
|
|
1450
|
+
for (start = 0, end = Math.min(this.w, newLen); start < end && (this.r[start] === newItems[start] || this.h && compare(this.y, this.r[start], newItems[start])); start++) {
|
|
1451
|
+
if (this.h)
|
|
1452
|
+
this.h[start].write(newItems[start]);
|
|
1380
1453
|
}
|
|
1381
|
-
for (end = this.w - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.r[end] === newItems[newEnd] || this.
|
|
1454
|
+
for (end = this.w - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.r[end] === newItems[newEnd] || this.h && compare(this.y, this.r[end], newItems[newEnd])); end--, newEnd--) {
|
|
1382
1455
|
temp[newEnd] = this.k[end];
|
|
1383
|
-
tempNodes[newEnd] = this.
|
|
1384
|
-
tempRows && (tempRows[newEnd] = this.
|
|
1456
|
+
tempNodes[newEnd] = this.g[end];
|
|
1457
|
+
tempRows && (tempRows[newEnd] = this.h[end]);
|
|
1385
1458
|
tempIndexes && (tempIndexes[newEnd] = this.l[end]);
|
|
1386
1459
|
}
|
|
1387
1460
|
newIndices = /* @__PURE__ */ new Map();
|
|
@@ -1399,28 +1472,28 @@ function updateKeyedMap() {
|
|
|
1399
1472
|
j = newIndices.get(key);
|
|
1400
1473
|
if (j !== void 0 && j !== -1) {
|
|
1401
1474
|
temp[j] = this.k[i];
|
|
1402
|
-
tempNodes[j] = this.
|
|
1403
|
-
tempRows && (tempRows[j] = this.
|
|
1475
|
+
tempNodes[j] = this.g[i];
|
|
1476
|
+
tempRows && (tempRows[j] = this.h[i]);
|
|
1404
1477
|
tempIndexes && (tempIndexes[j] = this.l[i]);
|
|
1405
1478
|
j = newIndicesNext[j];
|
|
1406
1479
|
newIndices.set(key, j);
|
|
1407
1480
|
} else
|
|
1408
|
-
this.
|
|
1481
|
+
this.g[i].dispose();
|
|
1409
1482
|
}
|
|
1410
1483
|
for (j = start; j < newLen; j++) {
|
|
1411
1484
|
if (j in temp) {
|
|
1412
1485
|
this.k[j] = temp[j];
|
|
1413
|
-
this.
|
|
1486
|
+
this.g[j] = tempNodes[j];
|
|
1414
1487
|
if (tempRows) {
|
|
1415
|
-
this.
|
|
1416
|
-
this.
|
|
1488
|
+
this.h[j] = tempRows[j];
|
|
1489
|
+
this.h[j].write(newItems[j]);
|
|
1417
1490
|
}
|
|
1418
1491
|
if (tempIndexes) {
|
|
1419
1492
|
this.l[j] = tempIndexes[j];
|
|
1420
1493
|
this.l[j].write(j);
|
|
1421
1494
|
}
|
|
1422
1495
|
} else {
|
|
1423
|
-
this.k[j] = compute(this.
|
|
1496
|
+
this.k[j] = compute(this.g[j] = new Owner(), mapper, null);
|
|
1424
1497
|
}
|
|
1425
1498
|
}
|
|
1426
1499
|
this.k = this.k.slice(0, this.w = newLen);
|
|
@@ -1433,4 +1506,4 @@ function compare(key, a, b) {
|
|
|
1433
1506
|
return key ? key(a) === key(b) : true;
|
|
1434
1507
|
}
|
|
1435
1508
|
|
|
1436
|
-
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, runWithOwner, setContext, untrack, unwrap };
|
|
1509
|
+
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, runWithOwner, setContext, untrack, unwrap };
|