@solidjs/signals 0.2.2 → 0.2.4
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 +113 -73
- package/dist/node.cjs +365 -324
- package/dist/prod.js +364 -324
- package/dist/types/core/core.d.ts +4 -0
- package/dist/types/core/index.d.ts +1 -2
- package/dist/types/core/utils.d.ts +0 -4
- package/dist/types/map.d.ts +1 -0
- package/dist/types/store/index.d.ts +2 -2
- package/dist/types/store/projection.d.ts +3 -1
- package/package.json +1 -1
- /package/dist/types/store/{utilities.d.ts → utils.d.ts} +0 -0
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,67 +127,13 @@ 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
|
|
134
134
|
function isUndefined(value) {
|
|
135
135
|
return typeof value === "undefined";
|
|
136
136
|
}
|
|
137
|
-
function flatten(children, options) {
|
|
138
|
-
if (typeof children === "function" && !children.length) {
|
|
139
|
-
if (options == null ? void 0 : options.doNotUnwrap)
|
|
140
|
-
return children;
|
|
141
|
-
do {
|
|
142
|
-
children = children();
|
|
143
|
-
} while (typeof children === "function" && !children.length);
|
|
144
|
-
}
|
|
145
|
-
if ((options == null ? void 0 : options.skipNonRendered) && (children == null || children === true || children === false || children === ""))
|
|
146
|
-
return;
|
|
147
|
-
if (Array.isArray(children)) {
|
|
148
|
-
let results = [];
|
|
149
|
-
if (flattenArray(children, results, options)) {
|
|
150
|
-
return () => {
|
|
151
|
-
let nested = [];
|
|
152
|
-
flattenArray(results, nested, { ...options, doNotUnwrap: false });
|
|
153
|
-
return nested;
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
return results;
|
|
157
|
-
}
|
|
158
|
-
return children;
|
|
159
|
-
}
|
|
160
|
-
function flattenArray(children, results = [], options) {
|
|
161
|
-
let notReady = null;
|
|
162
|
-
let needsUnwrap = false;
|
|
163
|
-
for (let i = 0; i < children.length; i++) {
|
|
164
|
-
try {
|
|
165
|
-
let child = children[i];
|
|
166
|
-
if (typeof child === "function" && !child.length) {
|
|
167
|
-
if (options == null ? void 0 : options.doNotUnwrap) {
|
|
168
|
-
results.push(child);
|
|
169
|
-
needsUnwrap = true;
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
|
-
do {
|
|
173
|
-
child = child();
|
|
174
|
-
} while (typeof child === "function" && !child.length);
|
|
175
|
-
}
|
|
176
|
-
if (Array.isArray(child)) {
|
|
177
|
-
needsUnwrap = flattenArray(child, results, options);
|
|
178
|
-
} else if ((options == null ? void 0 : options.skipNonRendered) && (child == null || child === true || child === false || child === "")) {
|
|
179
|
-
} else
|
|
180
|
-
results.push(child);
|
|
181
|
-
} catch (e) {
|
|
182
|
-
if (!(e instanceof NotReadyError))
|
|
183
|
-
throw e;
|
|
184
|
-
notReady = e;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
if (notReady)
|
|
188
|
-
throw notReady;
|
|
189
|
-
return needsUnwrap;
|
|
190
|
-
}
|
|
191
137
|
|
|
192
138
|
// src/core/owner.ts
|
|
193
139
|
var currentOwner = null;
|
|
@@ -204,9 +150,9 @@ var Owner = class {
|
|
|
204
150
|
// We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
|
|
205
151
|
// However, the children are actually added in reverse creation order
|
|
206
152
|
// See comment at the top of the file for an example of the _nextSibling traversal
|
|
207
|
-
s = null;
|
|
208
|
-
n = null;
|
|
209
153
|
t = null;
|
|
154
|
+
n = null;
|
|
155
|
+
u = null;
|
|
210
156
|
a = STATE_CLEAN;
|
|
211
157
|
l = null;
|
|
212
158
|
p = defaultContext;
|
|
@@ -217,10 +163,10 @@ var Owner = class {
|
|
|
217
163
|
currentOwner.append(this);
|
|
218
164
|
}
|
|
219
165
|
append(child) {
|
|
220
|
-
child.s = this;
|
|
221
166
|
child.t = this;
|
|
167
|
+
child.u = this;
|
|
222
168
|
if (this.n)
|
|
223
|
-
this.n.
|
|
169
|
+
this.n.u = child;
|
|
224
170
|
child.n = this.n;
|
|
225
171
|
this.n = child;
|
|
226
172
|
if (child.p !== this.p) {
|
|
@@ -235,26 +181,26 @@ var Owner = class {
|
|
|
235
181
|
dispose(self = true) {
|
|
236
182
|
if (this.a === STATE_DISPOSED)
|
|
237
183
|
return;
|
|
238
|
-
let head = self ? this.
|
|
239
|
-
while (current && current.
|
|
184
|
+
let head = self ? this.u || this.t : this, current = this.n, next = null;
|
|
185
|
+
while (current && current.t === this) {
|
|
240
186
|
current.dispose(true);
|
|
241
|
-
current.
|
|
187
|
+
current.A();
|
|
242
188
|
next = current.n;
|
|
243
189
|
current.n = null;
|
|
244
190
|
current = next;
|
|
245
191
|
}
|
|
246
192
|
if (self)
|
|
247
|
-
this.
|
|
193
|
+
this.A();
|
|
248
194
|
if (current)
|
|
249
|
-
current.
|
|
195
|
+
current.u = !self ? this : this.u;
|
|
250
196
|
if (head)
|
|
251
197
|
head.n = current;
|
|
252
198
|
}
|
|
253
|
-
|
|
254
|
-
if (this.
|
|
255
|
-
this.
|
|
256
|
-
this.s = null;
|
|
199
|
+
A() {
|
|
200
|
+
if (this.u)
|
|
201
|
+
this.u.n = null;
|
|
257
202
|
this.t = null;
|
|
203
|
+
this.u = null;
|
|
258
204
|
this.p = defaultContext;
|
|
259
205
|
this.m = null;
|
|
260
206
|
this.a = STATE_DISPOSED;
|
|
@@ -352,49 +298,49 @@ function getObserver() {
|
|
|
352
298
|
var UNCHANGED = Symbol(0);
|
|
353
299
|
var Computation = class extends Owner {
|
|
354
300
|
b = null;
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
301
|
+
e = null;
|
|
302
|
+
g;
|
|
303
|
+
G;
|
|
304
|
+
B;
|
|
359
305
|
// Used in __DEV__ mode, hopefully removed in production
|
|
360
|
-
|
|
306
|
+
$;
|
|
361
307
|
// Using false is an optimization as an alternative to _equals: () => false
|
|
362
308
|
// which could enable more efficient DIRTY notification
|
|
363
|
-
|
|
364
|
-
|
|
309
|
+
O = isEqual;
|
|
310
|
+
V;
|
|
365
311
|
/** Whether the computation is an error or has ancestors that are unresolved */
|
|
366
|
-
|
|
312
|
+
f = 0;
|
|
367
313
|
/** Which flags raised by sources are handled, vs. being passed through. */
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
314
|
+
P = DEFAULT_FLAGS;
|
|
315
|
+
Q = null;
|
|
316
|
+
y = -1;
|
|
317
|
+
K = false;
|
|
372
318
|
constructor(initialValue, compute2, options) {
|
|
373
319
|
super(compute2 === null);
|
|
374
|
-
this.
|
|
320
|
+
this.B = compute2;
|
|
375
321
|
this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
|
|
376
|
-
this.
|
|
377
|
-
this.
|
|
322
|
+
this.f = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
|
|
323
|
+
this.g = initialValue;
|
|
378
324
|
if ((options == null ? void 0 : options.equals) !== void 0)
|
|
379
|
-
this.
|
|
325
|
+
this.O = options.equals;
|
|
380
326
|
if (options == null ? void 0 : options.unobserved)
|
|
381
|
-
this.
|
|
327
|
+
this.V = options == null ? void 0 : options.unobserved;
|
|
382
328
|
}
|
|
383
|
-
|
|
329
|
+
W() {
|
|
384
330
|
var _a;
|
|
385
|
-
if (this.
|
|
386
|
-
if (this.
|
|
331
|
+
if (this.B) {
|
|
332
|
+
if (this.f & ERROR_BIT && this.y <= getClock())
|
|
387
333
|
update(this);
|
|
388
334
|
else
|
|
389
|
-
this.
|
|
335
|
+
this.z();
|
|
390
336
|
}
|
|
391
|
-
if (!this.
|
|
337
|
+
if (!this.B || ((_a = this.b) == null ? void 0 : _a.length))
|
|
392
338
|
track(this);
|
|
393
|
-
newFlags |= this.
|
|
394
|
-
if (this.
|
|
395
|
-
throw this.
|
|
339
|
+
newFlags |= this.f & ~currentMask;
|
|
340
|
+
if (this.f & ERROR_BIT) {
|
|
341
|
+
throw this.G;
|
|
396
342
|
} else {
|
|
397
|
-
return this.
|
|
343
|
+
return this.g;
|
|
398
344
|
}
|
|
399
345
|
}
|
|
400
346
|
/**
|
|
@@ -402,7 +348,7 @@ var Computation = class extends Owner {
|
|
|
402
348
|
* Automatically re-executes the surrounding computation when the value changes
|
|
403
349
|
*/
|
|
404
350
|
read() {
|
|
405
|
-
return this.
|
|
351
|
+
return this.W();
|
|
406
352
|
}
|
|
407
353
|
/**
|
|
408
354
|
* Return the current value of this computation
|
|
@@ -412,15 +358,15 @@ var Computation = class extends Owner {
|
|
|
412
358
|
* before continuing
|
|
413
359
|
*/
|
|
414
360
|
wait() {
|
|
415
|
-
if (this.
|
|
361
|
+
if (this.B && this.f & ERROR_BIT && this.y <= getClock()) {
|
|
416
362
|
update(this);
|
|
417
363
|
}
|
|
418
|
-
if ((notStale || this.
|
|
364
|
+
if ((notStale || this.f & UNINITIALIZED_BIT) && this.loading()) {
|
|
419
365
|
throw new NotReadyError();
|
|
420
366
|
}
|
|
421
367
|
if (staleCheck && this.loading())
|
|
422
|
-
staleCheck.
|
|
423
|
-
return this.
|
|
368
|
+
staleCheck.g = true;
|
|
369
|
+
return this.W();
|
|
424
370
|
}
|
|
425
371
|
/**
|
|
426
372
|
* Return true if the computation is the value is dependent on an unresolved promise
|
|
@@ -430,44 +376,44 @@ var Computation = class extends Owner {
|
|
|
430
376
|
* loading state changes
|
|
431
377
|
*/
|
|
432
378
|
loading() {
|
|
433
|
-
if (this.
|
|
434
|
-
this.
|
|
379
|
+
if (this.Q === null) {
|
|
380
|
+
this.Q = loadingState(this);
|
|
435
381
|
}
|
|
436
|
-
return this.
|
|
382
|
+
return this.Q.read();
|
|
437
383
|
}
|
|
438
384
|
/** Update the computation with a new value. */
|
|
439
385
|
write(value, flags = 0, raw = false) {
|
|
440
|
-
const newValue = !raw && typeof value === "function" ? value(this.
|
|
441
|
-
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));
|
|
442
388
|
if (valueChanged) {
|
|
443
|
-
this.
|
|
444
|
-
this.
|
|
445
|
-
}
|
|
446
|
-
const changedFlagsMask = this.
|
|
447
|
-
this.
|
|
448
|
-
this.
|
|
449
|
-
if (this.
|
|
450
|
-
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++) {
|
|
451
397
|
if (valueChanged) {
|
|
452
|
-
this.
|
|
398
|
+
this.e[i].q(STATE_DIRTY);
|
|
453
399
|
} else if (changedFlagsMask) {
|
|
454
|
-
this.
|
|
400
|
+
this.e[i].X(changedFlagsMask, changedFlags);
|
|
455
401
|
}
|
|
456
402
|
}
|
|
457
403
|
}
|
|
458
|
-
return this.
|
|
404
|
+
return this.g;
|
|
459
405
|
}
|
|
460
406
|
/**
|
|
461
407
|
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
|
462
408
|
*/
|
|
463
409
|
q(state, skipQueue) {
|
|
464
|
-
if (this.a >= state && !this.
|
|
410
|
+
if (this.a >= state && !this.K)
|
|
465
411
|
return;
|
|
466
|
-
this.
|
|
412
|
+
this.K = !!skipQueue;
|
|
467
413
|
this.a = state;
|
|
468
|
-
if (this.
|
|
469
|
-
for (let i = 0; i < this.
|
|
470
|
-
this.
|
|
414
|
+
if (this.e) {
|
|
415
|
+
for (let i = 0; i < this.e.length; i++) {
|
|
416
|
+
this.e[i].q(STATE_CHECK, skipQueue);
|
|
471
417
|
}
|
|
472
418
|
}
|
|
473
419
|
}
|
|
@@ -477,31 +423,31 @@ var Computation = class extends Owner {
|
|
|
477
423
|
* @param mask A bitmask for which flag(s) were changed.
|
|
478
424
|
* @param newFlags The source's new flags, masked to just the changed ones.
|
|
479
425
|
*/
|
|
480
|
-
|
|
426
|
+
X(mask, newFlags2) {
|
|
481
427
|
if (this.a >= STATE_DIRTY)
|
|
482
428
|
return;
|
|
483
|
-
if (mask & this.
|
|
429
|
+
if (mask & this.P) {
|
|
484
430
|
this.q(STATE_DIRTY);
|
|
485
431
|
return;
|
|
486
432
|
}
|
|
487
433
|
if (this.a >= STATE_CHECK)
|
|
488
434
|
return;
|
|
489
|
-
const prevFlags = this.
|
|
435
|
+
const prevFlags = this.f & mask;
|
|
490
436
|
const deltaFlags = prevFlags ^ newFlags2;
|
|
491
437
|
if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
|
|
492
438
|
this.q(STATE_CHECK);
|
|
493
439
|
} else {
|
|
494
|
-
this.
|
|
495
|
-
if (this.
|
|
496
|
-
for (let i = 0; i < this.
|
|
497
|
-
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);
|
|
498
444
|
}
|
|
499
445
|
}
|
|
500
446
|
}
|
|
501
447
|
}
|
|
502
|
-
|
|
503
|
-
this.
|
|
504
|
-
this.write(UNCHANGED, this.
|
|
448
|
+
H(error) {
|
|
449
|
+
this.G = error;
|
|
450
|
+
this.write(UNCHANGED, this.f & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
|
|
505
451
|
}
|
|
506
452
|
/**
|
|
507
453
|
* This is the core part of the reactivity system, which makes sure that the values are updated
|
|
@@ -510,7 +456,7 @@ var Computation = class extends Owner {
|
|
|
510
456
|
*
|
|
511
457
|
* This function will ensure that the value and states we read from the computation are up to date
|
|
512
458
|
*/
|
|
513
|
-
|
|
459
|
+
z() {
|
|
514
460
|
if (this.a === STATE_DISPOSED) {
|
|
515
461
|
throw new Error("Tried to read a disposed computation");
|
|
516
462
|
}
|
|
@@ -520,8 +466,8 @@ var Computation = class extends Owner {
|
|
|
520
466
|
let observerFlags = 0;
|
|
521
467
|
if (this.a === STATE_CHECK) {
|
|
522
468
|
for (let i = 0; i < this.b.length; i++) {
|
|
523
|
-
this.b[i].
|
|
524
|
-
observerFlags |= this.b[i].
|
|
469
|
+
this.b[i].z();
|
|
470
|
+
observerFlags |= this.b[i].f;
|
|
525
471
|
if (this.a === STATE_DIRTY) {
|
|
526
472
|
break;
|
|
527
473
|
}
|
|
@@ -537,27 +483,27 @@ var Computation = class extends Owner {
|
|
|
537
483
|
/**
|
|
538
484
|
* Remove ourselves from the owner graph and the computation graph
|
|
539
485
|
*/
|
|
540
|
-
|
|
486
|
+
A() {
|
|
541
487
|
if (this.a === STATE_DISPOSED)
|
|
542
488
|
return;
|
|
543
489
|
if (this.b)
|
|
544
490
|
removeSourceObservers(this, 0);
|
|
545
|
-
super.
|
|
491
|
+
super.A();
|
|
546
492
|
}
|
|
547
493
|
};
|
|
548
494
|
function loadingState(node) {
|
|
549
|
-
const prevOwner = setOwner(node.
|
|
495
|
+
const prevOwner = setOwner(node.t);
|
|
550
496
|
const options = void 0;
|
|
551
497
|
const computation = new Computation(
|
|
552
498
|
void 0,
|
|
553
499
|
() => {
|
|
554
500
|
track(node);
|
|
555
|
-
node.
|
|
556
|
-
return !!(node.
|
|
501
|
+
node.z();
|
|
502
|
+
return !!(node.f & LOADING_BIT);
|
|
557
503
|
},
|
|
558
504
|
options
|
|
559
505
|
);
|
|
560
|
-
computation.
|
|
506
|
+
computation.P = ERROR_BIT | LOADING_BIT;
|
|
561
507
|
setOwner(prevOwner);
|
|
562
508
|
return computation;
|
|
563
509
|
}
|
|
@@ -571,7 +517,7 @@ function track(computation) {
|
|
|
571
517
|
newSources.push(computation);
|
|
572
518
|
}
|
|
573
519
|
if (updateCheck) {
|
|
574
|
-
updateCheck.
|
|
520
|
+
updateCheck.g = computation.y > currentObserver.y;
|
|
575
521
|
}
|
|
576
522
|
}
|
|
577
523
|
}
|
|
@@ -583,13 +529,13 @@ function update(node) {
|
|
|
583
529
|
try {
|
|
584
530
|
node.dispose(false);
|
|
585
531
|
node.emptyDisposal();
|
|
586
|
-
const result = compute(node, node.
|
|
532
|
+
const result = compute(node, node.B, node);
|
|
587
533
|
node.write(result, newFlags, true);
|
|
588
534
|
} catch (error) {
|
|
589
535
|
if (error instanceof NotReadyError) {
|
|
590
|
-
node.write(UNCHANGED, newFlags | LOADING_BIT | node.
|
|
536
|
+
node.write(UNCHANGED, newFlags | LOADING_BIT | node.f & UNINITIALIZED_BIT);
|
|
591
537
|
} else {
|
|
592
|
-
node.
|
|
538
|
+
node.H(error);
|
|
593
539
|
}
|
|
594
540
|
} finally {
|
|
595
541
|
if (newSources) {
|
|
@@ -606,10 +552,10 @@ function update(node) {
|
|
|
606
552
|
let source;
|
|
607
553
|
for (let i = newSourcesIndex; i < node.b.length; i++) {
|
|
608
554
|
source = node.b[i];
|
|
609
|
-
if (!source.
|
|
610
|
-
source.
|
|
555
|
+
if (!source.e)
|
|
556
|
+
source.e = [node];
|
|
611
557
|
else
|
|
612
|
-
source.
|
|
558
|
+
source.e.push(node);
|
|
613
559
|
}
|
|
614
560
|
} else if (node.b && newSourcesIndex < node.b.length) {
|
|
615
561
|
removeSourceObservers(node, newSourcesIndex);
|
|
@@ -618,7 +564,7 @@ function update(node) {
|
|
|
618
564
|
newSources = prevSources;
|
|
619
565
|
newSourcesIndex = prevSourcesIndex;
|
|
620
566
|
newFlags = prevFlags;
|
|
621
|
-
node.
|
|
567
|
+
node.y = getClock() + 1;
|
|
622
568
|
node.a = STATE_CLEAN;
|
|
623
569
|
}
|
|
624
570
|
}
|
|
@@ -628,12 +574,12 @@ function removeSourceObservers(node, index) {
|
|
|
628
574
|
let swap;
|
|
629
575
|
for (let i = index; i < node.b.length; i++) {
|
|
630
576
|
source = node.b[i];
|
|
631
|
-
if (source.
|
|
632
|
-
swap = source.
|
|
633
|
-
source.
|
|
634
|
-
source.
|
|
635
|
-
if (!source.
|
|
636
|
-
(_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);
|
|
637
583
|
}
|
|
638
584
|
}
|
|
639
585
|
}
|
|
@@ -647,10 +593,10 @@ function untrack(fn) {
|
|
|
647
593
|
}
|
|
648
594
|
function hasUpdated(fn) {
|
|
649
595
|
const current = updateCheck;
|
|
650
|
-
updateCheck = {
|
|
596
|
+
updateCheck = { g: false };
|
|
651
597
|
try {
|
|
652
598
|
fn();
|
|
653
|
-
return updateCheck.
|
|
599
|
+
return updateCheck.g;
|
|
654
600
|
} finally {
|
|
655
601
|
updateCheck = current;
|
|
656
602
|
}
|
|
@@ -658,10 +604,10 @@ function hasUpdated(fn) {
|
|
|
658
604
|
function isPending(fn, loadingValue) {
|
|
659
605
|
const argLength = arguments.length;
|
|
660
606
|
const current = staleCheck;
|
|
661
|
-
staleCheck = {
|
|
607
|
+
staleCheck = { g: false };
|
|
662
608
|
try {
|
|
663
609
|
latest(fn);
|
|
664
|
-
return staleCheck.
|
|
610
|
+
return staleCheck.g;
|
|
665
611
|
} catch (err) {
|
|
666
612
|
if (!(err instanceof NotReadyError))
|
|
667
613
|
return false;
|
|
@@ -708,10 +654,10 @@ function runWithObserver(observer, run) {
|
|
|
708
654
|
if (error instanceof NotReadyError) {
|
|
709
655
|
observer.write(
|
|
710
656
|
UNCHANGED,
|
|
711
|
-
newFlags | LOADING_BIT | observer.
|
|
657
|
+
newFlags | LOADING_BIT | observer.f & UNINITIALIZED_BIT
|
|
712
658
|
);
|
|
713
659
|
} else {
|
|
714
|
-
observer.
|
|
660
|
+
observer.H(error);
|
|
715
661
|
}
|
|
716
662
|
} finally {
|
|
717
663
|
if (newSources) {
|
|
@@ -726,10 +672,10 @@ function runWithObserver(observer, run) {
|
|
|
726
672
|
let source;
|
|
727
673
|
for (let i = newSourcesIndex; i < observer.b.length; i++) {
|
|
728
674
|
source = observer.b[i];
|
|
729
|
-
if (!source.
|
|
730
|
-
source.
|
|
675
|
+
if (!source.e)
|
|
676
|
+
source.e = [observer];
|
|
731
677
|
else
|
|
732
|
-
source.
|
|
678
|
+
source.e.push(observer);
|
|
733
679
|
}
|
|
734
680
|
}
|
|
735
681
|
newSources = prevSources;
|
|
@@ -740,10 +686,10 @@ function runWithObserver(observer, run) {
|
|
|
740
686
|
function compute(owner, fn, observer) {
|
|
741
687
|
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask, prevNotStale = notStale;
|
|
742
688
|
currentObserver = observer;
|
|
743
|
-
currentMask = (observer == null ? void 0 : observer.
|
|
689
|
+
currentMask = (observer == null ? void 0 : observer.P) ?? DEFAULT_FLAGS;
|
|
744
690
|
notStale = true;
|
|
745
691
|
try {
|
|
746
|
-
return fn(observer ? observer.
|
|
692
|
+
return fn(observer ? observer.g : void 0);
|
|
747
693
|
} finally {
|
|
748
694
|
setOwner(prevOwner);
|
|
749
695
|
currentObserver = prevObserver;
|
|
@@ -751,6 +697,68 @@ function compute(owner, fn, observer) {
|
|
|
751
697
|
notStale = prevNotStale;
|
|
752
698
|
}
|
|
753
699
|
}
|
|
700
|
+
function flatten(children, options) {
|
|
701
|
+
try {
|
|
702
|
+
if (typeof children === "function" && !children.length) {
|
|
703
|
+
if (options == null ? void 0 : options.doNotUnwrap)
|
|
704
|
+
return children;
|
|
705
|
+
do {
|
|
706
|
+
children = children();
|
|
707
|
+
} while (typeof children === "function" && !children.length);
|
|
708
|
+
}
|
|
709
|
+
if ((options == null ? void 0 : options.skipNonRendered) && (children == null || children === true || children === false || children === ""))
|
|
710
|
+
return;
|
|
711
|
+
if (Array.isArray(children)) {
|
|
712
|
+
let results = [];
|
|
713
|
+
if (flattenArray(children, results, options)) {
|
|
714
|
+
return () => {
|
|
715
|
+
let nested = [];
|
|
716
|
+
flattenArray(results, nested, { ...options, doNotUnwrap: false });
|
|
717
|
+
return nested;
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
return results;
|
|
721
|
+
}
|
|
722
|
+
return children;
|
|
723
|
+
} catch (e) {
|
|
724
|
+
if ((options == null ? void 0 : options.skipNonRendered) && e instanceof NotReadyError) {
|
|
725
|
+
newFlags |= LOADING_BIT;
|
|
726
|
+
return void 0;
|
|
727
|
+
}
|
|
728
|
+
throw e;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
function flattenArray(children, results = [], options) {
|
|
732
|
+
let notReady = null;
|
|
733
|
+
let needsUnwrap = false;
|
|
734
|
+
for (let i = 0; i < children.length; i++) {
|
|
735
|
+
try {
|
|
736
|
+
let child = children[i];
|
|
737
|
+
if (typeof child === "function" && !child.length) {
|
|
738
|
+
if (options == null ? void 0 : options.doNotUnwrap) {
|
|
739
|
+
results.push(child);
|
|
740
|
+
needsUnwrap = true;
|
|
741
|
+
continue;
|
|
742
|
+
}
|
|
743
|
+
do {
|
|
744
|
+
child = child();
|
|
745
|
+
} while (typeof child === "function" && !child.length);
|
|
746
|
+
}
|
|
747
|
+
if (Array.isArray(child)) {
|
|
748
|
+
needsUnwrap = flattenArray(child, results, options);
|
|
749
|
+
} else if ((options == null ? void 0 : options.skipNonRendered) && (child == null || child === true || child === false || child === "")) {
|
|
750
|
+
} else
|
|
751
|
+
results.push(child);
|
|
752
|
+
} catch (e) {
|
|
753
|
+
if (!(e instanceof NotReadyError))
|
|
754
|
+
throw e;
|
|
755
|
+
notReady = e;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
if (notReady)
|
|
759
|
+
throw notReady;
|
|
760
|
+
return needsUnwrap;
|
|
761
|
+
}
|
|
754
762
|
function createBoundary(fn, queue) {
|
|
755
763
|
const owner = new Owner();
|
|
756
764
|
const parentQueue = owner.h;
|
|
@@ -761,84 +769,84 @@ function createBoundary(fn, queue) {
|
|
|
761
769
|
|
|
762
770
|
// src/core/effect.ts
|
|
763
771
|
var Effect = class extends Computation {
|
|
764
|
-
K;
|
|
765
772
|
L;
|
|
766
|
-
B;
|
|
767
|
-
Q = false;
|
|
768
773
|
M;
|
|
769
|
-
|
|
774
|
+
C;
|
|
775
|
+
R = false;
|
|
776
|
+
N;
|
|
777
|
+
w;
|
|
770
778
|
constructor(initialValue, compute2, effect, error, options) {
|
|
771
779
|
super(initialValue, compute2, options);
|
|
772
|
-
this.
|
|
773
|
-
this.
|
|
774
|
-
this.
|
|
775
|
-
this.
|
|
776
|
-
if (this.
|
|
777
|
-
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);
|
|
778
786
|
}
|
|
779
|
-
this.
|
|
780
|
-
!(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());
|
|
781
789
|
}
|
|
782
790
|
write(value, flags = 0) {
|
|
783
791
|
var _a, _b;
|
|
784
792
|
if (this.a == STATE_DIRTY) {
|
|
785
|
-
const currentFlags = this.
|
|
786
|
-
this.
|
|
787
|
-
if (this.
|
|
788
|
-
(_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);
|
|
789
797
|
}
|
|
790
798
|
}
|
|
791
799
|
if (value === UNCHANGED)
|
|
792
|
-
return this.
|
|
793
|
-
this.
|
|
794
|
-
this.
|
|
800
|
+
return this.g;
|
|
801
|
+
this.g = value;
|
|
802
|
+
this.R = true;
|
|
795
803
|
return value;
|
|
796
804
|
}
|
|
797
805
|
q(state, skipQueue) {
|
|
798
806
|
if (this.a >= state || skipQueue)
|
|
799
807
|
return;
|
|
800
808
|
if (this.a === STATE_CLEAN)
|
|
801
|
-
this.h.enqueue(this.
|
|
809
|
+
this.h.enqueue(this.w, this);
|
|
802
810
|
this.a = state;
|
|
803
811
|
}
|
|
804
|
-
|
|
812
|
+
H(error) {
|
|
805
813
|
var _a, _b, _c;
|
|
806
|
-
(_a = this.
|
|
807
|
-
if (this.
|
|
808
|
-
this.
|
|
809
|
-
(_c = (_b = this.h).R) == null ? void 0 : _c.call(_b, this);
|
|
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);
|
|
810
817
|
}
|
|
811
|
-
|
|
818
|
+
this.f = ERROR_BIT;
|
|
819
|
+
if (this.w === EFFECT_USER) {
|
|
812
820
|
try {
|
|
813
|
-
return this.
|
|
821
|
+
return this.M ? this.C = this.M(error) : console.error(new EffectError(this.L, error));
|
|
814
822
|
} catch (e) {
|
|
815
823
|
error = e;
|
|
816
824
|
}
|
|
817
825
|
}
|
|
818
826
|
this.handleError(error);
|
|
819
827
|
}
|
|
820
|
-
|
|
828
|
+
A() {
|
|
821
829
|
var _a;
|
|
822
830
|
if (this.a === STATE_DISPOSED)
|
|
823
831
|
return;
|
|
824
|
-
this.K = void 0;
|
|
825
|
-
this.M = void 0;
|
|
826
832
|
this.L = void 0;
|
|
827
|
-
|
|
828
|
-
this.
|
|
829
|
-
|
|
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();
|
|
830
838
|
}
|
|
831
|
-
|
|
839
|
+
U() {
|
|
832
840
|
var _a;
|
|
833
|
-
if (this.
|
|
834
|
-
(_a = this.
|
|
841
|
+
if (this.R && this.a !== STATE_DISPOSED) {
|
|
842
|
+
(_a = this.C) == null ? void 0 : _a.call(this);
|
|
835
843
|
try {
|
|
836
|
-
this.
|
|
844
|
+
this.C = this.L(this.g, this.N);
|
|
837
845
|
} catch (e) {
|
|
838
846
|
this.handleError(e);
|
|
839
847
|
} finally {
|
|
840
|
-
this.
|
|
841
|
-
this.
|
|
848
|
+
this.N = this.g;
|
|
849
|
+
this.R = false;
|
|
842
850
|
}
|
|
843
851
|
}
|
|
844
852
|
}
|
|
@@ -846,10 +854,10 @@ var Effect = class extends Computation {
|
|
|
846
854
|
var EagerComputation = class extends Computation {
|
|
847
855
|
constructor(initialValue, compute2, options) {
|
|
848
856
|
super(initialValue, compute2, options);
|
|
849
|
-
!(options == null ? void 0 : options.defer) && this.
|
|
857
|
+
!(options == null ? void 0 : options.defer) && this.z();
|
|
850
858
|
}
|
|
851
859
|
q(state, skipQueue) {
|
|
852
|
-
if (this.a >= state && !this.
|
|
860
|
+
if (this.a >= state && !this.K)
|
|
853
861
|
return;
|
|
854
862
|
if (this.a === STATE_CLEAN && !skipQueue)
|
|
855
863
|
this.h.enqueue(EFFECT_PURE, this);
|
|
@@ -861,7 +869,7 @@ var ProjectionComputation = class extends Computation {
|
|
|
861
869
|
super(null, compute2);
|
|
862
870
|
}
|
|
863
871
|
q(state, skipQueue) {
|
|
864
|
-
if (this.a >= state && !this.
|
|
872
|
+
if (this.a >= state && !this.K)
|
|
865
873
|
return;
|
|
866
874
|
if (this.a === STATE_CLEAN && !skipQueue)
|
|
867
875
|
this.h.enqueue(EFFECT_PURE, this);
|
|
@@ -871,26 +879,26 @@ var ProjectionComputation = class extends Computation {
|
|
|
871
879
|
|
|
872
880
|
// src/core/suspense.ts
|
|
873
881
|
var SuspenseQueue = class extends Queue {
|
|
874
|
-
|
|
882
|
+
c = /* @__PURE__ */ new Set();
|
|
875
883
|
o = false;
|
|
876
|
-
|
|
884
|
+
T = new Computation(false, null);
|
|
877
885
|
run(type) {
|
|
878
886
|
if (type && this.o)
|
|
879
887
|
return;
|
|
880
888
|
return super.run(type);
|
|
881
889
|
}
|
|
882
|
-
|
|
883
|
-
if (node.
|
|
884
|
-
this.
|
|
890
|
+
S(node) {
|
|
891
|
+
if (node.f & LOADING_BIT) {
|
|
892
|
+
this.c.add(node);
|
|
885
893
|
if (!this.o) {
|
|
886
894
|
this.o = true;
|
|
887
|
-
this.
|
|
895
|
+
this.T.write(true);
|
|
888
896
|
}
|
|
889
897
|
} else {
|
|
890
|
-
this.
|
|
891
|
-
if (this.
|
|
898
|
+
this.c.delete(node);
|
|
899
|
+
if (this.c.size === 0) {
|
|
892
900
|
this.o = false;
|
|
893
|
-
this.
|
|
901
|
+
this.T.write(false);
|
|
894
902
|
}
|
|
895
903
|
}
|
|
896
904
|
}
|
|
@@ -898,13 +906,13 @@ var SuspenseQueue = class extends Queue {
|
|
|
898
906
|
var LiveComputation = class extends EagerComputation {
|
|
899
907
|
write(value, flags = 0) {
|
|
900
908
|
var _a, _b;
|
|
901
|
-
const currentFlags = this.
|
|
909
|
+
const currentFlags = this.f;
|
|
902
910
|
const dirty = this.a === STATE_DIRTY;
|
|
903
911
|
super.write(value, flags);
|
|
904
912
|
if (dirty && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
905
|
-
(_b = (_a = this.h).
|
|
913
|
+
(_b = (_a = this.h).S) == null ? void 0 : _b.call(_a, this);
|
|
906
914
|
}
|
|
907
|
-
return this.
|
|
915
|
+
return this.g;
|
|
908
916
|
}
|
|
909
917
|
};
|
|
910
918
|
function createSuspense(fn, fallback) {
|
|
@@ -913,7 +921,7 @@ function createSuspense(fn, fallback) {
|
|
|
913
921
|
const child = new Computation(null, fn);
|
|
914
922
|
return new LiveComputation(null, () => flatten(child.wait()));
|
|
915
923
|
}, queue);
|
|
916
|
-
const equality = new Computation(null, () => queue.
|
|
924
|
+
const equality = new Computation(null, () => queue.T.read() || queue.o);
|
|
917
925
|
const comp = new Computation(null, () => equality.read() ? fallback() : tree.read());
|
|
918
926
|
return comp.read.bind(comp);
|
|
919
927
|
}
|
|
@@ -945,10 +953,10 @@ function createMemo(compute2, value, options) {
|
|
|
945
953
|
var _a, _b, _c;
|
|
946
954
|
if (node) {
|
|
947
955
|
resolvedValue = node.wait();
|
|
948
|
-
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) {
|
|
949
957
|
node.dispose();
|
|
950
958
|
node = void 0;
|
|
951
|
-
} else if (!node.
|
|
959
|
+
} else if (!node.t && !((_c = node.e) == null ? void 0 : _c.length)) {
|
|
952
960
|
node.dispose();
|
|
953
961
|
node.a = STATE_DIRTY;
|
|
954
962
|
}
|
|
@@ -960,10 +968,10 @@ function createAsync(compute2, value, options) {
|
|
|
960
968
|
let uninitialized = value === void 0;
|
|
961
969
|
const lhs = new EagerComputation(
|
|
962
970
|
{
|
|
963
|
-
|
|
971
|
+
g: value
|
|
964
972
|
},
|
|
965
973
|
(p) => {
|
|
966
|
-
const value2 = p == null ? void 0 : p.
|
|
974
|
+
const value2 = p == null ? void 0 : p.g;
|
|
967
975
|
const source = compute2(value2);
|
|
968
976
|
const isPromise = source instanceof Promise;
|
|
969
977
|
const iterator = source[Symbol.asyncIterator];
|
|
@@ -972,13 +980,13 @@ function createAsync(compute2, value, options) {
|
|
|
972
980
|
wait() {
|
|
973
981
|
return source;
|
|
974
982
|
},
|
|
975
|
-
|
|
983
|
+
g: source
|
|
976
984
|
};
|
|
977
985
|
}
|
|
978
986
|
const signal = new Computation(value2, null, options);
|
|
979
987
|
const w = signal.wait;
|
|
980
988
|
signal.wait = function() {
|
|
981
|
-
if (signal.
|
|
989
|
+
if (signal.f & ERROR_BIT && signal.y <= getClock()) {
|
|
982
990
|
lhs.q(STATE_DIRTY);
|
|
983
991
|
throw new NotReadyError();
|
|
984
992
|
}
|
|
@@ -993,7 +1001,7 @@ function createAsync(compute2, value, options) {
|
|
|
993
1001
|
},
|
|
994
1002
|
(error) => {
|
|
995
1003
|
uninitialized = true;
|
|
996
|
-
signal.
|
|
1004
|
+
signal.H(error);
|
|
997
1005
|
}
|
|
998
1006
|
);
|
|
999
1007
|
} else {
|
|
@@ -1056,7 +1064,7 @@ function createErrorBoundary(fn, fallback) {
|
|
|
1056
1064
|
);
|
|
1057
1065
|
nodes.add(node);
|
|
1058
1066
|
if (nodes.size === 1)
|
|
1059
|
-
error.write({
|
|
1067
|
+
error.write({ G: err });
|
|
1060
1068
|
}
|
|
1061
1069
|
owner.m = owner.m ? [handler, ...owner.m] : [handler];
|
|
1062
1070
|
const guarded = compute(
|
|
@@ -1064,7 +1072,7 @@ function createErrorBoundary(fn, fallback) {
|
|
|
1064
1072
|
() => {
|
|
1065
1073
|
const c = new Computation(void 0, fn);
|
|
1066
1074
|
const f = new EagerComputation(void 0, () => flatten(c.read()), { defer: true });
|
|
1067
|
-
f.
|
|
1075
|
+
f.H = function(error2) {
|
|
1068
1076
|
this.handleError(error2);
|
|
1069
1077
|
};
|
|
1070
1078
|
return f;
|
|
@@ -1077,12 +1085,12 @@ function createErrorBoundary(fn, fallback) {
|
|
|
1077
1085
|
if (!error.read())
|
|
1078
1086
|
return resolved;
|
|
1079
1087
|
}
|
|
1080
|
-
return fallback(error.read().
|
|
1088
|
+
return fallback(error.read().G, () => {
|
|
1081
1089
|
var _a;
|
|
1082
1090
|
incrementClock();
|
|
1083
1091
|
for (let node of nodes) {
|
|
1084
1092
|
node.a = STATE_DIRTY;
|
|
1085
|
-
(_a = node.h) == null ? void 0 : _a.enqueue(node.
|
|
1093
|
+
(_a = node.h) == null ? void 0 : _a.enqueue(node.w, node);
|
|
1086
1094
|
}
|
|
1087
1095
|
});
|
|
1088
1096
|
});
|
|
@@ -1107,12 +1115,15 @@ function resolve(fn) {
|
|
|
1107
1115
|
|
|
1108
1116
|
// src/store/projection.ts
|
|
1109
1117
|
function createProjection(fn, initialValue = {}) {
|
|
1110
|
-
const [store
|
|
1118
|
+
const [store] = createStore(fn, initialValue);
|
|
1119
|
+
return store;
|
|
1120
|
+
}
|
|
1121
|
+
function wrapProjection(fn, store, setStore) {
|
|
1111
1122
|
const node = new ProjectionComputation(() => {
|
|
1112
1123
|
setStore(fn);
|
|
1113
1124
|
});
|
|
1114
1125
|
const wrapped = /* @__PURE__ */ new WeakMap();
|
|
1115
|
-
return wrap(store, node, wrapped);
|
|
1126
|
+
return [wrap(store, node, wrapped), setStore];
|
|
1116
1127
|
}
|
|
1117
1128
|
function wrap(source, node, wrapped) {
|
|
1118
1129
|
if (wrapped.has(source))
|
|
@@ -1250,7 +1261,7 @@ var proxyTraps = {
|
|
|
1250
1261
|
return desc.get.call(receiver);
|
|
1251
1262
|
}
|
|
1252
1263
|
if (Writing.has(storeValue)) {
|
|
1253
|
-
const value2 = tracked ? tracked.
|
|
1264
|
+
const value2 = tracked ? tracked.g : storeValue[property];
|
|
1254
1265
|
return isWrappable(value2) ? (Writing.add(value2[$RAW] || value2), wrap2(value2)) : value2;
|
|
1255
1266
|
}
|
|
1256
1267
|
let value = tracked ? nodes[property].read() : storeValue[property];
|
|
@@ -1311,10 +1322,8 @@ function setProperty(state, property, value, deleting = false) {
|
|
|
1311
1322
|
}
|
|
1312
1323
|
function createStore(first, second) {
|
|
1313
1324
|
const derived = typeof first === "function", store = derived ? second : first;
|
|
1314
|
-
if (derived)
|
|
1315
|
-
return createProjection(first, store);
|
|
1316
1325
|
const unwrappedStore = unwrap(store, false);
|
|
1317
|
-
|
|
1326
|
+
let wrappedStore = wrap2(unwrappedStore);
|
|
1318
1327
|
const setStore = (fn) => {
|
|
1319
1328
|
try {
|
|
1320
1329
|
Writing.add(unwrappedStore);
|
|
@@ -1323,6 +1332,8 @@ function createStore(first, second) {
|
|
|
1323
1332
|
Writing.clear();
|
|
1324
1333
|
}
|
|
1325
1334
|
};
|
|
1335
|
+
if (derived)
|
|
1336
|
+
return wrapProjection(first, wrappedStore, setStore);
|
|
1326
1337
|
return [wrappedStore, setStore];
|
|
1327
1338
|
}
|
|
1328
1339
|
|
|
@@ -1439,7 +1450,7 @@ function reconcile(value, key) {
|
|
|
1439
1450
|
};
|
|
1440
1451
|
}
|
|
1441
1452
|
|
|
1442
|
-
// src/store/
|
|
1453
|
+
// src/store/utils.ts
|
|
1443
1454
|
function trueFn() {
|
|
1444
1455
|
return true;
|
|
1445
1456
|
}
|
|
@@ -1591,73 +1602,73 @@ function omit(props, ...keys) {
|
|
|
1591
1602
|
function mapArray(list, map, options) {
|
|
1592
1603
|
const keyFn = typeof (options == null ? void 0 : options.keyed) === "function" ? options.keyed : void 0;
|
|
1593
1604
|
return updateKeyedMap.bind({
|
|
1594
|
-
|
|
1605
|
+
I: new Owner(),
|
|
1595
1606
|
i: 0,
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1607
|
+
Y: list,
|
|
1608
|
+
x: [],
|
|
1609
|
+
D: map,
|
|
1610
|
+
d: [],
|
|
1611
|
+
c: [],
|
|
1612
|
+
E: keyFn,
|
|
1602
1613
|
j: keyFn || (options == null ? void 0 : options.keyed) === false ? [] : void 0,
|
|
1603
1614
|
k: map.length > 1 ? [] : void 0,
|
|
1604
1615
|
o: options == null ? void 0 : options.fallback
|
|
1605
1616
|
});
|
|
1606
1617
|
}
|
|
1607
1618
|
function updateKeyedMap() {
|
|
1608
|
-
const newItems = this.
|
|
1619
|
+
const newItems = this.Y() || [], newLen = newItems.length;
|
|
1609
1620
|
newItems[$TRACK];
|
|
1610
|
-
runWithOwner(this.
|
|
1621
|
+
runWithOwner(this.I, () => {
|
|
1611
1622
|
let i, j, mapper = this.j ? () => {
|
|
1612
1623
|
this.j[j] = new Computation(newItems[j], null);
|
|
1613
1624
|
this.k && (this.k[j] = new Computation(j, null));
|
|
1614
|
-
return this.
|
|
1625
|
+
return this.D(
|
|
1615
1626
|
Computation.prototype.read.bind(this.j[j]),
|
|
1616
1627
|
this.k ? Computation.prototype.read.bind(this.k[j]) : void 0
|
|
1617
1628
|
);
|
|
1618
1629
|
} : this.k ? () => {
|
|
1619
1630
|
const item = newItems[j];
|
|
1620
1631
|
this.k[j] = new Computation(j, null);
|
|
1621
|
-
return this.
|
|
1632
|
+
return this.D(() => item, Computation.prototype.read.bind(this.k[j]));
|
|
1622
1633
|
} : () => {
|
|
1623
1634
|
const item = newItems[j];
|
|
1624
|
-
return this.
|
|
1635
|
+
return this.D(() => item);
|
|
1625
1636
|
};
|
|
1626
1637
|
if (newLen === 0) {
|
|
1627
1638
|
if (this.i !== 0) {
|
|
1628
|
-
this.
|
|
1629
|
-
this.
|
|
1630
|
-
this.
|
|
1631
|
-
this.
|
|
1639
|
+
this.I.dispose(false);
|
|
1640
|
+
this.c = [];
|
|
1641
|
+
this.x = [];
|
|
1642
|
+
this.d = [];
|
|
1632
1643
|
this.i = 0;
|
|
1633
1644
|
this.j && (this.j = []);
|
|
1634
1645
|
this.k && (this.k = []);
|
|
1635
1646
|
}
|
|
1636
|
-
if (this.o && !this.
|
|
1637
|
-
this.
|
|
1638
|
-
this.
|
|
1647
|
+
if (this.o && !this.d[0]) {
|
|
1648
|
+
this.d[0] = compute(
|
|
1649
|
+
this.c[0] = new Owner(),
|
|
1639
1650
|
this.o,
|
|
1640
1651
|
null
|
|
1641
1652
|
);
|
|
1642
1653
|
}
|
|
1643
1654
|
} else if (this.i === 0) {
|
|
1644
|
-
if (this.
|
|
1645
|
-
this.
|
|
1646
|
-
this.
|
|
1655
|
+
if (this.c[0])
|
|
1656
|
+
this.c[0].dispose();
|
|
1657
|
+
this.d = new Array(newLen);
|
|
1647
1658
|
for (j = 0; j < newLen; j++) {
|
|
1648
|
-
this.
|
|
1649
|
-
this.
|
|
1659
|
+
this.x[j] = newItems[j];
|
|
1660
|
+
this.d[j] = compute(this.c[j] = new Owner(), mapper, null);
|
|
1650
1661
|
}
|
|
1651
1662
|
this.i = newLen;
|
|
1652
1663
|
} else {
|
|
1653
1664
|
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;
|
|
1654
|
-
for (start = 0, end = Math.min(this.i, newLen); start < end && (this.
|
|
1665
|
+
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++) {
|
|
1655
1666
|
if (this.j)
|
|
1656
1667
|
this.j[start].write(newItems[start]);
|
|
1657
1668
|
}
|
|
1658
|
-
for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.
|
|
1659
|
-
temp[newEnd] = this.
|
|
1660
|
-
tempNodes[newEnd] = this.
|
|
1669
|
+
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--) {
|
|
1670
|
+
temp[newEnd] = this.d[end];
|
|
1671
|
+
tempNodes[newEnd] = this.c[end];
|
|
1661
1672
|
tempRows && (tempRows[newEnd] = this.j[end]);
|
|
1662
1673
|
tempIndexes && (tempIndexes[newEnd] = this.k[end]);
|
|
1663
1674
|
}
|
|
@@ -1665,29 +1676,29 @@ function updateKeyedMap() {
|
|
|
1665
1676
|
newIndicesNext = new Array(newEnd + 1);
|
|
1666
1677
|
for (j = newEnd; j >= start; j--) {
|
|
1667
1678
|
item = newItems[j];
|
|
1668
|
-
key = this.
|
|
1679
|
+
key = this.E ? this.E(item) : item;
|
|
1669
1680
|
i = newIndices.get(key);
|
|
1670
1681
|
newIndicesNext[j] = i === void 0 ? -1 : i;
|
|
1671
1682
|
newIndices.set(key, j);
|
|
1672
1683
|
}
|
|
1673
1684
|
for (i = start; i <= end; i++) {
|
|
1674
|
-
item = this.
|
|
1675
|
-
key = this.
|
|
1685
|
+
item = this.x[i];
|
|
1686
|
+
key = this.E ? this.E(item) : item;
|
|
1676
1687
|
j = newIndices.get(key);
|
|
1677
1688
|
if (j !== void 0 && j !== -1) {
|
|
1678
|
-
temp[j] = this.
|
|
1679
|
-
tempNodes[j] = this.
|
|
1689
|
+
temp[j] = this.d[i];
|
|
1690
|
+
tempNodes[j] = this.c[i];
|
|
1680
1691
|
tempRows && (tempRows[j] = this.j[i]);
|
|
1681
1692
|
tempIndexes && (tempIndexes[j] = this.k[i]);
|
|
1682
1693
|
j = newIndicesNext[j];
|
|
1683
1694
|
newIndices.set(key, j);
|
|
1684
1695
|
} else
|
|
1685
|
-
this.
|
|
1696
|
+
this.c[i].dispose();
|
|
1686
1697
|
}
|
|
1687
1698
|
for (j = start; j < newLen; j++) {
|
|
1688
1699
|
if (j in temp) {
|
|
1689
|
-
this.
|
|
1690
|
-
this.
|
|
1700
|
+
this.d[j] = temp[j];
|
|
1701
|
+
this.c[j] = tempNodes[j];
|
|
1691
1702
|
if (tempRows) {
|
|
1692
1703
|
this.j[j] = tempRows[j];
|
|
1693
1704
|
this.j[j].write(newItems[j]);
|
|
@@ -1697,60 +1708,90 @@ function updateKeyedMap() {
|
|
|
1697
1708
|
this.k[j].write(j);
|
|
1698
1709
|
}
|
|
1699
1710
|
} else {
|
|
1700
|
-
this.
|
|
1711
|
+
this.d[j] = compute(this.c[j] = new Owner(), mapper, null);
|
|
1701
1712
|
}
|
|
1702
1713
|
}
|
|
1703
|
-
this.
|
|
1704
|
-
this.
|
|
1714
|
+
this.d = this.d.slice(0, this.i = newLen);
|
|
1715
|
+
this.x = newItems.slice(0);
|
|
1705
1716
|
}
|
|
1706
1717
|
});
|
|
1707
|
-
return this.
|
|
1718
|
+
return this.d;
|
|
1708
1719
|
}
|
|
1709
1720
|
function repeat(count, map, options) {
|
|
1710
1721
|
return updateRepeat.bind({
|
|
1711
|
-
|
|
1722
|
+
I: new Owner(),
|
|
1712
1723
|
i: 0,
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1724
|
+
r: 0,
|
|
1725
|
+
Z: count,
|
|
1726
|
+
D: map,
|
|
1727
|
+
c: [],
|
|
1728
|
+
d: [],
|
|
1729
|
+
_: options == null ? void 0 : options.from,
|
|
1717
1730
|
o: options == null ? void 0 : options.fallback
|
|
1718
1731
|
});
|
|
1719
1732
|
}
|
|
1720
1733
|
function updateRepeat() {
|
|
1721
|
-
|
|
1722
|
-
|
|
1734
|
+
var _a;
|
|
1735
|
+
const newLen = this.Z();
|
|
1736
|
+
const from = ((_a = this._) == null ? void 0 : _a.call(this)) || 0;
|
|
1737
|
+
runWithOwner(this.I, () => {
|
|
1723
1738
|
if (newLen === 0) {
|
|
1724
1739
|
if (this.i !== 0) {
|
|
1725
|
-
this.
|
|
1726
|
-
this.
|
|
1727
|
-
this.
|
|
1740
|
+
this.I.dispose(false);
|
|
1741
|
+
this.c = [];
|
|
1742
|
+
this.d = [];
|
|
1728
1743
|
this.i = 0;
|
|
1729
1744
|
}
|
|
1730
|
-
if (this.o && !this.
|
|
1731
|
-
this.
|
|
1732
|
-
this.
|
|
1745
|
+
if (this.o && !this.d[0]) {
|
|
1746
|
+
this.d[0] = compute(
|
|
1747
|
+
this.c[0] = new Owner(),
|
|
1733
1748
|
this.o,
|
|
1734
1749
|
null
|
|
1735
1750
|
);
|
|
1736
1751
|
}
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1752
|
+
return;
|
|
1753
|
+
}
|
|
1754
|
+
const to = from + newLen;
|
|
1755
|
+
const prevTo = this.r + this.i;
|
|
1756
|
+
if (this.i === 0 && this.c[0])
|
|
1757
|
+
this.c[0].dispose();
|
|
1758
|
+
for (let i = to; i < prevTo; i++)
|
|
1759
|
+
this.c[i - this.r].dispose();
|
|
1760
|
+
if (this.r < from) {
|
|
1761
|
+
let i = this.r;
|
|
1762
|
+
while (i < from && i < this.i)
|
|
1763
|
+
this.c[i++].dispose();
|
|
1764
|
+
this.c.splice(0, from - this.r);
|
|
1765
|
+
this.d.splice(0, from - this.r);
|
|
1766
|
+
} else if (this.r > from) {
|
|
1767
|
+
let i = prevTo - this.r - 1;
|
|
1768
|
+
let difference = this.r - from;
|
|
1769
|
+
this.c.length = this.d.length = newLen;
|
|
1770
|
+
while (i >= difference) {
|
|
1771
|
+
this.c[i] = this.c[i - difference];
|
|
1772
|
+
this.d[i] = this.d[i - difference];
|
|
1773
|
+
i--;
|
|
1774
|
+
}
|
|
1775
|
+
for (let i2 = 0; i2 < difference; i2++) {
|
|
1776
|
+
this.d[i2] = compute(
|
|
1777
|
+
this.c[i2] = new Owner(),
|
|
1778
|
+
() => this.D(i2 + from),
|
|
1744
1779
|
null
|
|
1745
1780
|
);
|
|
1746
1781
|
}
|
|
1747
|
-
for (let i = newLen; i < this.i; i++)
|
|
1748
|
-
this.f[i].dispose();
|
|
1749
|
-
this.g = this.g.slice(0, newLen);
|
|
1750
|
-
this.i = newLen;
|
|
1751
1782
|
}
|
|
1783
|
+
for (let i = prevTo; i < to; i++) {
|
|
1784
|
+
this.d[i - from] = compute(
|
|
1785
|
+
this.c[i - from] = new Owner(),
|
|
1786
|
+
() => this.D(i),
|
|
1787
|
+
null
|
|
1788
|
+
);
|
|
1789
|
+
}
|
|
1790
|
+
this.d = this.d.slice(0, newLen);
|
|
1791
|
+
this.r = from;
|
|
1792
|
+
this.i = newLen;
|
|
1752
1793
|
});
|
|
1753
|
-
return this.
|
|
1794
|
+
return this.d;
|
|
1754
1795
|
}
|
|
1755
1796
|
function compare(key, a, b) {
|
|
1756
1797
|
return key ? key(a) === key(b) : true;
|