@solidjs/signals 0.2.3 → 0.2.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 +118 -34
- package/dist/node.cjs +374 -287
- package/dist/prod.js +371 -287
- package/dist/types/map.d.ts +1 -0
- package/dist/types/store/index.d.ts +1 -1
- package/dist/types/store/projection.d.ts +3 -1
- package/dist/types/store/store.d.ts +1 -0
- package/package.json +1 -1
package/dist/node.cjs
CHANGED
|
@@ -45,42 +45,42 @@ function schedule() {
|
|
|
45
45
|
if (scheduled)
|
|
46
46
|
return;
|
|
47
47
|
scheduled = true;
|
|
48
|
-
if (!globalQueue.
|
|
48
|
+
if (!globalQueue.J)
|
|
49
49
|
queueMicrotask(flushSync);
|
|
50
50
|
}
|
|
51
51
|
var Queue = class {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
J = false;
|
|
53
|
+
s = [[], [], []];
|
|
54
|
+
F = [];
|
|
55
55
|
created = clock;
|
|
56
56
|
enqueue(type, node) {
|
|
57
|
-
this.
|
|
57
|
+
this.s[0].push(node);
|
|
58
58
|
if (type)
|
|
59
|
-
this.
|
|
59
|
+
this.s[type].push(node);
|
|
60
60
|
schedule();
|
|
61
61
|
}
|
|
62
62
|
run(type) {
|
|
63
|
-
if (this.
|
|
63
|
+
if (this.s[type].length) {
|
|
64
64
|
if (type === EFFECT_PURE) {
|
|
65
|
-
runPureQueue(this.
|
|
66
|
-
this.
|
|
65
|
+
runPureQueue(this.s[type]);
|
|
66
|
+
this.s[type] = [];
|
|
67
67
|
} else {
|
|
68
|
-
const effects = this.
|
|
69
|
-
this.
|
|
68
|
+
const effects = this.s[type];
|
|
69
|
+
this.s[type] = [];
|
|
70
70
|
runEffectQueue(effects);
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
let rerun = false;
|
|
74
|
-
for (let i = 0; i < this.
|
|
75
|
-
rerun = this.
|
|
74
|
+
for (let i = 0; i < this.F.length; i++) {
|
|
75
|
+
rerun = this.F[i].run(type) || rerun;
|
|
76
76
|
}
|
|
77
|
-
if (type === EFFECT_PURE && this.
|
|
77
|
+
if (type === EFFECT_PURE && this.s[type].length)
|
|
78
78
|
return true;
|
|
79
79
|
}
|
|
80
80
|
flush() {
|
|
81
|
-
if (this.
|
|
81
|
+
if (this.J)
|
|
82
82
|
return;
|
|
83
|
-
this.
|
|
83
|
+
this.J = true;
|
|
84
84
|
try {
|
|
85
85
|
while (this.run(EFFECT_PURE)) {
|
|
86
86
|
}
|
|
@@ -89,16 +89,16 @@ var Queue = class {
|
|
|
89
89
|
this.run(EFFECT_RENDER);
|
|
90
90
|
this.run(EFFECT_USER);
|
|
91
91
|
} finally {
|
|
92
|
-
this.
|
|
92
|
+
this.J = false;
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
addChild(child) {
|
|
96
|
-
this.
|
|
96
|
+
this.F.push(child);
|
|
97
97
|
}
|
|
98
98
|
removeChild(child) {
|
|
99
|
-
const index = this.
|
|
99
|
+
const index = this.F.indexOf(child);
|
|
100
100
|
if (index >= 0)
|
|
101
|
-
this.
|
|
101
|
+
this.F.splice(index, 1);
|
|
102
102
|
}
|
|
103
103
|
};
|
|
104
104
|
var globalQueue = new Queue();
|
|
@@ -109,14 +109,14 @@ function flushSync() {
|
|
|
109
109
|
}
|
|
110
110
|
function runTop(node) {
|
|
111
111
|
const ancestors = [];
|
|
112
|
-
for (let current = node; current !== null; current = current.
|
|
112
|
+
for (let current = node; current !== null; current = current.t) {
|
|
113
113
|
if (current.a !== STATE_CLEAN) {
|
|
114
114
|
ancestors.push(current);
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
118
118
|
if (ancestors[i].a !== STATE_DISPOSED)
|
|
119
|
-
ancestors[i].
|
|
119
|
+
ancestors[i].z();
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
function runPureQueue(queue) {
|
|
@@ -127,7 +127,7 @@ function runPureQueue(queue) {
|
|
|
127
127
|
}
|
|
128
128
|
function runEffectQueue(queue) {
|
|
129
129
|
for (let i = 0; i < queue.length; i++)
|
|
130
|
-
queue[i].
|
|
130
|
+
queue[i].U();
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
// src/core/utils.ts
|
|
@@ -150,9 +150,9 @@ var Owner = class {
|
|
|
150
150
|
// We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
|
|
151
151
|
// However, the children are actually added in reverse creation order
|
|
152
152
|
// See comment at the top of the file for an example of the _nextSibling traversal
|
|
153
|
-
s = null;
|
|
154
|
-
n = null;
|
|
155
153
|
t = null;
|
|
154
|
+
n = null;
|
|
155
|
+
u = null;
|
|
156
156
|
a = STATE_CLEAN;
|
|
157
157
|
l = null;
|
|
158
158
|
p = defaultContext;
|
|
@@ -163,10 +163,10 @@ var Owner = class {
|
|
|
163
163
|
currentOwner.append(this);
|
|
164
164
|
}
|
|
165
165
|
append(child) {
|
|
166
|
-
child.s = this;
|
|
167
166
|
child.t = this;
|
|
167
|
+
child.u = this;
|
|
168
168
|
if (this.n)
|
|
169
|
-
this.n.
|
|
169
|
+
this.n.u = child;
|
|
170
170
|
child.n = this.n;
|
|
171
171
|
this.n = child;
|
|
172
172
|
if (child.p !== this.p) {
|
|
@@ -181,26 +181,26 @@ var Owner = class {
|
|
|
181
181
|
dispose(self = true) {
|
|
182
182
|
if (this.a === STATE_DISPOSED)
|
|
183
183
|
return;
|
|
184
|
-
let head = self ? this.
|
|
185
|
-
while (current && current.
|
|
184
|
+
let head = self ? this.u || this.t : this, current = this.n, next = null;
|
|
185
|
+
while (current && current.t === this) {
|
|
186
186
|
current.dispose(true);
|
|
187
|
-
current.
|
|
187
|
+
current.A();
|
|
188
188
|
next = current.n;
|
|
189
189
|
current.n = null;
|
|
190
190
|
current = next;
|
|
191
191
|
}
|
|
192
192
|
if (self)
|
|
193
|
-
this.
|
|
193
|
+
this.A();
|
|
194
194
|
if (current)
|
|
195
|
-
current.
|
|
195
|
+
current.u = !self ? this : this.u;
|
|
196
196
|
if (head)
|
|
197
197
|
head.n = current;
|
|
198
198
|
}
|
|
199
|
-
|
|
200
|
-
if (this.
|
|
201
|
-
this.
|
|
202
|
-
this.s = null;
|
|
199
|
+
A() {
|
|
200
|
+
if (this.u)
|
|
201
|
+
this.u.n = null;
|
|
203
202
|
this.t = null;
|
|
203
|
+
this.u = null;
|
|
204
204
|
this.p = defaultContext;
|
|
205
205
|
this.m = null;
|
|
206
206
|
this.a = STATE_DISPOSED;
|
|
@@ -298,49 +298,49 @@ function getObserver() {
|
|
|
298
298
|
var UNCHANGED = Symbol(0);
|
|
299
299
|
var Computation = class extends Owner {
|
|
300
300
|
b = null;
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
301
|
+
e = null;
|
|
302
|
+
g;
|
|
303
|
+
G;
|
|
304
|
+
B;
|
|
305
305
|
// Used in __DEV__ mode, hopefully removed in production
|
|
306
|
-
|
|
306
|
+
$;
|
|
307
307
|
// Using false is an optimization as an alternative to _equals: () => false
|
|
308
308
|
// which could enable more efficient DIRTY notification
|
|
309
|
-
|
|
310
|
-
|
|
309
|
+
O = isEqual;
|
|
310
|
+
V;
|
|
311
311
|
/** Whether the computation is an error or has ancestors that are unresolved */
|
|
312
|
-
|
|
312
|
+
f = 0;
|
|
313
313
|
/** Which flags raised by sources are handled, vs. being passed through. */
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
314
|
+
P = DEFAULT_FLAGS;
|
|
315
|
+
Q = null;
|
|
316
|
+
y = -1;
|
|
317
|
+
K = false;
|
|
318
318
|
constructor(initialValue, compute2, options) {
|
|
319
319
|
super(compute2 === null);
|
|
320
|
-
this.
|
|
320
|
+
this.B = compute2;
|
|
321
321
|
this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
|
|
322
|
-
this.
|
|
323
|
-
this.
|
|
322
|
+
this.f = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
|
|
323
|
+
this.g = initialValue;
|
|
324
324
|
if ((options == null ? void 0 : options.equals) !== void 0)
|
|
325
|
-
this.
|
|
325
|
+
this.O = options.equals;
|
|
326
326
|
if (options == null ? void 0 : options.unobserved)
|
|
327
|
-
this.
|
|
327
|
+
this.V = options == null ? void 0 : options.unobserved;
|
|
328
328
|
}
|
|
329
|
-
|
|
329
|
+
W() {
|
|
330
330
|
var _a;
|
|
331
|
-
if (this.
|
|
332
|
-
if (this.
|
|
331
|
+
if (this.B) {
|
|
332
|
+
if (this.f & ERROR_BIT && this.y <= getClock())
|
|
333
333
|
update(this);
|
|
334
334
|
else
|
|
335
|
-
this.
|
|
335
|
+
this.z();
|
|
336
336
|
}
|
|
337
|
-
if (!this.
|
|
337
|
+
if (!this.B || ((_a = this.b) == null ? void 0 : _a.length))
|
|
338
338
|
track(this);
|
|
339
|
-
newFlags |= this.
|
|
340
|
-
if (this.
|
|
341
|
-
throw this.
|
|
339
|
+
newFlags |= this.f & ~currentMask;
|
|
340
|
+
if (this.f & ERROR_BIT) {
|
|
341
|
+
throw this.G;
|
|
342
342
|
} else {
|
|
343
|
-
return this.
|
|
343
|
+
return this.g;
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
346
|
/**
|
|
@@ -348,7 +348,7 @@ var Computation = class extends Owner {
|
|
|
348
348
|
* Automatically re-executes the surrounding computation when the value changes
|
|
349
349
|
*/
|
|
350
350
|
read() {
|
|
351
|
-
return this.
|
|
351
|
+
return this.W();
|
|
352
352
|
}
|
|
353
353
|
/**
|
|
354
354
|
* Return the current value of this computation
|
|
@@ -358,15 +358,15 @@ var Computation = class extends Owner {
|
|
|
358
358
|
* before continuing
|
|
359
359
|
*/
|
|
360
360
|
wait() {
|
|
361
|
-
if (this.
|
|
361
|
+
if (this.B && this.f & ERROR_BIT && this.y <= getClock()) {
|
|
362
362
|
update(this);
|
|
363
363
|
}
|
|
364
|
-
if ((notStale || this.
|
|
364
|
+
if ((notStale || this.f & UNINITIALIZED_BIT) && this.loading()) {
|
|
365
365
|
throw new NotReadyError();
|
|
366
366
|
}
|
|
367
367
|
if (staleCheck && this.loading())
|
|
368
|
-
staleCheck.
|
|
369
|
-
return this.
|
|
368
|
+
staleCheck.g = true;
|
|
369
|
+
return this.W();
|
|
370
370
|
}
|
|
371
371
|
/**
|
|
372
372
|
* Return true if the computation is the value is dependent on an unresolved promise
|
|
@@ -376,44 +376,44 @@ var Computation = class extends Owner {
|
|
|
376
376
|
* loading state changes
|
|
377
377
|
*/
|
|
378
378
|
loading() {
|
|
379
|
-
if (this.
|
|
380
|
-
this.
|
|
379
|
+
if (this.Q === null) {
|
|
380
|
+
this.Q = loadingState(this);
|
|
381
381
|
}
|
|
382
|
-
return this.
|
|
382
|
+
return this.Q.read();
|
|
383
383
|
}
|
|
384
384
|
/** Update the computation with a new value. */
|
|
385
385
|
write(value, flags = 0, raw = false) {
|
|
386
|
-
const newValue = !raw && typeof value === "function" ? value(this.
|
|
387
|
-
const valueChanged = newValue !== UNCHANGED && (!!(this.
|
|
386
|
+
const newValue = !raw && typeof value === "function" ? value(this.g) : value;
|
|
387
|
+
const valueChanged = newValue !== UNCHANGED && (!!(this.f & UNINITIALIZED_BIT) || this.O === false || !this.O(this.g, newValue));
|
|
388
388
|
if (valueChanged) {
|
|
389
|
-
this.
|
|
390
|
-
this.
|
|
391
|
-
}
|
|
392
|
-
const changedFlagsMask = this.
|
|
393
|
-
this.
|
|
394
|
-
this.
|
|
395
|
-
if (this.
|
|
396
|
-
for (let i = 0; i < this.
|
|
389
|
+
this.g = newValue;
|
|
390
|
+
this.G = void 0;
|
|
391
|
+
}
|
|
392
|
+
const changedFlagsMask = this.f ^ flags, changedFlags = changedFlagsMask & flags;
|
|
393
|
+
this.f = flags;
|
|
394
|
+
this.y = getClock() + 1;
|
|
395
|
+
if (this.e) {
|
|
396
|
+
for (let i = 0; i < this.e.length; i++) {
|
|
397
397
|
if (valueChanged) {
|
|
398
|
-
this.
|
|
398
|
+
this.e[i].q(STATE_DIRTY);
|
|
399
399
|
} else if (changedFlagsMask) {
|
|
400
|
-
this.
|
|
400
|
+
this.e[i].X(changedFlagsMask, changedFlags);
|
|
401
401
|
}
|
|
402
402
|
}
|
|
403
403
|
}
|
|
404
|
-
return this.
|
|
404
|
+
return this.g;
|
|
405
405
|
}
|
|
406
406
|
/**
|
|
407
407
|
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
|
408
408
|
*/
|
|
409
409
|
q(state, skipQueue) {
|
|
410
|
-
if (this.a >= state && !this.
|
|
410
|
+
if (this.a >= state && !this.K)
|
|
411
411
|
return;
|
|
412
|
-
this.
|
|
412
|
+
this.K = !!skipQueue;
|
|
413
413
|
this.a = state;
|
|
414
|
-
if (this.
|
|
415
|
-
for (let i = 0; i < this.
|
|
416
|
-
this.
|
|
414
|
+
if (this.e) {
|
|
415
|
+
for (let i = 0; i < this.e.length; i++) {
|
|
416
|
+
this.e[i].q(STATE_CHECK, skipQueue);
|
|
417
417
|
}
|
|
418
418
|
}
|
|
419
419
|
}
|
|
@@ -423,31 +423,31 @@ var Computation = class extends Owner {
|
|
|
423
423
|
* @param mask A bitmask for which flag(s) were changed.
|
|
424
424
|
* @param newFlags The source's new flags, masked to just the changed ones.
|
|
425
425
|
*/
|
|
426
|
-
|
|
426
|
+
X(mask, newFlags2) {
|
|
427
427
|
if (this.a >= STATE_DIRTY)
|
|
428
428
|
return;
|
|
429
|
-
if (mask & this.
|
|
429
|
+
if (mask & this.P) {
|
|
430
430
|
this.q(STATE_DIRTY);
|
|
431
431
|
return;
|
|
432
432
|
}
|
|
433
433
|
if (this.a >= STATE_CHECK)
|
|
434
434
|
return;
|
|
435
|
-
const prevFlags = this.
|
|
435
|
+
const prevFlags = this.f & mask;
|
|
436
436
|
const deltaFlags = prevFlags ^ newFlags2;
|
|
437
437
|
if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
|
|
438
438
|
this.q(STATE_CHECK);
|
|
439
439
|
} else {
|
|
440
|
-
this.
|
|
441
|
-
if (this.
|
|
442
|
-
for (let i = 0; i < this.
|
|
443
|
-
this.
|
|
440
|
+
this.f ^= deltaFlags;
|
|
441
|
+
if (this.e) {
|
|
442
|
+
for (let i = 0; i < this.e.length; i++) {
|
|
443
|
+
this.e[i].X(mask, newFlags2);
|
|
444
444
|
}
|
|
445
445
|
}
|
|
446
446
|
}
|
|
447
447
|
}
|
|
448
|
-
|
|
449
|
-
this.
|
|
450
|
-
this.write(UNCHANGED, this.
|
|
448
|
+
H(error) {
|
|
449
|
+
this.G = error;
|
|
450
|
+
this.write(UNCHANGED, this.f & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
|
|
451
451
|
}
|
|
452
452
|
/**
|
|
453
453
|
* This is the core part of the reactivity system, which makes sure that the values are updated
|
|
@@ -456,7 +456,7 @@ var Computation = class extends Owner {
|
|
|
456
456
|
*
|
|
457
457
|
* This function will ensure that the value and states we read from the computation are up to date
|
|
458
458
|
*/
|
|
459
|
-
|
|
459
|
+
z() {
|
|
460
460
|
if (this.a === STATE_DISPOSED) {
|
|
461
461
|
throw new Error("Tried to read a disposed computation");
|
|
462
462
|
}
|
|
@@ -466,8 +466,8 @@ var Computation = class extends Owner {
|
|
|
466
466
|
let observerFlags = 0;
|
|
467
467
|
if (this.a === STATE_CHECK) {
|
|
468
468
|
for (let i = 0; i < this.b.length; i++) {
|
|
469
|
-
this.b[i].
|
|
470
|
-
observerFlags |= this.b[i].
|
|
469
|
+
this.b[i].z();
|
|
470
|
+
observerFlags |= this.b[i].f;
|
|
471
471
|
if (this.a === STATE_DIRTY) {
|
|
472
472
|
break;
|
|
473
473
|
}
|
|
@@ -483,27 +483,27 @@ var Computation = class extends Owner {
|
|
|
483
483
|
/**
|
|
484
484
|
* Remove ourselves from the owner graph and the computation graph
|
|
485
485
|
*/
|
|
486
|
-
|
|
486
|
+
A() {
|
|
487
487
|
if (this.a === STATE_DISPOSED)
|
|
488
488
|
return;
|
|
489
489
|
if (this.b)
|
|
490
490
|
removeSourceObservers(this, 0);
|
|
491
|
-
super.
|
|
491
|
+
super.A();
|
|
492
492
|
}
|
|
493
493
|
};
|
|
494
494
|
function loadingState(node) {
|
|
495
|
-
const prevOwner = setOwner(node.
|
|
495
|
+
const prevOwner = setOwner(node.t);
|
|
496
496
|
const options = void 0;
|
|
497
497
|
const computation = new Computation(
|
|
498
498
|
void 0,
|
|
499
499
|
() => {
|
|
500
500
|
track(node);
|
|
501
|
-
node.
|
|
502
|
-
return !!(node.
|
|
501
|
+
node.z();
|
|
502
|
+
return !!(node.f & LOADING_BIT);
|
|
503
503
|
},
|
|
504
504
|
options
|
|
505
505
|
);
|
|
506
|
-
computation.
|
|
506
|
+
computation.P = ERROR_BIT | LOADING_BIT;
|
|
507
507
|
setOwner(prevOwner);
|
|
508
508
|
return computation;
|
|
509
509
|
}
|
|
@@ -517,7 +517,7 @@ function track(computation) {
|
|
|
517
517
|
newSources.push(computation);
|
|
518
518
|
}
|
|
519
519
|
if (updateCheck) {
|
|
520
|
-
updateCheck.
|
|
520
|
+
updateCheck.g = computation.y > currentObserver.y;
|
|
521
521
|
}
|
|
522
522
|
}
|
|
523
523
|
}
|
|
@@ -529,13 +529,13 @@ function update(node) {
|
|
|
529
529
|
try {
|
|
530
530
|
node.dispose(false);
|
|
531
531
|
node.emptyDisposal();
|
|
532
|
-
const result = compute(node, node.
|
|
532
|
+
const result = compute(node, node.B, node);
|
|
533
533
|
node.write(result, newFlags, true);
|
|
534
534
|
} catch (error) {
|
|
535
535
|
if (error instanceof NotReadyError) {
|
|
536
|
-
node.write(UNCHANGED, newFlags | LOADING_BIT | node.
|
|
536
|
+
node.write(UNCHANGED, newFlags | LOADING_BIT | node.f & UNINITIALIZED_BIT);
|
|
537
537
|
} else {
|
|
538
|
-
node.
|
|
538
|
+
node.H(error);
|
|
539
539
|
}
|
|
540
540
|
} finally {
|
|
541
541
|
if (newSources) {
|
|
@@ -552,10 +552,10 @@ function update(node) {
|
|
|
552
552
|
let source;
|
|
553
553
|
for (let i = newSourcesIndex; i < node.b.length; i++) {
|
|
554
554
|
source = node.b[i];
|
|
555
|
-
if (!source.
|
|
556
|
-
source.
|
|
555
|
+
if (!source.e)
|
|
556
|
+
source.e = [node];
|
|
557
557
|
else
|
|
558
|
-
source.
|
|
558
|
+
source.e.push(node);
|
|
559
559
|
}
|
|
560
560
|
} else if (node.b && newSourcesIndex < node.b.length) {
|
|
561
561
|
removeSourceObservers(node, newSourcesIndex);
|
|
@@ -564,7 +564,7 @@ function update(node) {
|
|
|
564
564
|
newSources = prevSources;
|
|
565
565
|
newSourcesIndex = prevSourcesIndex;
|
|
566
566
|
newFlags = prevFlags;
|
|
567
|
-
node.
|
|
567
|
+
node.y = getClock() + 1;
|
|
568
568
|
node.a = STATE_CLEAN;
|
|
569
569
|
}
|
|
570
570
|
}
|
|
@@ -574,12 +574,12 @@ function removeSourceObservers(node, index) {
|
|
|
574
574
|
let swap;
|
|
575
575
|
for (let i = index; i < node.b.length; i++) {
|
|
576
576
|
source = node.b[i];
|
|
577
|
-
if (source.
|
|
578
|
-
swap = source.
|
|
579
|
-
source.
|
|
580
|
-
source.
|
|
581
|
-
if (!source.
|
|
582
|
-
(_a = source.
|
|
577
|
+
if (source.e) {
|
|
578
|
+
swap = source.e.indexOf(node);
|
|
579
|
+
source.e[swap] = source.e[source.e.length - 1];
|
|
580
|
+
source.e.pop();
|
|
581
|
+
if (!source.e.length)
|
|
582
|
+
(_a = source.V) == null ? void 0 : _a.call(source);
|
|
583
583
|
}
|
|
584
584
|
}
|
|
585
585
|
}
|
|
@@ -593,10 +593,10 @@ function untrack(fn) {
|
|
|
593
593
|
}
|
|
594
594
|
function hasUpdated(fn) {
|
|
595
595
|
const current = updateCheck;
|
|
596
|
-
updateCheck = {
|
|
596
|
+
updateCheck = { g: false };
|
|
597
597
|
try {
|
|
598
598
|
fn();
|
|
599
|
-
return updateCheck.
|
|
599
|
+
return updateCheck.g;
|
|
600
600
|
} finally {
|
|
601
601
|
updateCheck = current;
|
|
602
602
|
}
|
|
@@ -604,10 +604,10 @@ function hasUpdated(fn) {
|
|
|
604
604
|
function isPending(fn, loadingValue) {
|
|
605
605
|
const argLength = arguments.length;
|
|
606
606
|
const current = staleCheck;
|
|
607
|
-
staleCheck = {
|
|
607
|
+
staleCheck = { g: false };
|
|
608
608
|
try {
|
|
609
609
|
latest(fn);
|
|
610
|
-
return staleCheck.
|
|
610
|
+
return staleCheck.g;
|
|
611
611
|
} catch (err) {
|
|
612
612
|
if (!(err instanceof NotReadyError))
|
|
613
613
|
return false;
|
|
@@ -654,10 +654,10 @@ function runWithObserver(observer, run) {
|
|
|
654
654
|
if (error instanceof NotReadyError) {
|
|
655
655
|
observer.write(
|
|
656
656
|
UNCHANGED,
|
|
657
|
-
newFlags | LOADING_BIT | observer.
|
|
657
|
+
newFlags | LOADING_BIT | observer.f & UNINITIALIZED_BIT
|
|
658
658
|
);
|
|
659
659
|
} else {
|
|
660
|
-
observer.
|
|
660
|
+
observer.H(error);
|
|
661
661
|
}
|
|
662
662
|
} finally {
|
|
663
663
|
if (newSources) {
|
|
@@ -672,10 +672,10 @@ function runWithObserver(observer, run) {
|
|
|
672
672
|
let source;
|
|
673
673
|
for (let i = newSourcesIndex; i < observer.b.length; i++) {
|
|
674
674
|
source = observer.b[i];
|
|
675
|
-
if (!source.
|
|
676
|
-
source.
|
|
675
|
+
if (!source.e)
|
|
676
|
+
source.e = [observer];
|
|
677
677
|
else
|
|
678
|
-
source.
|
|
678
|
+
source.e.push(observer);
|
|
679
679
|
}
|
|
680
680
|
}
|
|
681
681
|
newSources = prevSources;
|
|
@@ -686,10 +686,10 @@ function runWithObserver(observer, run) {
|
|
|
686
686
|
function compute(owner, fn, observer) {
|
|
687
687
|
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask, prevNotStale = notStale;
|
|
688
688
|
currentObserver = observer;
|
|
689
|
-
currentMask = (observer == null ? void 0 : observer.
|
|
689
|
+
currentMask = (observer == null ? void 0 : observer.P) ?? DEFAULT_FLAGS;
|
|
690
690
|
notStale = true;
|
|
691
691
|
try {
|
|
692
|
-
return fn(observer ? observer.
|
|
692
|
+
return fn(observer ? observer.g : void 0);
|
|
693
693
|
} finally {
|
|
694
694
|
setOwner(prevOwner);
|
|
695
695
|
currentObserver = prevObserver;
|
|
@@ -769,84 +769,84 @@ function createBoundary(fn, queue) {
|
|
|
769
769
|
|
|
770
770
|
// src/core/effect.ts
|
|
771
771
|
var Effect = class extends Computation {
|
|
772
|
-
K;
|
|
773
772
|
L;
|
|
774
|
-
B;
|
|
775
|
-
Q = false;
|
|
776
773
|
M;
|
|
777
|
-
|
|
774
|
+
C;
|
|
775
|
+
R = false;
|
|
776
|
+
N;
|
|
777
|
+
w;
|
|
778
778
|
constructor(initialValue, compute2, effect, error, options) {
|
|
779
779
|
super(initialValue, compute2, options);
|
|
780
|
-
this.
|
|
781
|
-
this.
|
|
782
|
-
this.
|
|
783
|
-
this.
|
|
784
|
-
if (this.
|
|
785
|
-
this.
|
|
780
|
+
this.L = effect;
|
|
781
|
+
this.M = error;
|
|
782
|
+
this.N = initialValue;
|
|
783
|
+
this.w = (options == null ? void 0 : options.render) ? EFFECT_RENDER : EFFECT_USER;
|
|
784
|
+
if (this.w === EFFECT_RENDER) {
|
|
785
|
+
this.B = (p) => getClock() > this.h.created && !(this.f & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
|
|
786
786
|
}
|
|
787
|
-
this.
|
|
788
|
-
!(options == null ? void 0 : options.defer) && (this.
|
|
787
|
+
this.z();
|
|
788
|
+
!(options == null ? void 0 : options.defer) && (this.w === EFFECT_USER ? this.h.enqueue(this.w, this) : this.U());
|
|
789
789
|
}
|
|
790
790
|
write(value, flags = 0) {
|
|
791
791
|
var _a, _b;
|
|
792
792
|
if (this.a == STATE_DIRTY) {
|
|
793
|
-
const currentFlags = this.
|
|
794
|
-
this.
|
|
795
|
-
if (this.
|
|
796
|
-
(_b = (_a = this.h).
|
|
793
|
+
const currentFlags = this.f;
|
|
794
|
+
this.f = flags;
|
|
795
|
+
if (this.w === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
796
|
+
(_b = (_a = this.h).S) == null ? void 0 : _b.call(_a, this);
|
|
797
797
|
}
|
|
798
798
|
}
|
|
799
799
|
if (value === UNCHANGED)
|
|
800
|
-
return this.
|
|
801
|
-
this.
|
|
802
|
-
this.
|
|
800
|
+
return this.g;
|
|
801
|
+
this.g = value;
|
|
802
|
+
this.R = true;
|
|
803
803
|
return value;
|
|
804
804
|
}
|
|
805
805
|
q(state, skipQueue) {
|
|
806
806
|
if (this.a >= state || skipQueue)
|
|
807
807
|
return;
|
|
808
808
|
if (this.a === STATE_CLEAN)
|
|
809
|
-
this.h.enqueue(this.
|
|
809
|
+
this.h.enqueue(this.w, this);
|
|
810
810
|
this.a = state;
|
|
811
811
|
}
|
|
812
|
-
|
|
812
|
+
H(error) {
|
|
813
813
|
var _a, _b, _c;
|
|
814
|
-
(_a = this.
|
|
815
|
-
if (this.
|
|
816
|
-
(_c = (_b = this.h).
|
|
814
|
+
(_a = this.C) == null ? void 0 : _a.call(this);
|
|
815
|
+
if (this.f & LOADING_BIT) {
|
|
816
|
+
(_c = (_b = this.h).S) == null ? void 0 : _c.call(_b, this);
|
|
817
817
|
}
|
|
818
|
-
this.
|
|
819
|
-
if (this.
|
|
818
|
+
this.f = ERROR_BIT;
|
|
819
|
+
if (this.w === EFFECT_USER) {
|
|
820
820
|
try {
|
|
821
|
-
return this.
|
|
821
|
+
return this.M ? this.C = this.M(error) : console.error(new EffectError(this.L, error));
|
|
822
822
|
} catch (e) {
|
|
823
823
|
error = e;
|
|
824
824
|
}
|
|
825
825
|
}
|
|
826
826
|
this.handleError(error);
|
|
827
827
|
}
|
|
828
|
-
|
|
828
|
+
A() {
|
|
829
829
|
var _a;
|
|
830
830
|
if (this.a === STATE_DISPOSED)
|
|
831
831
|
return;
|
|
832
|
-
this.K = void 0;
|
|
833
|
-
this.M = void 0;
|
|
834
832
|
this.L = void 0;
|
|
835
|
-
|
|
836
|
-
this.
|
|
837
|
-
|
|
833
|
+
this.N = void 0;
|
|
834
|
+
this.M = void 0;
|
|
835
|
+
(_a = this.C) == null ? void 0 : _a.call(this);
|
|
836
|
+
this.C = void 0;
|
|
837
|
+
super.A();
|
|
838
838
|
}
|
|
839
|
-
|
|
839
|
+
U() {
|
|
840
840
|
var _a;
|
|
841
|
-
if (this.
|
|
842
|
-
(_a = this.
|
|
841
|
+
if (this.R && this.a !== STATE_DISPOSED) {
|
|
842
|
+
(_a = this.C) == null ? void 0 : _a.call(this);
|
|
843
843
|
try {
|
|
844
|
-
this.
|
|
844
|
+
this.C = this.L(this.g, this.N);
|
|
845
845
|
} catch (e) {
|
|
846
846
|
this.handleError(e);
|
|
847
847
|
} finally {
|
|
848
|
-
this.
|
|
849
|
-
this.
|
|
848
|
+
this.N = this.g;
|
|
849
|
+
this.R = false;
|
|
850
850
|
}
|
|
851
851
|
}
|
|
852
852
|
}
|
|
@@ -854,10 +854,10 @@ var Effect = class extends Computation {
|
|
|
854
854
|
var EagerComputation = class extends Computation {
|
|
855
855
|
constructor(initialValue, compute2, options) {
|
|
856
856
|
super(initialValue, compute2, options);
|
|
857
|
-
!(options == null ? void 0 : options.defer) && this.
|
|
857
|
+
!(options == null ? void 0 : options.defer) && this.z();
|
|
858
858
|
}
|
|
859
859
|
q(state, skipQueue) {
|
|
860
|
-
if (this.a >= state && !this.
|
|
860
|
+
if (this.a >= state && !this.K)
|
|
861
861
|
return;
|
|
862
862
|
if (this.a === STATE_CLEAN && !skipQueue)
|
|
863
863
|
this.h.enqueue(EFFECT_PURE, this);
|
|
@@ -869,7 +869,7 @@ var ProjectionComputation = class extends Computation {
|
|
|
869
869
|
super(null, compute2);
|
|
870
870
|
}
|
|
871
871
|
q(state, skipQueue) {
|
|
872
|
-
if (this.a >= state && !this.
|
|
872
|
+
if (this.a >= state && !this.K)
|
|
873
873
|
return;
|
|
874
874
|
if (this.a === STATE_CLEAN && !skipQueue)
|
|
875
875
|
this.h.enqueue(EFFECT_PURE, this);
|
|
@@ -879,26 +879,26 @@ var ProjectionComputation = class extends Computation {
|
|
|
879
879
|
|
|
880
880
|
// src/core/suspense.ts
|
|
881
881
|
var SuspenseQueue = class extends Queue {
|
|
882
|
-
|
|
882
|
+
c = /* @__PURE__ */ new Set();
|
|
883
883
|
o = false;
|
|
884
|
-
|
|
884
|
+
T = new Computation(false, null);
|
|
885
885
|
run(type) {
|
|
886
886
|
if (type && this.o)
|
|
887
887
|
return;
|
|
888
888
|
return super.run(type);
|
|
889
889
|
}
|
|
890
|
-
|
|
891
|
-
if (node.
|
|
892
|
-
this.
|
|
890
|
+
S(node) {
|
|
891
|
+
if (node.f & LOADING_BIT) {
|
|
892
|
+
this.c.add(node);
|
|
893
893
|
if (!this.o) {
|
|
894
894
|
this.o = true;
|
|
895
|
-
this.
|
|
895
|
+
this.T.write(true);
|
|
896
896
|
}
|
|
897
897
|
} else {
|
|
898
|
-
this.
|
|
899
|
-
if (this.
|
|
898
|
+
this.c.delete(node);
|
|
899
|
+
if (this.c.size === 0) {
|
|
900
900
|
this.o = false;
|
|
901
|
-
this.
|
|
901
|
+
this.T.write(false);
|
|
902
902
|
}
|
|
903
903
|
}
|
|
904
904
|
}
|
|
@@ -906,13 +906,13 @@ var SuspenseQueue = class extends Queue {
|
|
|
906
906
|
var LiveComputation = class extends EagerComputation {
|
|
907
907
|
write(value, flags = 0) {
|
|
908
908
|
var _a, _b;
|
|
909
|
-
const currentFlags = this.
|
|
909
|
+
const currentFlags = this.f;
|
|
910
910
|
const dirty = this.a === STATE_DIRTY;
|
|
911
911
|
super.write(value, flags);
|
|
912
912
|
if (dirty && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
913
|
-
(_b = (_a = this.h).
|
|
913
|
+
(_b = (_a = this.h).S) == null ? void 0 : _b.call(_a, this);
|
|
914
914
|
}
|
|
915
|
-
return this.
|
|
915
|
+
return this.g;
|
|
916
916
|
}
|
|
917
917
|
};
|
|
918
918
|
function createSuspense(fn, fallback) {
|
|
@@ -921,7 +921,7 @@ function createSuspense(fn, fallback) {
|
|
|
921
921
|
const child = new Computation(null, fn);
|
|
922
922
|
return new LiveComputation(null, () => flatten(child.wait()));
|
|
923
923
|
}, queue);
|
|
924
|
-
const equality = new Computation(null, () => queue.
|
|
924
|
+
const equality = new Computation(null, () => queue.T.read() || queue.o);
|
|
925
925
|
const comp = new Computation(null, () => equality.read() ? fallback() : tree.read());
|
|
926
926
|
return comp.read.bind(comp);
|
|
927
927
|
}
|
|
@@ -953,10 +953,10 @@ function createMemo(compute2, value, options) {
|
|
|
953
953
|
var _a, _b, _c;
|
|
954
954
|
if (node) {
|
|
955
955
|
resolvedValue = node.wait();
|
|
956
|
-
if (!((_a = node.b) == null ? void 0 : _a.length) && ((_b = node.n) == null ? void 0 : _b.
|
|
956
|
+
if (!((_a = node.b) == null ? void 0 : _a.length) && ((_b = node.n) == null ? void 0 : _b.t) !== node) {
|
|
957
957
|
node.dispose();
|
|
958
958
|
node = void 0;
|
|
959
|
-
} else if (!node.
|
|
959
|
+
} else if (!node.t && !((_c = node.e) == null ? void 0 : _c.length)) {
|
|
960
960
|
node.dispose();
|
|
961
961
|
node.a = STATE_DIRTY;
|
|
962
962
|
}
|
|
@@ -968,10 +968,10 @@ function createAsync(compute2, value, options) {
|
|
|
968
968
|
let uninitialized = value === void 0;
|
|
969
969
|
const lhs = new EagerComputation(
|
|
970
970
|
{
|
|
971
|
-
|
|
971
|
+
g: value
|
|
972
972
|
},
|
|
973
973
|
(p) => {
|
|
974
|
-
const value2 = p == null ? void 0 : p.
|
|
974
|
+
const value2 = p == null ? void 0 : p.g;
|
|
975
975
|
const source = compute2(value2);
|
|
976
976
|
const isPromise = source instanceof Promise;
|
|
977
977
|
const iterator = source[Symbol.asyncIterator];
|
|
@@ -980,13 +980,13 @@ function createAsync(compute2, value, options) {
|
|
|
980
980
|
wait() {
|
|
981
981
|
return source;
|
|
982
982
|
},
|
|
983
|
-
|
|
983
|
+
g: source
|
|
984
984
|
};
|
|
985
985
|
}
|
|
986
|
-
const signal = new Computation(value2, null, options);
|
|
986
|
+
const signal = new Computation(value2, null, iterator ? { ...options, equals: false } : options);
|
|
987
987
|
const w = signal.wait;
|
|
988
988
|
signal.wait = function() {
|
|
989
|
-
if (signal.
|
|
989
|
+
if (signal.f & ERROR_BIT && signal.y <= getClock()) {
|
|
990
990
|
lhs.q(STATE_DIRTY);
|
|
991
991
|
throw new NotReadyError();
|
|
992
992
|
}
|
|
@@ -1001,7 +1001,7 @@ function createAsync(compute2, value, options) {
|
|
|
1001
1001
|
},
|
|
1002
1002
|
(error) => {
|
|
1003
1003
|
uninitialized = true;
|
|
1004
|
-
signal.
|
|
1004
|
+
signal.H(error);
|
|
1005
1005
|
}
|
|
1006
1006
|
);
|
|
1007
1007
|
} else {
|
|
@@ -1064,7 +1064,7 @@ function createErrorBoundary(fn, fallback) {
|
|
|
1064
1064
|
);
|
|
1065
1065
|
nodes.add(node);
|
|
1066
1066
|
if (nodes.size === 1)
|
|
1067
|
-
error.write({
|
|
1067
|
+
error.write({ G: err });
|
|
1068
1068
|
}
|
|
1069
1069
|
owner.m = owner.m ? [handler, ...owner.m] : [handler];
|
|
1070
1070
|
const guarded = compute(
|
|
@@ -1072,7 +1072,7 @@ function createErrorBoundary(fn, fallback) {
|
|
|
1072
1072
|
() => {
|
|
1073
1073
|
const c = new Computation(void 0, fn);
|
|
1074
1074
|
const f = new EagerComputation(void 0, () => flatten(c.read()), { defer: true });
|
|
1075
|
-
f.
|
|
1075
|
+
f.H = function(error2) {
|
|
1076
1076
|
this.handleError(error2);
|
|
1077
1077
|
};
|
|
1078
1078
|
return f;
|
|
@@ -1085,12 +1085,12 @@ function createErrorBoundary(fn, fallback) {
|
|
|
1085
1085
|
if (!error.read())
|
|
1086
1086
|
return resolved;
|
|
1087
1087
|
}
|
|
1088
|
-
return fallback(error.read().
|
|
1088
|
+
return fallback(error.read().G, () => {
|
|
1089
1089
|
var _a;
|
|
1090
1090
|
incrementClock();
|
|
1091
1091
|
for (let node of nodes) {
|
|
1092
1092
|
node.a = STATE_DIRTY;
|
|
1093
|
-
(_a = node.h) == null ? void 0 : _a.enqueue(node.
|
|
1093
|
+
(_a = node.h) == null ? void 0 : _a.enqueue(node.w, node);
|
|
1094
1094
|
}
|
|
1095
1095
|
});
|
|
1096
1096
|
});
|
|
@@ -1115,12 +1115,15 @@ function resolve(fn) {
|
|
|
1115
1115
|
|
|
1116
1116
|
// src/store/projection.ts
|
|
1117
1117
|
function createProjection(fn, initialValue = {}) {
|
|
1118
|
-
const [store
|
|
1118
|
+
const [store] = createStore(fn, initialValue);
|
|
1119
|
+
return store;
|
|
1120
|
+
}
|
|
1121
|
+
function wrapProjection(fn, store, setStore) {
|
|
1119
1122
|
const node = new ProjectionComputation(() => {
|
|
1120
1123
|
setStore(fn);
|
|
1121
1124
|
});
|
|
1122
1125
|
const wrapped = /* @__PURE__ */ new WeakMap();
|
|
1123
|
-
return wrap(store, node, wrapped);
|
|
1126
|
+
return [wrap(store, node, wrapped), setStore];
|
|
1124
1127
|
}
|
|
1125
1128
|
function wrap(source, node, wrapped) {
|
|
1126
1129
|
if (wrapped.has(source))
|
|
@@ -1145,8 +1148,10 @@ function wrap(source, node, wrapped) {
|
|
|
1145
1148
|
// src/store/store.ts
|
|
1146
1149
|
var $RAW = Symbol(0);
|
|
1147
1150
|
var $TRACK = Symbol(0);
|
|
1151
|
+
var $DEEP = Symbol(0);
|
|
1148
1152
|
var $TARGET = Symbol(0);
|
|
1149
1153
|
var $PROXY = Symbol(0);
|
|
1154
|
+
var PARENTS = /* @__PURE__ */ new WeakMap();
|
|
1150
1155
|
var STORE_VALUE = "v";
|
|
1151
1156
|
var STORE_NODE = "n";
|
|
1152
1157
|
var STORE_HAS = "h";
|
|
@@ -1169,11 +1174,11 @@ function wrap2(value) {
|
|
|
1169
1174
|
function isWrappable(obj) {
|
|
1170
1175
|
return obj != null && typeof obj === "object" && !Object.isFrozen(obj);
|
|
1171
1176
|
}
|
|
1172
|
-
function unwrap(item,
|
|
1177
|
+
function unwrap(item, deep2 = true, set) {
|
|
1173
1178
|
let result, unwrapped, v, prop;
|
|
1174
1179
|
if (result = item != null && item[$RAW])
|
|
1175
1180
|
return result;
|
|
1176
|
-
if (!
|
|
1181
|
+
if (!deep2)
|
|
1177
1182
|
return item;
|
|
1178
1183
|
if (!isWrappable(item) || (set == null ? void 0 : set.has(item)))
|
|
1179
1184
|
return item;
|
|
@@ -1183,11 +1188,11 @@ function unwrap(item, deep = true, set) {
|
|
|
1183
1188
|
if (Array.isArray(item)) {
|
|
1184
1189
|
for (let i = 0, l = item.length; i < l; i++) {
|
|
1185
1190
|
v = item[i];
|
|
1186
|
-
if ((unwrapped = unwrap(v,
|
|
1191
|
+
if ((unwrapped = unwrap(v, deep2, set)) !== v)
|
|
1187
1192
|
item[i] = unwrapped;
|
|
1188
1193
|
}
|
|
1189
1194
|
} else {
|
|
1190
|
-
if (!
|
|
1195
|
+
if (!deep2)
|
|
1191
1196
|
return item;
|
|
1192
1197
|
const keys = Object.keys(item);
|
|
1193
1198
|
for (let i = 0, l = keys.length; i < l; i++) {
|
|
@@ -1196,7 +1201,7 @@ function unwrap(item, deep = true, set) {
|
|
|
1196
1201
|
if (desc.get)
|
|
1197
1202
|
continue;
|
|
1198
1203
|
v = item[prop];
|
|
1199
|
-
if ((unwrapped = unwrap(v,
|
|
1204
|
+
if ((unwrapped = unwrap(v, deep2, set)) !== v)
|
|
1200
1205
|
item[prop] = unwrapped;
|
|
1201
1206
|
}
|
|
1202
1207
|
}
|
|
@@ -1229,8 +1234,8 @@ function proxyDescriptor(target, property) {
|
|
|
1229
1234
|
desc.get = () => target[STORE_VALUE][$PROXY][property];
|
|
1230
1235
|
return desc;
|
|
1231
1236
|
}
|
|
1232
|
-
function trackSelf(target) {
|
|
1233
|
-
getObserver() && getNode(getNodes(target, STORE_NODE),
|
|
1237
|
+
function trackSelf(target, symbol = $TRACK) {
|
|
1238
|
+
getObserver() && getNode(getNodes(target, STORE_NODE), symbol, void 0, false).read();
|
|
1234
1239
|
}
|
|
1235
1240
|
function ownKeys(target) {
|
|
1236
1241
|
trackSelf(target);
|
|
@@ -1245,8 +1250,8 @@ var proxyTraps = {
|
|
|
1245
1250
|
return target[STORE_VALUE];
|
|
1246
1251
|
if (property === $PROXY)
|
|
1247
1252
|
return receiver;
|
|
1248
|
-
if (property === $TRACK) {
|
|
1249
|
-
trackSelf(target);
|
|
1253
|
+
if (property === $TRACK || property === $DEEP) {
|
|
1254
|
+
trackSelf(target, property);
|
|
1250
1255
|
return receiver;
|
|
1251
1256
|
}
|
|
1252
1257
|
const nodes = getNodes(target, STORE_NODE);
|
|
@@ -1258,7 +1263,7 @@ var proxyTraps = {
|
|
|
1258
1263
|
return desc.get.call(receiver);
|
|
1259
1264
|
}
|
|
1260
1265
|
if (Writing.has(storeValue)) {
|
|
1261
|
-
const value2 = tracked ? tracked.
|
|
1266
|
+
const value2 = tracked ? tracked.g : storeValue[property];
|
|
1262
1267
|
return isWrappable(value2) ? (Writing.add(value2[$RAW] || value2), wrap2(value2)) : value2;
|
|
1263
1268
|
}
|
|
1264
1269
|
let value = tracked ? nodes[property].read() : storeValue[property];
|
|
@@ -1267,7 +1272,7 @@ var proxyTraps = {
|
|
|
1267
1272
|
let proto;
|
|
1268
1273
|
return !Array.isArray(storeValue) && (proto = Object.getPrototypeOf(storeValue)) && proto !== Object.prototype ? value.bind(storeValue) : value;
|
|
1269
1274
|
} else if (getObserver()) {
|
|
1270
|
-
|
|
1275
|
+
return getNode(nodes, property, isWrappable(value) ? wrap2(value) : value).read();
|
|
1271
1276
|
}
|
|
1272
1277
|
}
|
|
1273
1278
|
return isWrappable(value) ? wrap2(value) : value;
|
|
@@ -1294,7 +1299,7 @@ var proxyTraps = {
|
|
|
1294
1299
|
}
|
|
1295
1300
|
};
|
|
1296
1301
|
function setProperty(state, property, value, deleting = false) {
|
|
1297
|
-
var _a, _b, _c, _d, _e;
|
|
1302
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1298
1303
|
const prev = state[property];
|
|
1299
1304
|
if (!deleting && prev === value)
|
|
1300
1305
|
return;
|
|
@@ -1303,6 +1308,13 @@ function setProperty(state, property, value, deleting = false) {
|
|
|
1303
1308
|
delete state[property];
|
|
1304
1309
|
else
|
|
1305
1310
|
state[property] = value;
|
|
1311
|
+
const wrappable = isWrappable(value);
|
|
1312
|
+
if (isWrappable(prev)) {
|
|
1313
|
+
const parents = PARENTS.get(prev);
|
|
1314
|
+
parents && (parents instanceof Set ? parents.delete(state) : PARENTS.delete(prev));
|
|
1315
|
+
}
|
|
1316
|
+
if (recursivelyNotify(state) && wrappable)
|
|
1317
|
+
recursivelyAddParent(value[$RAW] || value, state);
|
|
1306
1318
|
const target = (_a = state[$PROXY]) == null ? void 0 : _a[$TARGET];
|
|
1307
1319
|
if (!target)
|
|
1308
1320
|
return;
|
|
@@ -1311,18 +1323,56 @@ function setProperty(state, property, value, deleting = false) {
|
|
|
1311
1323
|
else
|
|
1312
1324
|
(_e = (_d = target[STORE_HAS]) == null ? void 0 : _d[property]) == null ? void 0 : _e.write(true);
|
|
1313
1325
|
const nodes = getNodes(target, STORE_NODE);
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1326
|
+
(_f = nodes[property]) == null ? void 0 : _f.write(wrappable ? wrap2(value) : value);
|
|
1327
|
+
Array.isArray(state) && state.length !== len && ((_g = nodes.length) == null ? void 0 : _g.write(state.length));
|
|
1328
|
+
(_h = nodes[$TRACK]) == null ? void 0 : _h.write(void 0);
|
|
1329
|
+
}
|
|
1330
|
+
function recursivelyNotify(state) {
|
|
1331
|
+
var _a, _b;
|
|
1332
|
+
let target = (_a = state[$PROXY]) == null ? void 0 : _a[$TARGET];
|
|
1333
|
+
let notified = false;
|
|
1334
|
+
target && ((_b = getNodes(target, STORE_NODE)[$DEEP]) == null ? void 0 : _b.write(void 0), notified = true);
|
|
1335
|
+
const parents = PARENTS.get(state);
|
|
1336
|
+
if (!parents)
|
|
1337
|
+
return notified;
|
|
1338
|
+
if (parents instanceof Set) {
|
|
1339
|
+
for (let parent of parents)
|
|
1340
|
+
notified = recursivelyNotify(parent) || notified;
|
|
1341
|
+
} else
|
|
1342
|
+
notified = recursivelyNotify(parents) || notified;
|
|
1343
|
+
return notified;
|
|
1344
|
+
}
|
|
1345
|
+
function recursivelyAddParent(state, parent) {
|
|
1346
|
+
if (parent) {
|
|
1347
|
+
let parents = PARENTS.get(state);
|
|
1348
|
+
if (!parents)
|
|
1349
|
+
PARENTS.set(state, parent);
|
|
1350
|
+
else if (parents !== parent) {
|
|
1351
|
+
if (!(parents instanceof Set))
|
|
1352
|
+
PARENTS.set(state, parents = /* @__PURE__ */ new Set([parents]));
|
|
1353
|
+
else if (parents.has(parent))
|
|
1354
|
+
return;
|
|
1355
|
+
parents.add(parent);
|
|
1356
|
+
} else
|
|
1357
|
+
return;
|
|
1358
|
+
}
|
|
1359
|
+
if (Array.isArray(state)) {
|
|
1360
|
+
for (let i = 0; i < state.length; i++) {
|
|
1361
|
+
const item = state[i];
|
|
1362
|
+
isWrappable(item) && recursivelyAddParent(item[$RAW] || item, state);
|
|
1363
|
+
}
|
|
1364
|
+
} else {
|
|
1365
|
+
const keys = Object.keys(state);
|
|
1366
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1367
|
+
const item = state[keys[i]];
|
|
1368
|
+
isWrappable(item) && recursivelyAddParent(item[$RAW] || item, state);
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1319
1371
|
}
|
|
1320
1372
|
function createStore(first, second) {
|
|
1321
1373
|
const derived = typeof first === "function", store = derived ? second : first;
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
const unwrappedStore = unwrap(store, false);
|
|
1325
|
-
const wrappedStore = wrap2(unwrappedStore);
|
|
1374
|
+
const unwrappedStore = unwrap(store);
|
|
1375
|
+
let wrappedStore = wrap2(unwrappedStore);
|
|
1326
1376
|
const setStore = (fn) => {
|
|
1327
1377
|
try {
|
|
1328
1378
|
Writing.add(unwrappedStore);
|
|
@@ -1331,8 +1381,14 @@ function createStore(first, second) {
|
|
|
1331
1381
|
Writing.clear();
|
|
1332
1382
|
}
|
|
1333
1383
|
};
|
|
1384
|
+
if (derived)
|
|
1385
|
+
return wrapProjection(first, wrappedStore, setStore);
|
|
1334
1386
|
return [wrappedStore, setStore];
|
|
1335
1387
|
}
|
|
1388
|
+
function deep(store) {
|
|
1389
|
+
recursivelyAddParent(store[$RAW] || store);
|
|
1390
|
+
return store[$DEEP];
|
|
1391
|
+
}
|
|
1336
1392
|
|
|
1337
1393
|
// src/store/reconcile.ts
|
|
1338
1394
|
function applyState(next, state, keyFn) {
|
|
@@ -1599,73 +1655,73 @@ function omit(props, ...keys) {
|
|
|
1599
1655
|
function mapArray(list, map, options) {
|
|
1600
1656
|
const keyFn = typeof (options == null ? void 0 : options.keyed) === "function" ? options.keyed : void 0;
|
|
1601
1657
|
return updateKeyedMap.bind({
|
|
1602
|
-
|
|
1658
|
+
I: new Owner(),
|
|
1603
1659
|
i: 0,
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1660
|
+
Y: list,
|
|
1661
|
+
x: [],
|
|
1662
|
+
D: map,
|
|
1663
|
+
d: [],
|
|
1664
|
+
c: [],
|
|
1665
|
+
E: keyFn,
|
|
1610
1666
|
j: keyFn || (options == null ? void 0 : options.keyed) === false ? [] : void 0,
|
|
1611
1667
|
k: map.length > 1 ? [] : void 0,
|
|
1612
1668
|
o: options == null ? void 0 : options.fallback
|
|
1613
1669
|
});
|
|
1614
1670
|
}
|
|
1615
1671
|
function updateKeyedMap() {
|
|
1616
|
-
const newItems = this.
|
|
1672
|
+
const newItems = this.Y() || [], newLen = newItems.length;
|
|
1617
1673
|
newItems[$TRACK];
|
|
1618
|
-
runWithOwner(this.
|
|
1674
|
+
runWithOwner(this.I, () => {
|
|
1619
1675
|
let i, j, mapper = this.j ? () => {
|
|
1620
1676
|
this.j[j] = new Computation(newItems[j], null);
|
|
1621
1677
|
this.k && (this.k[j] = new Computation(j, null));
|
|
1622
|
-
return this.
|
|
1678
|
+
return this.D(
|
|
1623
1679
|
Computation.prototype.read.bind(this.j[j]),
|
|
1624
1680
|
this.k ? Computation.prototype.read.bind(this.k[j]) : void 0
|
|
1625
1681
|
);
|
|
1626
1682
|
} : this.k ? () => {
|
|
1627
1683
|
const item = newItems[j];
|
|
1628
1684
|
this.k[j] = new Computation(j, null);
|
|
1629
|
-
return this.
|
|
1685
|
+
return this.D(() => item, Computation.prototype.read.bind(this.k[j]));
|
|
1630
1686
|
} : () => {
|
|
1631
1687
|
const item = newItems[j];
|
|
1632
|
-
return this.
|
|
1688
|
+
return this.D(() => item);
|
|
1633
1689
|
};
|
|
1634
1690
|
if (newLen === 0) {
|
|
1635
1691
|
if (this.i !== 0) {
|
|
1636
|
-
this.
|
|
1637
|
-
this.
|
|
1638
|
-
this.
|
|
1639
|
-
this.
|
|
1692
|
+
this.I.dispose(false);
|
|
1693
|
+
this.c = [];
|
|
1694
|
+
this.x = [];
|
|
1695
|
+
this.d = [];
|
|
1640
1696
|
this.i = 0;
|
|
1641
1697
|
this.j && (this.j = []);
|
|
1642
1698
|
this.k && (this.k = []);
|
|
1643
1699
|
}
|
|
1644
|
-
if (this.o && !this.
|
|
1645
|
-
this.
|
|
1646
|
-
this.
|
|
1700
|
+
if (this.o && !this.d[0]) {
|
|
1701
|
+
this.d[0] = compute(
|
|
1702
|
+
this.c[0] = new Owner(),
|
|
1647
1703
|
this.o,
|
|
1648
1704
|
null
|
|
1649
1705
|
);
|
|
1650
1706
|
}
|
|
1651
1707
|
} else if (this.i === 0) {
|
|
1652
|
-
if (this.
|
|
1653
|
-
this.
|
|
1654
|
-
this.
|
|
1708
|
+
if (this.c[0])
|
|
1709
|
+
this.c[0].dispose();
|
|
1710
|
+
this.d = new Array(newLen);
|
|
1655
1711
|
for (j = 0; j < newLen; j++) {
|
|
1656
|
-
this.
|
|
1657
|
-
this.
|
|
1712
|
+
this.x[j] = newItems[j];
|
|
1713
|
+
this.d[j] = compute(this.c[j] = new Owner(), mapper, null);
|
|
1658
1714
|
}
|
|
1659
1715
|
this.i = newLen;
|
|
1660
1716
|
} else {
|
|
1661
1717
|
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;
|
|
1662
|
-
for (start = 0, end = Math.min(this.i, newLen); start < end && (this.
|
|
1718
|
+
for (start = 0, end = Math.min(this.i, newLen); start < end && (this.x[start] === newItems[start] || this.j && compare(this.E, this.x[start], newItems[start])); start++) {
|
|
1663
1719
|
if (this.j)
|
|
1664
1720
|
this.j[start].write(newItems[start]);
|
|
1665
1721
|
}
|
|
1666
|
-
for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.
|
|
1667
|
-
temp[newEnd] = this.
|
|
1668
|
-
tempNodes[newEnd] = this.
|
|
1722
|
+
for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.x[end] === newItems[newEnd] || this.j && compare(this.E, this.x[end], newItems[newEnd])); end--, newEnd--) {
|
|
1723
|
+
temp[newEnd] = this.d[end];
|
|
1724
|
+
tempNodes[newEnd] = this.c[end];
|
|
1669
1725
|
tempRows && (tempRows[newEnd] = this.j[end]);
|
|
1670
1726
|
tempIndexes && (tempIndexes[newEnd] = this.k[end]);
|
|
1671
1727
|
}
|
|
@@ -1673,29 +1729,29 @@ function updateKeyedMap() {
|
|
|
1673
1729
|
newIndicesNext = new Array(newEnd + 1);
|
|
1674
1730
|
for (j = newEnd; j >= start; j--) {
|
|
1675
1731
|
item = newItems[j];
|
|
1676
|
-
key = this.
|
|
1732
|
+
key = this.E ? this.E(item) : item;
|
|
1677
1733
|
i = newIndices.get(key);
|
|
1678
1734
|
newIndicesNext[j] = i === void 0 ? -1 : i;
|
|
1679
1735
|
newIndices.set(key, j);
|
|
1680
1736
|
}
|
|
1681
1737
|
for (i = start; i <= end; i++) {
|
|
1682
|
-
item = this.
|
|
1683
|
-
key = this.
|
|
1738
|
+
item = this.x[i];
|
|
1739
|
+
key = this.E ? this.E(item) : item;
|
|
1684
1740
|
j = newIndices.get(key);
|
|
1685
1741
|
if (j !== void 0 && j !== -1) {
|
|
1686
|
-
temp[j] = this.
|
|
1687
|
-
tempNodes[j] = this.
|
|
1742
|
+
temp[j] = this.d[i];
|
|
1743
|
+
tempNodes[j] = this.c[i];
|
|
1688
1744
|
tempRows && (tempRows[j] = this.j[i]);
|
|
1689
1745
|
tempIndexes && (tempIndexes[j] = this.k[i]);
|
|
1690
1746
|
j = newIndicesNext[j];
|
|
1691
1747
|
newIndices.set(key, j);
|
|
1692
1748
|
} else
|
|
1693
|
-
this.
|
|
1749
|
+
this.c[i].dispose();
|
|
1694
1750
|
}
|
|
1695
1751
|
for (j = start; j < newLen; j++) {
|
|
1696
1752
|
if (j in temp) {
|
|
1697
|
-
this.
|
|
1698
|
-
this.
|
|
1753
|
+
this.d[j] = temp[j];
|
|
1754
|
+
this.c[j] = tempNodes[j];
|
|
1699
1755
|
if (tempRows) {
|
|
1700
1756
|
this.j[j] = tempRows[j];
|
|
1701
1757
|
this.j[j].write(newItems[j]);
|
|
@@ -1705,60 +1761,90 @@ function updateKeyedMap() {
|
|
|
1705
1761
|
this.k[j].write(j);
|
|
1706
1762
|
}
|
|
1707
1763
|
} else {
|
|
1708
|
-
this.
|
|
1764
|
+
this.d[j] = compute(this.c[j] = new Owner(), mapper, null);
|
|
1709
1765
|
}
|
|
1710
1766
|
}
|
|
1711
|
-
this.
|
|
1712
|
-
this.
|
|
1767
|
+
this.d = this.d.slice(0, this.i = newLen);
|
|
1768
|
+
this.x = newItems.slice(0);
|
|
1713
1769
|
}
|
|
1714
1770
|
});
|
|
1715
|
-
return this.
|
|
1771
|
+
return this.d;
|
|
1716
1772
|
}
|
|
1717
1773
|
function repeat(count, map, options) {
|
|
1718
1774
|
return updateRepeat.bind({
|
|
1719
|
-
|
|
1775
|
+
I: new Owner(),
|
|
1720
1776
|
i: 0,
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1777
|
+
r: 0,
|
|
1778
|
+
Z: count,
|
|
1779
|
+
D: map,
|
|
1780
|
+
c: [],
|
|
1781
|
+
d: [],
|
|
1782
|
+
_: options == null ? void 0 : options.from,
|
|
1725
1783
|
o: options == null ? void 0 : options.fallback
|
|
1726
1784
|
});
|
|
1727
1785
|
}
|
|
1728
1786
|
function updateRepeat() {
|
|
1729
|
-
|
|
1730
|
-
|
|
1787
|
+
var _a;
|
|
1788
|
+
const newLen = this.Z();
|
|
1789
|
+
const from = ((_a = this._) == null ? void 0 : _a.call(this)) || 0;
|
|
1790
|
+
runWithOwner(this.I, () => {
|
|
1731
1791
|
if (newLen === 0) {
|
|
1732
1792
|
if (this.i !== 0) {
|
|
1733
|
-
this.
|
|
1734
|
-
this.
|
|
1735
|
-
this.
|
|
1793
|
+
this.I.dispose(false);
|
|
1794
|
+
this.c = [];
|
|
1795
|
+
this.d = [];
|
|
1736
1796
|
this.i = 0;
|
|
1737
1797
|
}
|
|
1738
|
-
if (this.o && !this.
|
|
1739
|
-
this.
|
|
1740
|
-
this.
|
|
1798
|
+
if (this.o && !this.d[0]) {
|
|
1799
|
+
this.d[0] = compute(
|
|
1800
|
+
this.c[0] = new Owner(),
|
|
1741
1801
|
this.o,
|
|
1742
1802
|
null
|
|
1743
1803
|
);
|
|
1744
1804
|
}
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1805
|
+
return;
|
|
1806
|
+
}
|
|
1807
|
+
const to = from + newLen;
|
|
1808
|
+
const prevTo = this.r + this.i;
|
|
1809
|
+
if (this.i === 0 && this.c[0])
|
|
1810
|
+
this.c[0].dispose();
|
|
1811
|
+
for (let i = to; i < prevTo; i++)
|
|
1812
|
+
this.c[i - this.r].dispose();
|
|
1813
|
+
if (this.r < from) {
|
|
1814
|
+
let i = this.r;
|
|
1815
|
+
while (i < from && i < this.i)
|
|
1816
|
+
this.c[i++].dispose();
|
|
1817
|
+
this.c.splice(0, from - this.r);
|
|
1818
|
+
this.d.splice(0, from - this.r);
|
|
1819
|
+
} else if (this.r > from) {
|
|
1820
|
+
let i = prevTo - this.r - 1;
|
|
1821
|
+
let difference = this.r - from;
|
|
1822
|
+
this.c.length = this.d.length = newLen;
|
|
1823
|
+
while (i >= difference) {
|
|
1824
|
+
this.c[i] = this.c[i - difference];
|
|
1825
|
+
this.d[i] = this.d[i - difference];
|
|
1826
|
+
i--;
|
|
1827
|
+
}
|
|
1828
|
+
for (let i2 = 0; i2 < difference; i2++) {
|
|
1829
|
+
this.d[i2] = compute(
|
|
1830
|
+
this.c[i2] = new Owner(),
|
|
1831
|
+
() => this.D(i2 + from),
|
|
1752
1832
|
null
|
|
1753
1833
|
);
|
|
1754
1834
|
}
|
|
1755
|
-
for (let i = newLen; i < this.i; i++)
|
|
1756
|
-
this.f[i].dispose();
|
|
1757
|
-
this.g = this.g.slice(0, newLen);
|
|
1758
|
-
this.i = newLen;
|
|
1759
1835
|
}
|
|
1836
|
+
for (let i = prevTo; i < to; i++) {
|
|
1837
|
+
this.d[i - from] = compute(
|
|
1838
|
+
this.c[i - from] = new Owner(),
|
|
1839
|
+
() => this.D(i),
|
|
1840
|
+
null
|
|
1841
|
+
);
|
|
1842
|
+
}
|
|
1843
|
+
this.d = this.d.slice(0, newLen);
|
|
1844
|
+
this.r = from;
|
|
1845
|
+
this.i = newLen;
|
|
1760
1846
|
});
|
|
1761
|
-
return this.
|
|
1847
|
+
return this.d;
|
|
1762
1848
|
}
|
|
1763
1849
|
function compare(key, a, b) {
|
|
1764
1850
|
return key ? key(a) === key(b) : true;
|
|
@@ -1788,6 +1874,7 @@ exports.createRoot = createRoot;
|
|
|
1788
1874
|
exports.createSignal = createSignal;
|
|
1789
1875
|
exports.createStore = createStore;
|
|
1790
1876
|
exports.createSuspense = createSuspense;
|
|
1877
|
+
exports.deep = deep;
|
|
1791
1878
|
exports.flatten = flatten;
|
|
1792
1879
|
exports.flushSync = flushSync;
|
|
1793
1880
|
exports.getContext = getContext;
|