@solidjs/signals 0.0.4 → 0.0.6
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 +122 -27
- package/dist/node.cjs +306 -208
- package/dist/prod.js +302 -207
- package/dist/types/core/index.d.ts +2 -1
- package/dist/types/core/scheduler.d.ts +1 -0
- package/dist/types/core/suspense.d.ts +2 -2
- 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
|
-
|
|
106
|
+
j = null;
|
|
55
107
|
n = defaultContext;
|
|
56
|
-
|
|
108
|
+
k = 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.k) {
|
|
125
|
+
child.k = !child.k ? this.k : [...child.k, ...this.k];
|
|
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.k = null;
|
|
103
155
|
this.a = STATE_DISPOSED;
|
|
104
156
|
this.emptyDisposal();
|
|
105
157
|
}
|
|
106
158
|
emptyDisposal() {
|
|
107
|
-
if (!this.
|
|
159
|
+
if (!this.j)
|
|
108
160
|
return;
|
|
109
|
-
if (Array.isArray(this.
|
|
110
|
-
for (let i = 0; i < this.
|
|
111
|
-
const callable = this.
|
|
161
|
+
if (Array.isArray(this.j)) {
|
|
162
|
+
for (let i = 0; i < this.j.length; i++) {
|
|
163
|
+
const callable = this.j[i];
|
|
112
164
|
callable.call(callable);
|
|
113
165
|
}
|
|
114
166
|
} else {
|
|
115
|
-
this.
|
|
167
|
+
this.j.call(this.j);
|
|
116
168
|
}
|
|
117
|
-
this.
|
|
169
|
+
this.j = null;
|
|
118
170
|
}
|
|
119
171
|
handleError(error) {
|
|
120
|
-
if (!this.
|
|
172
|
+
if (!this.k)
|
|
121
173
|
throw error;
|
|
122
|
-
let i = 0, len = this.
|
|
174
|
+
let i = 0, len = this.k.length;
|
|
123
175
|
for (i = 0; i < len; i++) {
|
|
124
176
|
try {
|
|
125
|
-
this.
|
|
177
|
+
this.k[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.j) {
|
|
217
|
+
node.j = fn;
|
|
218
|
+
} else if (Array.isArray(node.j)) {
|
|
219
|
+
node.j.push(fn);
|
|
168
220
|
} else {
|
|
169
|
-
node.
|
|
221
|
+
node.j = [node.j, fn];
|
|
170
222
|
}
|
|
171
223
|
return fn;
|
|
172
224
|
}
|
|
@@ -195,40 +247,40 @@ 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
|
+
C;
|
|
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
|
|
205
257
|
// which could enable more efficient DIRTY notification
|
|
206
|
-
|
|
207
|
-
|
|
258
|
+
G = isEqual;
|
|
259
|
+
O;
|
|
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
|
-
|
|
212
|
-
|
|
263
|
+
D = DEFAULT_FLAGS;
|
|
264
|
+
z = null;
|
|
213
265
|
H = null;
|
|
214
266
|
I = -1;
|
|
215
267
|
constructor(initialValue, compute2, options) {
|
|
216
268
|
super(compute2 === null);
|
|
217
|
-
this.
|
|
269
|
+
this.C = compute2;
|
|
218
270
|
this.a = compute2 ? STATE_UNINITIALIZED : STATE_CLEAN;
|
|
219
271
|
this.d = initialValue;
|
|
220
272
|
if (options?.equals !== void 0)
|
|
221
|
-
this.
|
|
273
|
+
this.G = options.equals;
|
|
222
274
|
if (options?.unobserved)
|
|
223
|
-
this.
|
|
275
|
+
this.O = options?.unobserved;
|
|
224
276
|
}
|
|
225
|
-
|
|
226
|
-
if (this.
|
|
277
|
+
P() {
|
|
278
|
+
if (this.C)
|
|
227
279
|
this.s();
|
|
228
|
-
if (!this.
|
|
280
|
+
if (!this.C || 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;
|
|
@@ -239,7 +291,7 @@ var Computation = class extends Owner {
|
|
|
239
291
|
* Automatically re-executes the surrounding computation when the value changes
|
|
240
292
|
*/
|
|
241
293
|
read() {
|
|
242
|
-
return this.
|
|
294
|
+
return this.P();
|
|
243
295
|
}
|
|
244
296
|
/**
|
|
245
297
|
* Return the current value of this computation
|
|
@@ -252,7 +304,7 @@ var Computation = class extends Owner {
|
|
|
252
304
|
if (!syncResolve && this.loading()) {
|
|
253
305
|
throw new NotReadyError();
|
|
254
306
|
}
|
|
255
|
-
return this.
|
|
307
|
+
return this.P();
|
|
256
308
|
}
|
|
257
309
|
/**
|
|
258
310
|
* Return true if the computation is the value is dependent on an unresolved promise
|
|
@@ -272,26 +324,26 @@ var Computation = class extends Owner {
|
|
|
272
324
|
* Triggers re-execution of the computation when the error state changes
|
|
273
325
|
*/
|
|
274
326
|
error() {
|
|
275
|
-
if (this.
|
|
276
|
-
this.
|
|
327
|
+
if (this.z === null) {
|
|
328
|
+
this.z = errorState(this);
|
|
277
329
|
}
|
|
278
|
-
return this.
|
|
330
|
+
return this.z.read();
|
|
279
331
|
}
|
|
280
332
|
/** Update the computation with a new value. */
|
|
281
333
|
write(value, flags = 0, raw = false) {
|
|
282
334
|
const newValue = !raw && typeof value === "function" ? value(this.d) : value;
|
|
283
|
-
const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.a === STATE_UNINITIALIZED || this.
|
|
335
|
+
const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.a === STATE_UNINITIALIZED || this.G === false || !this.G(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].Q(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
|
}
|
|
@@ -316,30 +368,30 @@ var Computation = class extends Owner {
|
|
|
316
368
|
* @param mask A bitmask for which flag(s) were changed.
|
|
317
369
|
* @param newFlags The source's new flags, masked to just the changed ones.
|
|
318
370
|
*/
|
|
319
|
-
|
|
371
|
+
Q(mask, newFlags2) {
|
|
320
372
|
if (this.a >= STATE_DIRTY)
|
|
321
373
|
return;
|
|
322
|
-
if (mask & this.
|
|
374
|
+
if (mask & this.D) {
|
|
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].Q(mask, newFlags2);
|
|
337
389
|
}
|
|
338
390
|
}
|
|
339
391
|
}
|
|
340
392
|
}
|
|
341
|
-
|
|
342
|
-
this.write(error, this.
|
|
393
|
+
J(error) {
|
|
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.D = 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.D = 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,37 +489,37 @@ 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.C, node);
|
|
441
493
|
node.write(result, newFlags, true);
|
|
442
494
|
} catch (error) {
|
|
443
495
|
if (error instanceof NotReadyError) {
|
|
444
496
|
node.write(UNCHANGED, newFlags | LOADING_BIT);
|
|
445
497
|
} else {
|
|
446
|
-
node.
|
|
498
|
+
node.J(error);
|
|
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,14 +530,14 @@ 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.
|
|
488
|
-
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)
|
|
540
|
+
source.O?.();
|
|
489
541
|
}
|
|
490
542
|
}
|
|
491
543
|
}
|
|
@@ -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?.D ?? DEFAULT_FLAGS;
|
|
533
585
|
try {
|
|
534
586
|
return compute2(observer ? observer.d : void 0);
|
|
535
587
|
} finally {
|
|
@@ -545,13 +597,13 @@ function schedule() {
|
|
|
545
597
|
if (scheduled)
|
|
546
598
|
return;
|
|
547
599
|
scheduled = true;
|
|
548
|
-
if (!globalQueue.
|
|
600
|
+
if (!globalQueue.E)
|
|
549
601
|
queueMicrotask(flushSync);
|
|
550
602
|
}
|
|
551
603
|
var Queue = class {
|
|
552
|
-
|
|
604
|
+
E = false;
|
|
553
605
|
u = [[], [], []];
|
|
554
|
-
|
|
606
|
+
A = [];
|
|
555
607
|
enqueue(type, node) {
|
|
556
608
|
this.u[0].push(node);
|
|
557
609
|
if (type)
|
|
@@ -569,14 +621,14 @@ var Queue = class {
|
|
|
569
621
|
runEffectQueue(effects);
|
|
570
622
|
}
|
|
571
623
|
}
|
|
572
|
-
for (let i = 0; i < this.
|
|
573
|
-
this.
|
|
624
|
+
for (let i = 0; i < this.A.length; i++) {
|
|
625
|
+
this.A[i].run(type);
|
|
574
626
|
}
|
|
575
627
|
}
|
|
576
628
|
flush() {
|
|
577
|
-
if (this.
|
|
629
|
+
if (this.E)
|
|
578
630
|
return;
|
|
579
|
-
this.
|
|
631
|
+
this.E = true;
|
|
580
632
|
try {
|
|
581
633
|
this.run(EFFECT_PURE);
|
|
582
634
|
incrementClock();
|
|
@@ -584,24 +636,32 @@ var Queue = class {
|
|
|
584
636
|
this.run(EFFECT_RENDER);
|
|
585
637
|
this.run(EFFECT_USER);
|
|
586
638
|
} finally {
|
|
587
|
-
this.
|
|
639
|
+
this.E = false;
|
|
588
640
|
}
|
|
589
641
|
}
|
|
590
642
|
addChild(child) {
|
|
591
|
-
this.
|
|
643
|
+
this.A.push(child);
|
|
592
644
|
}
|
|
593
645
|
removeChild(child) {
|
|
594
|
-
const index = this.
|
|
646
|
+
const index = this.A.indexOf(child);
|
|
595
647
|
if (index >= 0)
|
|
596
|
-
this.
|
|
648
|
+
this.A.splice(index, 1);
|
|
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;
|
|
@@ -634,52 +694,52 @@ function runEffectQueue(queue) {
|
|
|
634
694
|
|
|
635
695
|
// src/core/effect.ts
|
|
636
696
|
var Effect = class extends Computation {
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
697
|
+
K;
|
|
698
|
+
L = false;
|
|
699
|
+
F;
|
|
700
|
+
B;
|
|
641
701
|
e;
|
|
642
702
|
constructor(initialValue, compute2, effect, options) {
|
|
643
703
|
super(initialValue, compute2, options);
|
|
644
|
-
this.
|
|
645
|
-
this.
|
|
646
|
-
this.
|
|
704
|
+
this.K = effect;
|
|
705
|
+
this.F = initialValue;
|
|
706
|
+
this.B = options?.render ? EFFECT_RENDER : EFFECT_USER;
|
|
647
707
|
this.e = getOwner()?.e || globalQueue;
|
|
648
708
|
this.s();
|
|
649
|
-
this.
|
|
709
|
+
this.B === EFFECT_USER ? this.e.enqueue(this.B, 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.B === 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;
|
|
659
719
|
this.d = value;
|
|
660
|
-
this.
|
|
720
|
+
this.L = true;
|
|
661
721
|
return value;
|
|
662
722
|
}
|
|
663
723
|
t(state) {
|
|
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.B, this);
|
|
668
728
|
this.a = state;
|
|
669
729
|
}
|
|
670
|
-
|
|
730
|
+
J(error) {
|
|
671
731
|
this.handleError(error);
|
|
672
732
|
}
|
|
673
733
|
x() {
|
|
674
|
-
this.
|
|
675
|
-
this.
|
|
734
|
+
this.K = void 0;
|
|
735
|
+
this.F = void 0;
|
|
676
736
|
super.x();
|
|
677
737
|
}
|
|
678
738
|
R() {
|
|
679
|
-
if (this.
|
|
680
|
-
this.
|
|
681
|
-
this.
|
|
682
|
-
this.
|
|
739
|
+
if (this.L && this.a !== STATE_DISPOSED) {
|
|
740
|
+
this.K(this.d, this.F);
|
|
741
|
+
this.F = this.d;
|
|
742
|
+
this.L = false;
|
|
683
743
|
}
|
|
684
744
|
}
|
|
685
745
|
};
|
|
@@ -701,35 +761,48 @@ 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
|
+
M = new Computation(false, null);
|
|
707
767
|
run(type) {
|
|
708
768
|
if (type && this.q)
|
|
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.M.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.M.write(false));
|
|
724
784
|
}
|
|
725
785
|
}
|
|
726
786
|
}
|
|
727
787
|
};
|
|
728
|
-
|
|
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
|
+
};
|
|
798
|
+
function createSuspense(fn, fallback) {
|
|
729
799
|
const queue = new SuspenseQueue();
|
|
730
|
-
const tree = createBoundary(
|
|
731
|
-
|
|
732
|
-
|
|
800
|
+
const tree = createBoundary(() => {
|
|
801
|
+
const child = new Computation(null, fn);
|
|
802
|
+
return new LiveComputation(null, () => flatten(child.wait()));
|
|
803
|
+
}, queue);
|
|
804
|
+
const equality = new Computation(null, () => queue.M.read() || queue.q);
|
|
805
|
+
const comp = new Computation(null, () => equality.read() ? fallback() : 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);
|
|
@@ -845,14 +918,36 @@ function runWithOwner(owner, run) {
|
|
|
845
918
|
return void 0;
|
|
846
919
|
}
|
|
847
920
|
}
|
|
848
|
-
function
|
|
921
|
+
function createErrorBoundary(fn, fallback) {
|
|
849
922
|
const owner = new Owner();
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
923
|
+
const error = new Computation(null, null);
|
|
924
|
+
const reset = new Computation(null, null, { equals: false });
|
|
925
|
+
const handler = (err) => error.write({ z: err });
|
|
926
|
+
owner.k = owner.k ? [handler, ...owner.k] : [handler];
|
|
927
|
+
const guarded = compute(
|
|
928
|
+
owner,
|
|
929
|
+
() => {
|
|
930
|
+
const c = new Computation(null, () => (reset.read(), fn()));
|
|
931
|
+
const f = new Computation(null, () => flatten(c.read()));
|
|
932
|
+
f.J = function(error2) {
|
|
933
|
+
this.handleError(error2);
|
|
934
|
+
};
|
|
935
|
+
return f;
|
|
936
|
+
},
|
|
937
|
+
null
|
|
938
|
+
);
|
|
939
|
+
const decision = new Computation(null, () => {
|
|
940
|
+
if (!error.read()) {
|
|
941
|
+
const resolved = guarded.read();
|
|
942
|
+
if (!error.read())
|
|
943
|
+
return resolved;
|
|
944
|
+
}
|
|
945
|
+
return fallback(error.read().z, () => {
|
|
946
|
+
error.write(null);
|
|
947
|
+
reset.write(null);
|
|
948
|
+
});
|
|
949
|
+
});
|
|
950
|
+
return decision.read.bind(decision);
|
|
856
951
|
}
|
|
857
952
|
|
|
858
953
|
// src/store/store.ts
|
|
@@ -1314,75 +1409,75 @@ function omit(props, ...keys) {
|
|
|
1314
1409
|
function mapArray(list, map, options) {
|
|
1315
1410
|
const keyFn = typeof options?.keyed === "function" ? options.keyed : void 0;
|
|
1316
1411
|
return updateKeyedMap.bind({
|
|
1317
|
-
|
|
1412
|
+
T: new Owner(),
|
|
1318
1413
|
w: 0,
|
|
1319
1414
|
U: list,
|
|
1320
1415
|
r: [],
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1416
|
+
N: map,
|
|
1417
|
+
l: [],
|
|
1418
|
+
g: [],
|
|
1324
1419
|
y: keyFn,
|
|
1325
|
-
|
|
1326
|
-
|
|
1420
|
+
h: keyFn || options?.keyed === false ? [] : void 0,
|
|
1421
|
+
i: map.length > 1 ? [] : void 0,
|
|
1327
1422
|
q: options?.fallback
|
|
1328
1423
|
});
|
|
1329
1424
|
}
|
|
1330
1425
|
function updateKeyedMap() {
|
|
1331
1426
|
const newItems = this.U() || [], newLen = newItems.length;
|
|
1332
1427
|
newItems[$TRACK];
|
|
1333
|
-
runWithOwner(this.
|
|
1334
|
-
let i, j, mapper = this.
|
|
1335
|
-
this.
|
|
1336
|
-
this.
|
|
1337
|
-
return this.
|
|
1338
|
-
Computation.prototype.read.bind(this.
|
|
1339
|
-
Computation.prototype.read.bind(this.
|
|
1428
|
+
runWithOwner(this.T, () => {
|
|
1429
|
+
let i, j, mapper = this.h ? () => {
|
|
1430
|
+
this.h[j] = new Computation(newItems[j], null);
|
|
1431
|
+
this.i && (this.i[j] = new Computation(j, null));
|
|
1432
|
+
return this.N(
|
|
1433
|
+
Computation.prototype.read.bind(this.h[j]),
|
|
1434
|
+
this.i ? Computation.prototype.read.bind(this.i[j]) : void 0
|
|
1340
1435
|
);
|
|
1341
|
-
} : this.
|
|
1436
|
+
} : this.i ? () => {
|
|
1342
1437
|
const item = newItems[j];
|
|
1343
|
-
this.
|
|
1344
|
-
return this.
|
|
1438
|
+
this.i[j] = new Computation(j, null);
|
|
1439
|
+
return this.N(() => item, Computation.prototype.read.bind(this.i[j]));
|
|
1345
1440
|
} : () => {
|
|
1346
1441
|
const item = newItems[j];
|
|
1347
|
-
return this.
|
|
1442
|
+
return this.N(() => item);
|
|
1348
1443
|
};
|
|
1349
1444
|
if (newLen === 0) {
|
|
1350
1445
|
if (this.w !== 0) {
|
|
1351
|
-
this.
|
|
1352
|
-
this.
|
|
1446
|
+
this.T.dispose(false);
|
|
1447
|
+
this.g = [];
|
|
1353
1448
|
this.r = [];
|
|
1354
|
-
this.
|
|
1449
|
+
this.l = [];
|
|
1355
1450
|
this.w = 0;
|
|
1356
|
-
this.
|
|
1357
|
-
this.
|
|
1451
|
+
this.h && (this.h = []);
|
|
1452
|
+
this.i && (this.i = []);
|
|
1358
1453
|
}
|
|
1359
|
-
if (this.q && !this.
|
|
1360
|
-
this.
|
|
1361
|
-
this.
|
|
1454
|
+
if (this.q && !this.l[0]) {
|
|
1455
|
+
this.l[0] = compute(
|
|
1456
|
+
this.g[0] = new Owner(),
|
|
1362
1457
|
this.q,
|
|
1363
1458
|
null
|
|
1364
1459
|
);
|
|
1365
1460
|
}
|
|
1366
1461
|
} else if (this.w === 0) {
|
|
1367
|
-
if (this.
|
|
1368
|
-
this.
|
|
1369
|
-
this.
|
|
1462
|
+
if (this.g[0])
|
|
1463
|
+
this.g[0].dispose();
|
|
1464
|
+
this.l = new Array(newLen);
|
|
1370
1465
|
for (j = 0; j < newLen; j++) {
|
|
1371
1466
|
this.r[j] = newItems[j];
|
|
1372
|
-
this.
|
|
1467
|
+
this.l[j] = compute(this.g[j] = new Owner(), mapper, null);
|
|
1373
1468
|
}
|
|
1374
1469
|
this.w = newLen;
|
|
1375
1470
|
} 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.
|
|
1471
|
+
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.i ? new Array(newLen) : void 0;
|
|
1472
|
+
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++) {
|
|
1473
|
+
if (this.h)
|
|
1474
|
+
this.h[start].write(newItems[start]);
|
|
1380
1475
|
}
|
|
1381
|
-
for (end = this.w - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.r[end] === newItems[newEnd] || this.
|
|
1382
|
-
temp[newEnd] = this.
|
|
1383
|
-
tempNodes[newEnd] = this.
|
|
1384
|
-
tempRows && (tempRows[newEnd] = this.
|
|
1385
|
-
tempIndexes && (tempIndexes[newEnd] = this.
|
|
1476
|
+
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--) {
|
|
1477
|
+
temp[newEnd] = this.l[end];
|
|
1478
|
+
tempNodes[newEnd] = this.g[end];
|
|
1479
|
+
tempRows && (tempRows[newEnd] = this.h[end]);
|
|
1480
|
+
tempIndexes && (tempIndexes[newEnd] = this.i[end]);
|
|
1386
1481
|
}
|
|
1387
1482
|
newIndices = /* @__PURE__ */ new Map();
|
|
1388
1483
|
newIndicesNext = new Array(newEnd + 1);
|
|
@@ -1398,39 +1493,39 @@ function updateKeyedMap() {
|
|
|
1398
1493
|
key = this.y ? this.y(item) : item;
|
|
1399
1494
|
j = newIndices.get(key);
|
|
1400
1495
|
if (j !== void 0 && j !== -1) {
|
|
1401
|
-
temp[j] = this.
|
|
1402
|
-
tempNodes[j] = this.
|
|
1403
|
-
tempRows && (tempRows[j] = this.
|
|
1404
|
-
tempIndexes && (tempIndexes[j] = this.
|
|
1496
|
+
temp[j] = this.l[i];
|
|
1497
|
+
tempNodes[j] = this.g[i];
|
|
1498
|
+
tempRows && (tempRows[j] = this.h[i]);
|
|
1499
|
+
tempIndexes && (tempIndexes[j] = this.i[i]);
|
|
1405
1500
|
j = newIndicesNext[j];
|
|
1406
1501
|
newIndices.set(key, j);
|
|
1407
1502
|
} else
|
|
1408
|
-
this.
|
|
1503
|
+
this.g[i].dispose();
|
|
1409
1504
|
}
|
|
1410
1505
|
for (j = start; j < newLen; j++) {
|
|
1411
1506
|
if (j in temp) {
|
|
1412
|
-
this.
|
|
1413
|
-
this.
|
|
1507
|
+
this.l[j] = temp[j];
|
|
1508
|
+
this.g[j] = tempNodes[j];
|
|
1414
1509
|
if (tempRows) {
|
|
1415
|
-
this.
|
|
1416
|
-
this.
|
|
1510
|
+
this.h[j] = tempRows[j];
|
|
1511
|
+
this.h[j].write(newItems[j]);
|
|
1417
1512
|
}
|
|
1418
1513
|
if (tempIndexes) {
|
|
1419
|
-
this.
|
|
1420
|
-
this.
|
|
1514
|
+
this.i[j] = tempIndexes[j];
|
|
1515
|
+
this.i[j].write(j);
|
|
1421
1516
|
}
|
|
1422
1517
|
} else {
|
|
1423
|
-
this.
|
|
1518
|
+
this.l[j] = compute(this.g[j] = new Owner(), mapper, null);
|
|
1424
1519
|
}
|
|
1425
1520
|
}
|
|
1426
|
-
this.
|
|
1521
|
+
this.l = this.l.slice(0, this.w = newLen);
|
|
1427
1522
|
this.r = newItems.slice(0);
|
|
1428
1523
|
}
|
|
1429
1524
|
});
|
|
1430
|
-
return this.
|
|
1525
|
+
return this.l;
|
|
1431
1526
|
}
|
|
1432
1527
|
function compare(key, a, b) {
|
|
1433
1528
|
return key ? key(a) === key(b) : true;
|
|
1434
1529
|
}
|
|
1435
1530
|
|
|
1436
|
-
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY,
|
|
1531
|
+
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, 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 };
|