@solidjs/signals 0.2.3 → 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 +48 -16
- package/dist/node.cjs +302 -269
- package/dist/prod.js +301 -269
- package/dist/types/map.d.ts +1 -0
- package/dist/types/store/projection.d.ts +3 -1
- package/package.json +1 -1
package/dist/prod.js
CHANGED
|
@@ -43,42 +43,42 @@ function schedule() {
|
|
|
43
43
|
if (scheduled)
|
|
44
44
|
return;
|
|
45
45
|
scheduled = true;
|
|
46
|
-
if (!globalQueue.
|
|
46
|
+
if (!globalQueue.J)
|
|
47
47
|
queueMicrotask(flushSync);
|
|
48
48
|
}
|
|
49
49
|
var Queue = class {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
J = false;
|
|
51
|
+
s = [[], [], []];
|
|
52
|
+
F = [];
|
|
53
53
|
created = clock;
|
|
54
54
|
enqueue(type, node) {
|
|
55
|
-
this.
|
|
55
|
+
this.s[0].push(node);
|
|
56
56
|
if (type)
|
|
57
|
-
this.
|
|
57
|
+
this.s[type].push(node);
|
|
58
58
|
schedule();
|
|
59
59
|
}
|
|
60
60
|
run(type) {
|
|
61
|
-
if (this.
|
|
61
|
+
if (this.s[type].length) {
|
|
62
62
|
if (type === EFFECT_PURE) {
|
|
63
|
-
runPureQueue(this.
|
|
64
|
-
this.
|
|
63
|
+
runPureQueue(this.s[type]);
|
|
64
|
+
this.s[type] = [];
|
|
65
65
|
} else {
|
|
66
|
-
const effects = this.
|
|
67
|
-
this.
|
|
66
|
+
const effects = this.s[type];
|
|
67
|
+
this.s[type] = [];
|
|
68
68
|
runEffectQueue(effects);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
let rerun = false;
|
|
72
|
-
for (let i = 0; i < this.
|
|
73
|
-
rerun = this.
|
|
72
|
+
for (let i = 0; i < this.F.length; i++) {
|
|
73
|
+
rerun = this.F[i].run(type) || rerun;
|
|
74
74
|
}
|
|
75
|
-
if (type === EFFECT_PURE && this.
|
|
75
|
+
if (type === EFFECT_PURE && this.s[type].length)
|
|
76
76
|
return true;
|
|
77
77
|
}
|
|
78
78
|
flush() {
|
|
79
|
-
if (this.
|
|
79
|
+
if (this.J)
|
|
80
80
|
return;
|
|
81
|
-
this.
|
|
81
|
+
this.J = true;
|
|
82
82
|
try {
|
|
83
83
|
while (this.run(EFFECT_PURE)) {
|
|
84
84
|
}
|
|
@@ -87,16 +87,16 @@ var Queue = class {
|
|
|
87
87
|
this.run(EFFECT_RENDER);
|
|
88
88
|
this.run(EFFECT_USER);
|
|
89
89
|
} finally {
|
|
90
|
-
this.
|
|
90
|
+
this.J = false;
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
addChild(child) {
|
|
94
|
-
this.
|
|
94
|
+
this.F.push(child);
|
|
95
95
|
}
|
|
96
96
|
removeChild(child) {
|
|
97
|
-
const index = this.
|
|
97
|
+
const index = this.F.indexOf(child);
|
|
98
98
|
if (index >= 0)
|
|
99
|
-
this.
|
|
99
|
+
this.F.splice(index, 1);
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
102
|
var globalQueue = new Queue();
|
|
@@ -107,14 +107,14 @@ function flushSync() {
|
|
|
107
107
|
}
|
|
108
108
|
function runTop(node) {
|
|
109
109
|
const ancestors = [];
|
|
110
|
-
for (let current = node; current !== null; current = current.
|
|
110
|
+
for (let current = node; current !== null; current = current.t) {
|
|
111
111
|
if (current.a !== STATE_CLEAN) {
|
|
112
112
|
ancestors.push(current);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
116
116
|
if (ancestors[i].a !== STATE_DISPOSED)
|
|
117
|
-
ancestors[i].
|
|
117
|
+
ancestors[i].z();
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
function runPureQueue(queue) {
|
|
@@ -125,7 +125,7 @@ function runPureQueue(queue) {
|
|
|
125
125
|
}
|
|
126
126
|
function runEffectQueue(queue) {
|
|
127
127
|
for (let i = 0; i < queue.length; i++)
|
|
128
|
-
queue[i].
|
|
128
|
+
queue[i].U();
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
// src/core/utils.ts
|
|
@@ -148,9 +148,9 @@ var Owner = class {
|
|
|
148
148
|
// We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
|
|
149
149
|
// However, the children are actually added in reverse creation order
|
|
150
150
|
// See comment at the top of the file for an example of the _nextSibling traversal
|
|
151
|
-
s = null;
|
|
152
|
-
n = null;
|
|
153
151
|
t = null;
|
|
152
|
+
n = null;
|
|
153
|
+
u = null;
|
|
154
154
|
a = STATE_CLEAN;
|
|
155
155
|
l = null;
|
|
156
156
|
p = defaultContext;
|
|
@@ -161,10 +161,10 @@ var Owner = class {
|
|
|
161
161
|
currentOwner.append(this);
|
|
162
162
|
}
|
|
163
163
|
append(child) {
|
|
164
|
-
child.s = this;
|
|
165
164
|
child.t = this;
|
|
165
|
+
child.u = this;
|
|
166
166
|
if (this.n)
|
|
167
|
-
this.n.
|
|
167
|
+
this.n.u = child;
|
|
168
168
|
child.n = this.n;
|
|
169
169
|
this.n = child;
|
|
170
170
|
if (child.p !== this.p) {
|
|
@@ -179,26 +179,26 @@ var Owner = class {
|
|
|
179
179
|
dispose(self = true) {
|
|
180
180
|
if (this.a === STATE_DISPOSED)
|
|
181
181
|
return;
|
|
182
|
-
let head = self ? this.
|
|
183
|
-
while (current && current.
|
|
182
|
+
let head = self ? this.u || this.t : this, current = this.n, next = null;
|
|
183
|
+
while (current && current.t === this) {
|
|
184
184
|
current.dispose(true);
|
|
185
|
-
current.
|
|
185
|
+
current.A();
|
|
186
186
|
next = current.n;
|
|
187
187
|
current.n = null;
|
|
188
188
|
current = next;
|
|
189
189
|
}
|
|
190
190
|
if (self)
|
|
191
|
-
this.
|
|
191
|
+
this.A();
|
|
192
192
|
if (current)
|
|
193
|
-
current.
|
|
193
|
+
current.u = !self ? this : this.u;
|
|
194
194
|
if (head)
|
|
195
195
|
head.n = current;
|
|
196
196
|
}
|
|
197
|
-
|
|
198
|
-
if (this.
|
|
199
|
-
this.
|
|
200
|
-
this.s = null;
|
|
197
|
+
A() {
|
|
198
|
+
if (this.u)
|
|
199
|
+
this.u.n = null;
|
|
201
200
|
this.t = null;
|
|
201
|
+
this.u = null;
|
|
202
202
|
this.p = defaultContext;
|
|
203
203
|
this.m = null;
|
|
204
204
|
this.a = STATE_DISPOSED;
|
|
@@ -296,48 +296,48 @@ function getObserver() {
|
|
|
296
296
|
var UNCHANGED = Symbol(0);
|
|
297
297
|
var Computation = class extends Owner {
|
|
298
298
|
b = null;
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
299
|
+
e = null;
|
|
300
|
+
g;
|
|
301
|
+
G;
|
|
302
|
+
B;
|
|
303
303
|
// Used in __DEV__ mode, hopefully removed in production
|
|
304
|
-
|
|
304
|
+
$;
|
|
305
305
|
// Using false is an optimization as an alternative to _equals: () => false
|
|
306
306
|
// which could enable more efficient DIRTY notification
|
|
307
|
-
|
|
308
|
-
|
|
307
|
+
O = isEqual;
|
|
308
|
+
V;
|
|
309
309
|
/** Whether the computation is an error or has ancestors that are unresolved */
|
|
310
|
-
|
|
310
|
+
f = 0;
|
|
311
311
|
/** Which flags raised by sources are handled, vs. being passed through. */
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
312
|
+
P = DEFAULT_FLAGS;
|
|
313
|
+
Q = null;
|
|
314
|
+
y = -1;
|
|
315
|
+
K = false;
|
|
316
316
|
constructor(initialValue, compute2, options) {
|
|
317
317
|
super(compute2 === null);
|
|
318
|
-
this.
|
|
318
|
+
this.B = compute2;
|
|
319
319
|
this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
|
|
320
|
-
this.
|
|
321
|
-
this.
|
|
320
|
+
this.f = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
|
|
321
|
+
this.g = initialValue;
|
|
322
322
|
if (options?.equals !== void 0)
|
|
323
|
-
this.
|
|
323
|
+
this.O = options.equals;
|
|
324
324
|
if (options?.unobserved)
|
|
325
|
-
this.
|
|
325
|
+
this.V = options?.unobserved;
|
|
326
326
|
}
|
|
327
|
-
|
|
328
|
-
if (this.
|
|
329
|
-
if (this.
|
|
327
|
+
W() {
|
|
328
|
+
if (this.B) {
|
|
329
|
+
if (this.f & ERROR_BIT && this.y <= getClock())
|
|
330
330
|
update(this);
|
|
331
331
|
else
|
|
332
|
-
this.
|
|
332
|
+
this.z();
|
|
333
333
|
}
|
|
334
|
-
if (!this.
|
|
334
|
+
if (!this.B || this.b?.length)
|
|
335
335
|
track(this);
|
|
336
|
-
newFlags |= this.
|
|
337
|
-
if (this.
|
|
338
|
-
throw this.
|
|
336
|
+
newFlags |= this.f & ~currentMask;
|
|
337
|
+
if (this.f & ERROR_BIT) {
|
|
338
|
+
throw this.G;
|
|
339
339
|
} else {
|
|
340
|
-
return this.
|
|
340
|
+
return this.g;
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
343
|
/**
|
|
@@ -345,7 +345,7 @@ var Computation = class extends Owner {
|
|
|
345
345
|
* Automatically re-executes the surrounding computation when the value changes
|
|
346
346
|
*/
|
|
347
347
|
read() {
|
|
348
|
-
return this.
|
|
348
|
+
return this.W();
|
|
349
349
|
}
|
|
350
350
|
/**
|
|
351
351
|
* Return the current value of this computation
|
|
@@ -355,15 +355,15 @@ var Computation = class extends Owner {
|
|
|
355
355
|
* before continuing
|
|
356
356
|
*/
|
|
357
357
|
wait() {
|
|
358
|
-
if (this.
|
|
358
|
+
if (this.B && this.f & ERROR_BIT && this.y <= getClock()) {
|
|
359
359
|
update(this);
|
|
360
360
|
}
|
|
361
|
-
if ((notStale || this.
|
|
361
|
+
if ((notStale || this.f & UNINITIALIZED_BIT) && this.loading()) {
|
|
362
362
|
throw new NotReadyError();
|
|
363
363
|
}
|
|
364
364
|
if (staleCheck && this.loading())
|
|
365
|
-
staleCheck.
|
|
366
|
-
return this.
|
|
365
|
+
staleCheck.g = true;
|
|
366
|
+
return this.W();
|
|
367
367
|
}
|
|
368
368
|
/**
|
|
369
369
|
* Return true if the computation is the value is dependent on an unresolved promise
|
|
@@ -373,44 +373,44 @@ var Computation = class extends Owner {
|
|
|
373
373
|
* loading state changes
|
|
374
374
|
*/
|
|
375
375
|
loading() {
|
|
376
|
-
if (this.
|
|
377
|
-
this.
|
|
376
|
+
if (this.Q === null) {
|
|
377
|
+
this.Q = loadingState(this);
|
|
378
378
|
}
|
|
379
|
-
return this.
|
|
379
|
+
return this.Q.read();
|
|
380
380
|
}
|
|
381
381
|
/** Update the computation with a new value. */
|
|
382
382
|
write(value, flags = 0, raw = false) {
|
|
383
|
-
const newValue = !raw && typeof value === "function" ? value(this.
|
|
384
|
-
const valueChanged = newValue !== UNCHANGED && (!!(this.
|
|
383
|
+
const newValue = !raw && typeof value === "function" ? value(this.g) : value;
|
|
384
|
+
const valueChanged = newValue !== UNCHANGED && (!!(this.f & UNINITIALIZED_BIT) || this.O === false || !this.O(this.g, newValue));
|
|
385
385
|
if (valueChanged) {
|
|
386
|
-
this.
|
|
387
|
-
this.
|
|
388
|
-
}
|
|
389
|
-
const changedFlagsMask = this.
|
|
390
|
-
this.
|
|
391
|
-
this.
|
|
392
|
-
if (this.
|
|
393
|
-
for (let i = 0; i < this.
|
|
386
|
+
this.g = newValue;
|
|
387
|
+
this.G = void 0;
|
|
388
|
+
}
|
|
389
|
+
const changedFlagsMask = this.f ^ flags, changedFlags = changedFlagsMask & flags;
|
|
390
|
+
this.f = flags;
|
|
391
|
+
this.y = getClock() + 1;
|
|
392
|
+
if (this.e) {
|
|
393
|
+
for (let i = 0; i < this.e.length; i++) {
|
|
394
394
|
if (valueChanged) {
|
|
395
|
-
this.
|
|
395
|
+
this.e[i].q(STATE_DIRTY);
|
|
396
396
|
} else if (changedFlagsMask) {
|
|
397
|
-
this.
|
|
397
|
+
this.e[i].X(changedFlagsMask, changedFlags);
|
|
398
398
|
}
|
|
399
399
|
}
|
|
400
400
|
}
|
|
401
|
-
return this.
|
|
401
|
+
return this.g;
|
|
402
402
|
}
|
|
403
403
|
/**
|
|
404
404
|
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
|
405
405
|
*/
|
|
406
406
|
q(state, skipQueue) {
|
|
407
|
-
if (this.a >= state && !this.
|
|
407
|
+
if (this.a >= state && !this.K)
|
|
408
408
|
return;
|
|
409
|
-
this.
|
|
409
|
+
this.K = !!skipQueue;
|
|
410
410
|
this.a = state;
|
|
411
|
-
if (this.
|
|
412
|
-
for (let i = 0; i < this.
|
|
413
|
-
this.
|
|
411
|
+
if (this.e) {
|
|
412
|
+
for (let i = 0; i < this.e.length; i++) {
|
|
413
|
+
this.e[i].q(STATE_CHECK, skipQueue);
|
|
414
414
|
}
|
|
415
415
|
}
|
|
416
416
|
}
|
|
@@ -420,31 +420,31 @@ var Computation = class extends Owner {
|
|
|
420
420
|
* @param mask A bitmask for which flag(s) were changed.
|
|
421
421
|
* @param newFlags The source's new flags, masked to just the changed ones.
|
|
422
422
|
*/
|
|
423
|
-
|
|
423
|
+
X(mask, newFlags2) {
|
|
424
424
|
if (this.a >= STATE_DIRTY)
|
|
425
425
|
return;
|
|
426
|
-
if (mask & this.
|
|
426
|
+
if (mask & this.P) {
|
|
427
427
|
this.q(STATE_DIRTY);
|
|
428
428
|
return;
|
|
429
429
|
}
|
|
430
430
|
if (this.a >= STATE_CHECK)
|
|
431
431
|
return;
|
|
432
|
-
const prevFlags = this.
|
|
432
|
+
const prevFlags = this.f & mask;
|
|
433
433
|
const deltaFlags = prevFlags ^ newFlags2;
|
|
434
434
|
if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
|
|
435
435
|
this.q(STATE_CHECK);
|
|
436
436
|
} else {
|
|
437
|
-
this.
|
|
438
|
-
if (this.
|
|
439
|
-
for (let i = 0; i < this.
|
|
440
|
-
this.
|
|
437
|
+
this.f ^= deltaFlags;
|
|
438
|
+
if (this.e) {
|
|
439
|
+
for (let i = 0; i < this.e.length; i++) {
|
|
440
|
+
this.e[i].X(mask, newFlags2);
|
|
441
441
|
}
|
|
442
442
|
}
|
|
443
443
|
}
|
|
444
444
|
}
|
|
445
|
-
|
|
446
|
-
this.
|
|
447
|
-
this.write(UNCHANGED, this.
|
|
445
|
+
H(error) {
|
|
446
|
+
this.G = error;
|
|
447
|
+
this.write(UNCHANGED, this.f & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
|
|
448
448
|
}
|
|
449
449
|
/**
|
|
450
450
|
* This is the core part of the reactivity system, which makes sure that the values are updated
|
|
@@ -453,7 +453,7 @@ var Computation = class extends Owner {
|
|
|
453
453
|
*
|
|
454
454
|
* This function will ensure that the value and states we read from the computation are up to date
|
|
455
455
|
*/
|
|
456
|
-
|
|
456
|
+
z() {
|
|
457
457
|
if (this.a === STATE_DISPOSED) {
|
|
458
458
|
throw new Error("Tried to read a disposed computation");
|
|
459
459
|
}
|
|
@@ -463,8 +463,8 @@ var Computation = class extends Owner {
|
|
|
463
463
|
let observerFlags = 0;
|
|
464
464
|
if (this.a === STATE_CHECK) {
|
|
465
465
|
for (let i = 0; i < this.b.length; i++) {
|
|
466
|
-
this.b[i].
|
|
467
|
-
observerFlags |= this.b[i].
|
|
466
|
+
this.b[i].z();
|
|
467
|
+
observerFlags |= this.b[i].f;
|
|
468
468
|
if (this.a === STATE_DIRTY) {
|
|
469
469
|
break;
|
|
470
470
|
}
|
|
@@ -480,27 +480,27 @@ var Computation = class extends Owner {
|
|
|
480
480
|
/**
|
|
481
481
|
* Remove ourselves from the owner graph and the computation graph
|
|
482
482
|
*/
|
|
483
|
-
|
|
483
|
+
A() {
|
|
484
484
|
if (this.a === STATE_DISPOSED)
|
|
485
485
|
return;
|
|
486
486
|
if (this.b)
|
|
487
487
|
removeSourceObservers(this, 0);
|
|
488
|
-
super.
|
|
488
|
+
super.A();
|
|
489
489
|
}
|
|
490
490
|
};
|
|
491
491
|
function loadingState(node) {
|
|
492
|
-
const prevOwner = setOwner(node.
|
|
492
|
+
const prevOwner = setOwner(node.t);
|
|
493
493
|
const options = void 0;
|
|
494
494
|
const computation = new Computation(
|
|
495
495
|
void 0,
|
|
496
496
|
() => {
|
|
497
497
|
track(node);
|
|
498
|
-
node.
|
|
499
|
-
return !!(node.
|
|
498
|
+
node.z();
|
|
499
|
+
return !!(node.f & LOADING_BIT);
|
|
500
500
|
},
|
|
501
501
|
options
|
|
502
502
|
);
|
|
503
|
-
computation.
|
|
503
|
+
computation.P = ERROR_BIT | LOADING_BIT;
|
|
504
504
|
setOwner(prevOwner);
|
|
505
505
|
return computation;
|
|
506
506
|
}
|
|
@@ -514,7 +514,7 @@ function track(computation) {
|
|
|
514
514
|
newSources.push(computation);
|
|
515
515
|
}
|
|
516
516
|
if (updateCheck) {
|
|
517
|
-
updateCheck.
|
|
517
|
+
updateCheck.g = computation.y > currentObserver.y;
|
|
518
518
|
}
|
|
519
519
|
}
|
|
520
520
|
}
|
|
@@ -526,13 +526,13 @@ function update(node) {
|
|
|
526
526
|
try {
|
|
527
527
|
node.dispose(false);
|
|
528
528
|
node.emptyDisposal();
|
|
529
|
-
const result = compute(node, node.
|
|
529
|
+
const result = compute(node, node.B, node);
|
|
530
530
|
node.write(result, newFlags, true);
|
|
531
531
|
} catch (error) {
|
|
532
532
|
if (error instanceof NotReadyError) {
|
|
533
|
-
node.write(UNCHANGED, newFlags | LOADING_BIT | node.
|
|
533
|
+
node.write(UNCHANGED, newFlags | LOADING_BIT | node.f & UNINITIALIZED_BIT);
|
|
534
534
|
} else {
|
|
535
|
-
node.
|
|
535
|
+
node.H(error);
|
|
536
536
|
}
|
|
537
537
|
} finally {
|
|
538
538
|
if (newSources) {
|
|
@@ -549,10 +549,10 @@ function update(node) {
|
|
|
549
549
|
let source;
|
|
550
550
|
for (let i = newSourcesIndex; i < node.b.length; i++) {
|
|
551
551
|
source = node.b[i];
|
|
552
|
-
if (!source.
|
|
553
|
-
source.
|
|
552
|
+
if (!source.e)
|
|
553
|
+
source.e = [node];
|
|
554
554
|
else
|
|
555
|
-
source.
|
|
555
|
+
source.e.push(node);
|
|
556
556
|
}
|
|
557
557
|
} else if (node.b && newSourcesIndex < node.b.length) {
|
|
558
558
|
removeSourceObservers(node, newSourcesIndex);
|
|
@@ -561,7 +561,7 @@ function update(node) {
|
|
|
561
561
|
newSources = prevSources;
|
|
562
562
|
newSourcesIndex = prevSourcesIndex;
|
|
563
563
|
newFlags = prevFlags;
|
|
564
|
-
node.
|
|
564
|
+
node.y = getClock() + 1;
|
|
565
565
|
node.a = STATE_CLEAN;
|
|
566
566
|
}
|
|
567
567
|
}
|
|
@@ -570,12 +570,12 @@ function removeSourceObservers(node, index) {
|
|
|
570
570
|
let swap;
|
|
571
571
|
for (let i = index; i < node.b.length; i++) {
|
|
572
572
|
source = node.b[i];
|
|
573
|
-
if (source.
|
|
574
|
-
swap = source.
|
|
575
|
-
source.
|
|
576
|
-
source.
|
|
577
|
-
if (!source.
|
|
578
|
-
source.
|
|
573
|
+
if (source.e) {
|
|
574
|
+
swap = source.e.indexOf(node);
|
|
575
|
+
source.e[swap] = source.e[source.e.length - 1];
|
|
576
|
+
source.e.pop();
|
|
577
|
+
if (!source.e.length)
|
|
578
|
+
source.V?.();
|
|
579
579
|
}
|
|
580
580
|
}
|
|
581
581
|
}
|
|
@@ -589,10 +589,10 @@ function untrack(fn) {
|
|
|
589
589
|
}
|
|
590
590
|
function hasUpdated(fn) {
|
|
591
591
|
const current = updateCheck;
|
|
592
|
-
updateCheck = {
|
|
592
|
+
updateCheck = { g: false };
|
|
593
593
|
try {
|
|
594
594
|
fn();
|
|
595
|
-
return updateCheck.
|
|
595
|
+
return updateCheck.g;
|
|
596
596
|
} finally {
|
|
597
597
|
updateCheck = current;
|
|
598
598
|
}
|
|
@@ -600,10 +600,10 @@ function hasUpdated(fn) {
|
|
|
600
600
|
function isPending(fn, loadingValue) {
|
|
601
601
|
const argLength = arguments.length;
|
|
602
602
|
const current = staleCheck;
|
|
603
|
-
staleCheck = {
|
|
603
|
+
staleCheck = { g: false };
|
|
604
604
|
try {
|
|
605
605
|
latest(fn);
|
|
606
|
-
return staleCheck.
|
|
606
|
+
return staleCheck.g;
|
|
607
607
|
} catch (err) {
|
|
608
608
|
if (!(err instanceof NotReadyError))
|
|
609
609
|
return false;
|
|
@@ -650,10 +650,10 @@ function runWithObserver(observer, run) {
|
|
|
650
650
|
if (error instanceof NotReadyError) {
|
|
651
651
|
observer.write(
|
|
652
652
|
UNCHANGED,
|
|
653
|
-
newFlags | LOADING_BIT | observer.
|
|
653
|
+
newFlags | LOADING_BIT | observer.f & UNINITIALIZED_BIT
|
|
654
654
|
);
|
|
655
655
|
} else {
|
|
656
|
-
observer.
|
|
656
|
+
observer.H(error);
|
|
657
657
|
}
|
|
658
658
|
} finally {
|
|
659
659
|
if (newSources) {
|
|
@@ -668,10 +668,10 @@ function runWithObserver(observer, run) {
|
|
|
668
668
|
let source;
|
|
669
669
|
for (let i = newSourcesIndex; i < observer.b.length; i++) {
|
|
670
670
|
source = observer.b[i];
|
|
671
|
-
if (!source.
|
|
672
|
-
source.
|
|
671
|
+
if (!source.e)
|
|
672
|
+
source.e = [observer];
|
|
673
673
|
else
|
|
674
|
-
source.
|
|
674
|
+
source.e.push(observer);
|
|
675
675
|
}
|
|
676
676
|
}
|
|
677
677
|
newSources = prevSources;
|
|
@@ -682,10 +682,10 @@ function runWithObserver(observer, run) {
|
|
|
682
682
|
function compute(owner, fn, observer) {
|
|
683
683
|
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask, prevNotStale = notStale;
|
|
684
684
|
currentObserver = observer;
|
|
685
|
-
currentMask = observer?.
|
|
685
|
+
currentMask = observer?.P ?? DEFAULT_FLAGS;
|
|
686
686
|
notStale = true;
|
|
687
687
|
try {
|
|
688
|
-
return fn(observer ? observer.
|
|
688
|
+
return fn(observer ? observer.g : void 0);
|
|
689
689
|
} finally {
|
|
690
690
|
setOwner(prevOwner);
|
|
691
691
|
currentObserver = prevObserver;
|
|
@@ -765,80 +765,80 @@ function createBoundary(fn, queue) {
|
|
|
765
765
|
|
|
766
766
|
// src/core/effect.ts
|
|
767
767
|
var Effect = class extends Computation {
|
|
768
|
-
K;
|
|
769
768
|
L;
|
|
770
|
-
B;
|
|
771
|
-
Q = false;
|
|
772
769
|
M;
|
|
773
|
-
|
|
770
|
+
C;
|
|
771
|
+
R = false;
|
|
772
|
+
N;
|
|
773
|
+
w;
|
|
774
774
|
constructor(initialValue, compute2, effect, error, options) {
|
|
775
775
|
super(initialValue, compute2, options);
|
|
776
|
-
this.
|
|
777
|
-
this.
|
|
778
|
-
this.
|
|
779
|
-
this.
|
|
780
|
-
if (this.
|
|
781
|
-
this.
|
|
776
|
+
this.L = effect;
|
|
777
|
+
this.M = error;
|
|
778
|
+
this.N = initialValue;
|
|
779
|
+
this.w = options?.render ? EFFECT_RENDER : EFFECT_USER;
|
|
780
|
+
if (this.w === EFFECT_RENDER) {
|
|
781
|
+
this.B = (p) => getClock() > this.h.created && !(this.f & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
|
|
782
782
|
}
|
|
783
|
-
this.
|
|
784
|
-
!options?.defer && (this.
|
|
783
|
+
this.z();
|
|
784
|
+
!options?.defer && (this.w === EFFECT_USER ? this.h.enqueue(this.w, this) : this.U());
|
|
785
785
|
}
|
|
786
786
|
write(value, flags = 0) {
|
|
787
787
|
if (this.a == STATE_DIRTY) {
|
|
788
|
-
const currentFlags = this.
|
|
789
|
-
this.
|
|
790
|
-
if (this.
|
|
791
|
-
this.h.
|
|
788
|
+
const currentFlags = this.f;
|
|
789
|
+
this.f = flags;
|
|
790
|
+
if (this.w === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
791
|
+
this.h.S?.(this);
|
|
792
792
|
}
|
|
793
793
|
}
|
|
794
794
|
if (value === UNCHANGED)
|
|
795
|
-
return this.
|
|
796
|
-
this.
|
|
797
|
-
this.
|
|
795
|
+
return this.g;
|
|
796
|
+
this.g = value;
|
|
797
|
+
this.R = true;
|
|
798
798
|
return value;
|
|
799
799
|
}
|
|
800
800
|
q(state, skipQueue) {
|
|
801
801
|
if (this.a >= state || skipQueue)
|
|
802
802
|
return;
|
|
803
803
|
if (this.a === STATE_CLEAN)
|
|
804
|
-
this.h.enqueue(this.
|
|
804
|
+
this.h.enqueue(this.w, this);
|
|
805
805
|
this.a = state;
|
|
806
806
|
}
|
|
807
|
-
|
|
808
|
-
this.
|
|
809
|
-
if (this.
|
|
810
|
-
this.h.
|
|
807
|
+
H(error) {
|
|
808
|
+
this.C?.();
|
|
809
|
+
if (this.f & LOADING_BIT) {
|
|
810
|
+
this.h.S?.(this);
|
|
811
811
|
}
|
|
812
|
-
this.
|
|
813
|
-
if (this.
|
|
812
|
+
this.f = ERROR_BIT;
|
|
813
|
+
if (this.w === EFFECT_USER) {
|
|
814
814
|
try {
|
|
815
|
-
return this.
|
|
815
|
+
return this.M ? this.C = this.M(error) : console.error(new EffectError(this.L, error));
|
|
816
816
|
} catch (e) {
|
|
817
817
|
error = e;
|
|
818
818
|
}
|
|
819
819
|
}
|
|
820
820
|
this.handleError(error);
|
|
821
821
|
}
|
|
822
|
-
|
|
822
|
+
A() {
|
|
823
823
|
if (this.a === STATE_DISPOSED)
|
|
824
824
|
return;
|
|
825
|
-
this.K = void 0;
|
|
826
|
-
this.M = void 0;
|
|
827
825
|
this.L = void 0;
|
|
828
|
-
this.
|
|
829
|
-
this.
|
|
830
|
-
|
|
826
|
+
this.N = void 0;
|
|
827
|
+
this.M = void 0;
|
|
828
|
+
this.C?.();
|
|
829
|
+
this.C = void 0;
|
|
830
|
+
super.A();
|
|
831
831
|
}
|
|
832
|
-
|
|
833
|
-
if (this.
|
|
834
|
-
this.
|
|
832
|
+
U() {
|
|
833
|
+
if (this.R && this.a !== STATE_DISPOSED) {
|
|
834
|
+
this.C?.();
|
|
835
835
|
try {
|
|
836
|
-
this.
|
|
836
|
+
this.C = this.L(this.g, this.N);
|
|
837
837
|
} catch (e) {
|
|
838
838
|
this.handleError(e);
|
|
839
839
|
} finally {
|
|
840
|
-
this.
|
|
841
|
-
this.
|
|
840
|
+
this.N = this.g;
|
|
841
|
+
this.R = false;
|
|
842
842
|
}
|
|
843
843
|
}
|
|
844
844
|
}
|
|
@@ -846,10 +846,10 @@ var Effect = class extends Computation {
|
|
|
846
846
|
var EagerComputation = class extends Computation {
|
|
847
847
|
constructor(initialValue, compute2, options) {
|
|
848
848
|
super(initialValue, compute2, options);
|
|
849
|
-
!options?.defer && this.
|
|
849
|
+
!options?.defer && this.z();
|
|
850
850
|
}
|
|
851
851
|
q(state, skipQueue) {
|
|
852
|
-
if (this.a >= state && !this.
|
|
852
|
+
if (this.a >= state && !this.K)
|
|
853
853
|
return;
|
|
854
854
|
if (this.a === STATE_CLEAN && !skipQueue)
|
|
855
855
|
this.h.enqueue(EFFECT_PURE, this);
|
|
@@ -861,7 +861,7 @@ var ProjectionComputation = class extends Computation {
|
|
|
861
861
|
super(null, compute2);
|
|
862
862
|
}
|
|
863
863
|
q(state, skipQueue) {
|
|
864
|
-
if (this.a >= state && !this.
|
|
864
|
+
if (this.a >= state && !this.K)
|
|
865
865
|
return;
|
|
866
866
|
if (this.a === STATE_CLEAN && !skipQueue)
|
|
867
867
|
this.h.enqueue(EFFECT_PURE, this);
|
|
@@ -871,39 +871,39 @@ var ProjectionComputation = class extends Computation {
|
|
|
871
871
|
|
|
872
872
|
// src/core/suspense.ts
|
|
873
873
|
var SuspenseQueue = class extends Queue {
|
|
874
|
-
|
|
874
|
+
c = /* @__PURE__ */ new Set();
|
|
875
875
|
o = false;
|
|
876
|
-
|
|
876
|
+
T = new Computation(false, null);
|
|
877
877
|
run(type) {
|
|
878
878
|
if (type && this.o)
|
|
879
879
|
return;
|
|
880
880
|
return super.run(type);
|
|
881
881
|
}
|
|
882
|
-
|
|
883
|
-
if (node.
|
|
884
|
-
this.
|
|
882
|
+
S(node) {
|
|
883
|
+
if (node.f & LOADING_BIT) {
|
|
884
|
+
this.c.add(node);
|
|
885
885
|
if (!this.o) {
|
|
886
886
|
this.o = true;
|
|
887
|
-
this.
|
|
887
|
+
this.T.write(true);
|
|
888
888
|
}
|
|
889
889
|
} else {
|
|
890
|
-
this.
|
|
891
|
-
if (this.
|
|
890
|
+
this.c.delete(node);
|
|
891
|
+
if (this.c.size === 0) {
|
|
892
892
|
this.o = false;
|
|
893
|
-
this.
|
|
893
|
+
this.T.write(false);
|
|
894
894
|
}
|
|
895
895
|
}
|
|
896
896
|
}
|
|
897
897
|
};
|
|
898
898
|
var LiveComputation = class extends EagerComputation {
|
|
899
899
|
write(value, flags = 0) {
|
|
900
|
-
const currentFlags = this.
|
|
900
|
+
const currentFlags = this.f;
|
|
901
901
|
const dirty = this.a === STATE_DIRTY;
|
|
902
902
|
super.write(value, flags);
|
|
903
903
|
if (dirty && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
904
|
-
this.h.
|
|
904
|
+
this.h.S?.(this);
|
|
905
905
|
}
|
|
906
|
-
return this.
|
|
906
|
+
return this.g;
|
|
907
907
|
}
|
|
908
908
|
};
|
|
909
909
|
function createSuspense(fn, fallback) {
|
|
@@ -912,7 +912,7 @@ function createSuspense(fn, fallback) {
|
|
|
912
912
|
const child = new Computation(null, fn);
|
|
913
913
|
return new LiveComputation(null, () => flatten(child.wait()));
|
|
914
914
|
}, queue);
|
|
915
|
-
const equality = new Computation(null, () => queue.
|
|
915
|
+
const equality = new Computation(null, () => queue.T.read() || queue.o);
|
|
916
916
|
const comp = new Computation(null, () => equality.read() ? fallback() : tree.read());
|
|
917
917
|
return comp.read.bind(comp);
|
|
918
918
|
}
|
|
@@ -943,10 +943,10 @@ function createMemo(compute2, value, options) {
|
|
|
943
943
|
return () => {
|
|
944
944
|
if (node) {
|
|
945
945
|
resolvedValue = node.wait();
|
|
946
|
-
if (!node.b?.length && node.n?.
|
|
946
|
+
if (!node.b?.length && node.n?.t !== node) {
|
|
947
947
|
node.dispose();
|
|
948
948
|
node = void 0;
|
|
949
|
-
} else if (!node.
|
|
949
|
+
} else if (!node.t && !node.e?.length) {
|
|
950
950
|
node.dispose();
|
|
951
951
|
node.a = STATE_DIRTY;
|
|
952
952
|
}
|
|
@@ -958,10 +958,10 @@ function createAsync(compute2, value, options) {
|
|
|
958
958
|
let uninitialized = value === void 0;
|
|
959
959
|
const lhs = new EagerComputation(
|
|
960
960
|
{
|
|
961
|
-
|
|
961
|
+
g: value
|
|
962
962
|
},
|
|
963
963
|
(p) => {
|
|
964
|
-
const value2 = p?.
|
|
964
|
+
const value2 = p?.g;
|
|
965
965
|
const source = compute2(value2);
|
|
966
966
|
const isPromise = source instanceof Promise;
|
|
967
967
|
const iterator = source[Symbol.asyncIterator];
|
|
@@ -970,13 +970,13 @@ function createAsync(compute2, value, options) {
|
|
|
970
970
|
wait() {
|
|
971
971
|
return source;
|
|
972
972
|
},
|
|
973
|
-
|
|
973
|
+
g: source
|
|
974
974
|
};
|
|
975
975
|
}
|
|
976
976
|
const signal = new Computation(value2, null, options);
|
|
977
977
|
const w = signal.wait;
|
|
978
978
|
signal.wait = function() {
|
|
979
|
-
if (signal.
|
|
979
|
+
if (signal.f & ERROR_BIT && signal.y <= getClock()) {
|
|
980
980
|
lhs.q(STATE_DIRTY);
|
|
981
981
|
throw new NotReadyError();
|
|
982
982
|
}
|
|
@@ -991,7 +991,7 @@ function createAsync(compute2, value, options) {
|
|
|
991
991
|
},
|
|
992
992
|
(error) => {
|
|
993
993
|
uninitialized = true;
|
|
994
|
-
signal.
|
|
994
|
+
signal.H(error);
|
|
995
995
|
}
|
|
996
996
|
);
|
|
997
997
|
} else {
|
|
@@ -1054,7 +1054,7 @@ function createErrorBoundary(fn, fallback) {
|
|
|
1054
1054
|
);
|
|
1055
1055
|
nodes.add(node);
|
|
1056
1056
|
if (nodes.size === 1)
|
|
1057
|
-
error.write({
|
|
1057
|
+
error.write({ G: err });
|
|
1058
1058
|
}
|
|
1059
1059
|
owner.m = owner.m ? [handler, ...owner.m] : [handler];
|
|
1060
1060
|
const guarded = compute(
|
|
@@ -1062,7 +1062,7 @@ function createErrorBoundary(fn, fallback) {
|
|
|
1062
1062
|
() => {
|
|
1063
1063
|
const c = new Computation(void 0, fn);
|
|
1064
1064
|
const f = new EagerComputation(void 0, () => flatten(c.read()), { defer: true });
|
|
1065
|
-
f.
|
|
1065
|
+
f.H = function(error2) {
|
|
1066
1066
|
this.handleError(error2);
|
|
1067
1067
|
};
|
|
1068
1068
|
return f;
|
|
@@ -1075,11 +1075,11 @@ function createErrorBoundary(fn, fallback) {
|
|
|
1075
1075
|
if (!error.read())
|
|
1076
1076
|
return resolved;
|
|
1077
1077
|
}
|
|
1078
|
-
return fallback(error.read().
|
|
1078
|
+
return fallback(error.read().G, () => {
|
|
1079
1079
|
incrementClock();
|
|
1080
1080
|
for (let node of nodes) {
|
|
1081
1081
|
node.a = STATE_DIRTY;
|
|
1082
|
-
node.h?.enqueue(node.
|
|
1082
|
+
node.h?.enqueue(node.w, node);
|
|
1083
1083
|
}
|
|
1084
1084
|
});
|
|
1085
1085
|
});
|
|
@@ -1104,12 +1104,15 @@ function resolve(fn) {
|
|
|
1104
1104
|
|
|
1105
1105
|
// src/store/projection.ts
|
|
1106
1106
|
function createProjection(fn, initialValue = {}) {
|
|
1107
|
-
const [store
|
|
1107
|
+
const [store] = createStore(fn, initialValue);
|
|
1108
|
+
return store;
|
|
1109
|
+
}
|
|
1110
|
+
function wrapProjection(fn, store, setStore) {
|
|
1108
1111
|
const node = new ProjectionComputation(() => {
|
|
1109
1112
|
setStore(fn);
|
|
1110
1113
|
});
|
|
1111
1114
|
const wrapped = /* @__PURE__ */ new WeakMap();
|
|
1112
|
-
return wrap(store, node, wrapped);
|
|
1115
|
+
return [wrap(store, node, wrapped), setStore];
|
|
1113
1116
|
}
|
|
1114
1117
|
function wrap(source, node, wrapped) {
|
|
1115
1118
|
if (wrapped.has(source))
|
|
@@ -1247,7 +1250,7 @@ var proxyTraps = {
|
|
|
1247
1250
|
return desc.get.call(receiver);
|
|
1248
1251
|
}
|
|
1249
1252
|
if (Writing.has(storeValue)) {
|
|
1250
|
-
const value2 = tracked ? tracked.
|
|
1253
|
+
const value2 = tracked ? tracked.g : storeValue[property];
|
|
1251
1254
|
return isWrappable(value2) ? (Writing.add(value2[$RAW] || value2), wrap2(value2)) : value2;
|
|
1252
1255
|
}
|
|
1253
1256
|
let value = tracked ? nodes[property].read() : storeValue[property];
|
|
@@ -1307,10 +1310,8 @@ function setProperty(state, property, value, deleting = false) {
|
|
|
1307
1310
|
}
|
|
1308
1311
|
function createStore(first, second) {
|
|
1309
1312
|
const derived = typeof first === "function", store = derived ? second : first;
|
|
1310
|
-
if (derived)
|
|
1311
|
-
return createProjection(first, store);
|
|
1312
1313
|
const unwrappedStore = unwrap(store, false);
|
|
1313
|
-
|
|
1314
|
+
let wrappedStore = wrap2(unwrappedStore);
|
|
1314
1315
|
const setStore = (fn) => {
|
|
1315
1316
|
try {
|
|
1316
1317
|
Writing.add(unwrappedStore);
|
|
@@ -1319,6 +1320,8 @@ function createStore(first, second) {
|
|
|
1319
1320
|
Writing.clear();
|
|
1320
1321
|
}
|
|
1321
1322
|
};
|
|
1323
|
+
if (derived)
|
|
1324
|
+
return wrapProjection(first, wrappedStore, setStore);
|
|
1322
1325
|
return [wrappedStore, setStore];
|
|
1323
1326
|
}
|
|
1324
1327
|
|
|
@@ -1586,73 +1589,73 @@ function omit(props, ...keys) {
|
|
|
1586
1589
|
function mapArray(list, map, options) {
|
|
1587
1590
|
const keyFn = typeof options?.keyed === "function" ? options.keyed : void 0;
|
|
1588
1591
|
return updateKeyedMap.bind({
|
|
1589
|
-
|
|
1592
|
+
I: new Owner(),
|
|
1590
1593
|
i: 0,
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1594
|
+
Y: list,
|
|
1595
|
+
x: [],
|
|
1596
|
+
D: map,
|
|
1597
|
+
d: [],
|
|
1598
|
+
c: [],
|
|
1599
|
+
E: keyFn,
|
|
1597
1600
|
j: keyFn || options?.keyed === false ? [] : void 0,
|
|
1598
1601
|
k: map.length > 1 ? [] : void 0,
|
|
1599
1602
|
o: options?.fallback
|
|
1600
1603
|
});
|
|
1601
1604
|
}
|
|
1602
1605
|
function updateKeyedMap() {
|
|
1603
|
-
const newItems = this.
|
|
1606
|
+
const newItems = this.Y() || [], newLen = newItems.length;
|
|
1604
1607
|
newItems[$TRACK];
|
|
1605
|
-
runWithOwner(this.
|
|
1608
|
+
runWithOwner(this.I, () => {
|
|
1606
1609
|
let i, j, mapper = this.j ? () => {
|
|
1607
1610
|
this.j[j] = new Computation(newItems[j], null);
|
|
1608
1611
|
this.k && (this.k[j] = new Computation(j, null));
|
|
1609
|
-
return this.
|
|
1612
|
+
return this.D(
|
|
1610
1613
|
Computation.prototype.read.bind(this.j[j]),
|
|
1611
1614
|
this.k ? Computation.prototype.read.bind(this.k[j]) : void 0
|
|
1612
1615
|
);
|
|
1613
1616
|
} : this.k ? () => {
|
|
1614
1617
|
const item = newItems[j];
|
|
1615
1618
|
this.k[j] = new Computation(j, null);
|
|
1616
|
-
return this.
|
|
1619
|
+
return this.D(() => item, Computation.prototype.read.bind(this.k[j]));
|
|
1617
1620
|
} : () => {
|
|
1618
1621
|
const item = newItems[j];
|
|
1619
|
-
return this.
|
|
1622
|
+
return this.D(() => item);
|
|
1620
1623
|
};
|
|
1621
1624
|
if (newLen === 0) {
|
|
1622
1625
|
if (this.i !== 0) {
|
|
1623
|
-
this.
|
|
1624
|
-
this.
|
|
1625
|
-
this.
|
|
1626
|
-
this.
|
|
1626
|
+
this.I.dispose(false);
|
|
1627
|
+
this.c = [];
|
|
1628
|
+
this.x = [];
|
|
1629
|
+
this.d = [];
|
|
1627
1630
|
this.i = 0;
|
|
1628
1631
|
this.j && (this.j = []);
|
|
1629
1632
|
this.k && (this.k = []);
|
|
1630
1633
|
}
|
|
1631
|
-
if (this.o && !this.
|
|
1632
|
-
this.
|
|
1633
|
-
this.
|
|
1634
|
+
if (this.o && !this.d[0]) {
|
|
1635
|
+
this.d[0] = compute(
|
|
1636
|
+
this.c[0] = new Owner(),
|
|
1634
1637
|
this.o,
|
|
1635
1638
|
null
|
|
1636
1639
|
);
|
|
1637
1640
|
}
|
|
1638
1641
|
} else if (this.i === 0) {
|
|
1639
|
-
if (this.
|
|
1640
|
-
this.
|
|
1641
|
-
this.
|
|
1642
|
+
if (this.c[0])
|
|
1643
|
+
this.c[0].dispose();
|
|
1644
|
+
this.d = new Array(newLen);
|
|
1642
1645
|
for (j = 0; j < newLen; j++) {
|
|
1643
|
-
this.
|
|
1644
|
-
this.
|
|
1646
|
+
this.x[j] = newItems[j];
|
|
1647
|
+
this.d[j] = compute(this.c[j] = new Owner(), mapper, null);
|
|
1645
1648
|
}
|
|
1646
1649
|
this.i = newLen;
|
|
1647
1650
|
} else {
|
|
1648
1651
|
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;
|
|
1649
|
-
for (start = 0, end = Math.min(this.i, newLen); start < end && (this.
|
|
1652
|
+
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++) {
|
|
1650
1653
|
if (this.j)
|
|
1651
1654
|
this.j[start].write(newItems[start]);
|
|
1652
1655
|
}
|
|
1653
|
-
for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.
|
|
1654
|
-
temp[newEnd] = this.
|
|
1655
|
-
tempNodes[newEnd] = this.
|
|
1656
|
+
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--) {
|
|
1657
|
+
temp[newEnd] = this.d[end];
|
|
1658
|
+
tempNodes[newEnd] = this.c[end];
|
|
1656
1659
|
tempRows && (tempRows[newEnd] = this.j[end]);
|
|
1657
1660
|
tempIndexes && (tempIndexes[newEnd] = this.k[end]);
|
|
1658
1661
|
}
|
|
@@ -1660,29 +1663,29 @@ function updateKeyedMap() {
|
|
|
1660
1663
|
newIndicesNext = new Array(newEnd + 1);
|
|
1661
1664
|
for (j = newEnd; j >= start; j--) {
|
|
1662
1665
|
item = newItems[j];
|
|
1663
|
-
key = this.
|
|
1666
|
+
key = this.E ? this.E(item) : item;
|
|
1664
1667
|
i = newIndices.get(key);
|
|
1665
1668
|
newIndicesNext[j] = i === void 0 ? -1 : i;
|
|
1666
1669
|
newIndices.set(key, j);
|
|
1667
1670
|
}
|
|
1668
1671
|
for (i = start; i <= end; i++) {
|
|
1669
|
-
item = this.
|
|
1670
|
-
key = this.
|
|
1672
|
+
item = this.x[i];
|
|
1673
|
+
key = this.E ? this.E(item) : item;
|
|
1671
1674
|
j = newIndices.get(key);
|
|
1672
1675
|
if (j !== void 0 && j !== -1) {
|
|
1673
|
-
temp[j] = this.
|
|
1674
|
-
tempNodes[j] = this.
|
|
1676
|
+
temp[j] = this.d[i];
|
|
1677
|
+
tempNodes[j] = this.c[i];
|
|
1675
1678
|
tempRows && (tempRows[j] = this.j[i]);
|
|
1676
1679
|
tempIndexes && (tempIndexes[j] = this.k[i]);
|
|
1677
1680
|
j = newIndicesNext[j];
|
|
1678
1681
|
newIndices.set(key, j);
|
|
1679
1682
|
} else
|
|
1680
|
-
this.
|
|
1683
|
+
this.c[i].dispose();
|
|
1681
1684
|
}
|
|
1682
1685
|
for (j = start; j < newLen; j++) {
|
|
1683
1686
|
if (j in temp) {
|
|
1684
|
-
this.
|
|
1685
|
-
this.
|
|
1687
|
+
this.d[j] = temp[j];
|
|
1688
|
+
this.c[j] = tempNodes[j];
|
|
1686
1689
|
if (tempRows) {
|
|
1687
1690
|
this.j[j] = tempRows[j];
|
|
1688
1691
|
this.j[j].write(newItems[j]);
|
|
@@ -1692,60 +1695,89 @@ function updateKeyedMap() {
|
|
|
1692
1695
|
this.k[j].write(j);
|
|
1693
1696
|
}
|
|
1694
1697
|
} else {
|
|
1695
|
-
this.
|
|
1698
|
+
this.d[j] = compute(this.c[j] = new Owner(), mapper, null);
|
|
1696
1699
|
}
|
|
1697
1700
|
}
|
|
1698
|
-
this.
|
|
1699
|
-
this.
|
|
1701
|
+
this.d = this.d.slice(0, this.i = newLen);
|
|
1702
|
+
this.x = newItems.slice(0);
|
|
1700
1703
|
}
|
|
1701
1704
|
});
|
|
1702
|
-
return this.
|
|
1705
|
+
return this.d;
|
|
1703
1706
|
}
|
|
1704
1707
|
function repeat(count, map, options) {
|
|
1705
1708
|
return updateRepeat.bind({
|
|
1706
|
-
|
|
1709
|
+
I: new Owner(),
|
|
1707
1710
|
i: 0,
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1711
|
+
r: 0,
|
|
1712
|
+
Z: count,
|
|
1713
|
+
D: map,
|
|
1714
|
+
c: [],
|
|
1715
|
+
d: [],
|
|
1716
|
+
_: options?.from,
|
|
1712
1717
|
o: options?.fallback
|
|
1713
1718
|
});
|
|
1714
1719
|
}
|
|
1715
1720
|
function updateRepeat() {
|
|
1716
|
-
const newLen = this.
|
|
1717
|
-
|
|
1721
|
+
const newLen = this.Z();
|
|
1722
|
+
const from = this._?.() || 0;
|
|
1723
|
+
runWithOwner(this.I, () => {
|
|
1718
1724
|
if (newLen === 0) {
|
|
1719
1725
|
if (this.i !== 0) {
|
|
1720
|
-
this.
|
|
1721
|
-
this.
|
|
1722
|
-
this.
|
|
1726
|
+
this.I.dispose(false);
|
|
1727
|
+
this.c = [];
|
|
1728
|
+
this.d = [];
|
|
1723
1729
|
this.i = 0;
|
|
1724
1730
|
}
|
|
1725
|
-
if (this.o && !this.
|
|
1726
|
-
this.
|
|
1727
|
-
this.
|
|
1731
|
+
if (this.o && !this.d[0]) {
|
|
1732
|
+
this.d[0] = compute(
|
|
1733
|
+
this.c[0] = new Owner(),
|
|
1728
1734
|
this.o,
|
|
1729
1735
|
null
|
|
1730
1736
|
);
|
|
1731
1737
|
}
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1738
|
+
return;
|
|
1739
|
+
}
|
|
1740
|
+
const to = from + newLen;
|
|
1741
|
+
const prevTo = this.r + this.i;
|
|
1742
|
+
if (this.i === 0 && this.c[0])
|
|
1743
|
+
this.c[0].dispose();
|
|
1744
|
+
for (let i = to; i < prevTo; i++)
|
|
1745
|
+
this.c[i - this.r].dispose();
|
|
1746
|
+
if (this.r < from) {
|
|
1747
|
+
let i = this.r;
|
|
1748
|
+
while (i < from && i < this.i)
|
|
1749
|
+
this.c[i++].dispose();
|
|
1750
|
+
this.c.splice(0, from - this.r);
|
|
1751
|
+
this.d.splice(0, from - this.r);
|
|
1752
|
+
} else if (this.r > from) {
|
|
1753
|
+
let i = prevTo - this.r - 1;
|
|
1754
|
+
let difference = this.r - from;
|
|
1755
|
+
this.c.length = this.d.length = newLen;
|
|
1756
|
+
while (i >= difference) {
|
|
1757
|
+
this.c[i] = this.c[i - difference];
|
|
1758
|
+
this.d[i] = this.d[i - difference];
|
|
1759
|
+
i--;
|
|
1760
|
+
}
|
|
1761
|
+
for (let i2 = 0; i2 < difference; i2++) {
|
|
1762
|
+
this.d[i2] = compute(
|
|
1763
|
+
this.c[i2] = new Owner(),
|
|
1764
|
+
() => this.D(i2 + from),
|
|
1739
1765
|
null
|
|
1740
1766
|
);
|
|
1741
1767
|
}
|
|
1742
|
-
for (let i = newLen; i < this.i; i++)
|
|
1743
|
-
this.f[i].dispose();
|
|
1744
|
-
this.g = this.g.slice(0, newLen);
|
|
1745
|
-
this.i = newLen;
|
|
1746
1768
|
}
|
|
1769
|
+
for (let i = prevTo; i < to; i++) {
|
|
1770
|
+
this.d[i - from] = compute(
|
|
1771
|
+
this.c[i - from] = new Owner(),
|
|
1772
|
+
() => this.D(i),
|
|
1773
|
+
null
|
|
1774
|
+
);
|
|
1775
|
+
}
|
|
1776
|
+
this.d = this.d.slice(0, newLen);
|
|
1777
|
+
this.r = from;
|
|
1778
|
+
this.i = newLen;
|
|
1747
1779
|
});
|
|
1748
|
-
return this.
|
|
1780
|
+
return this.d;
|
|
1749
1781
|
}
|
|
1750
1782
|
function compare(key, a, b) {
|
|
1751
1783
|
return key ? key(a) === key(b) : true;
|