@solidjs/signals 0.0.1 → 0.0.3
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 -33
- package/dist/node.cjs +231 -215
- package/dist/prod.js +231 -216
- package/dist/types/core/effect.d.ts +1 -0
- package/dist/types/core/index.d.ts +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/map.d.ts +5 -4
- package/dist/types/signals.d.ts +31 -14
- package/dist/types/store/index.d.ts +1 -1
- package/dist/types/store/reconcile.d.ts +1 -1
- package/package.json +7 -2
package/dist/node.cjs
CHANGED
|
@@ -48,30 +48,30 @@ var Owner = class {
|
|
|
48
48
|
// We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
|
|
49
49
|
// However, the children are actually added in reverse creation order
|
|
50
50
|
// See comment at the top of the file for an example of the _nextSibling traversal
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
r = null;
|
|
52
|
+
m = null;
|
|
53
53
|
o = null;
|
|
54
54
|
a = STATE_CLEAN;
|
|
55
|
-
g = null;
|
|
56
|
-
m = defaultContext;
|
|
57
55
|
h = null;
|
|
56
|
+
n = defaultContext;
|
|
57
|
+
i = null;
|
|
58
58
|
e = null;
|
|
59
59
|
constructor(signal = false) {
|
|
60
60
|
if (currentOwner && !signal)
|
|
61
61
|
currentOwner.append(this);
|
|
62
62
|
}
|
|
63
63
|
append(child) {
|
|
64
|
-
child.
|
|
64
|
+
child.r = this;
|
|
65
65
|
child.o = this;
|
|
66
|
-
if (this.
|
|
67
|
-
this.
|
|
68
|
-
child.
|
|
69
|
-
this.
|
|
70
|
-
if (child.
|
|
71
|
-
child.
|
|
66
|
+
if (this.m)
|
|
67
|
+
this.m.o = child;
|
|
68
|
+
child.m = this.m;
|
|
69
|
+
this.m = child;
|
|
70
|
+
if (child.n !== this.n) {
|
|
71
|
+
child.n = { ...this.n, ...child.n };
|
|
72
72
|
}
|
|
73
|
-
if (this.
|
|
74
|
-
child.
|
|
73
|
+
if (this.i) {
|
|
74
|
+
child.i = !child.i ? this.i : [...child.i, ...this.i];
|
|
75
75
|
}
|
|
76
76
|
if (this.e)
|
|
77
77
|
child.e = this.e;
|
|
@@ -79,51 +79,51 @@ var Owner = class {
|
|
|
79
79
|
dispose(self = true) {
|
|
80
80
|
if (this.a === STATE_DISPOSED)
|
|
81
81
|
return;
|
|
82
|
-
let head = self ? this.o || this.
|
|
83
|
-
while (current && current.
|
|
82
|
+
let head = self ? this.o || this.r : this, current = this.m, next = null;
|
|
83
|
+
while (current && current.r === this) {
|
|
84
84
|
current.dispose(true);
|
|
85
|
-
current.
|
|
86
|
-
next = current.
|
|
87
|
-
current.
|
|
85
|
+
current.x();
|
|
86
|
+
next = current.m;
|
|
87
|
+
current.m = null;
|
|
88
88
|
current = next;
|
|
89
89
|
}
|
|
90
90
|
if (self)
|
|
91
|
-
this.
|
|
91
|
+
this.x();
|
|
92
92
|
if (current)
|
|
93
93
|
current.o = !self ? this : this.o;
|
|
94
94
|
if (head)
|
|
95
|
-
head.
|
|
95
|
+
head.m = current;
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
x() {
|
|
98
98
|
if (this.o)
|
|
99
|
-
this.o.
|
|
100
|
-
this.
|
|
99
|
+
this.o.m = null;
|
|
100
|
+
this.r = null;
|
|
101
101
|
this.o = null;
|
|
102
|
-
this.
|
|
103
|
-
this.
|
|
102
|
+
this.n = defaultContext;
|
|
103
|
+
this.i = null;
|
|
104
104
|
this.a = STATE_DISPOSED;
|
|
105
105
|
this.emptyDisposal();
|
|
106
106
|
}
|
|
107
107
|
emptyDisposal() {
|
|
108
|
-
if (!this.
|
|
108
|
+
if (!this.h)
|
|
109
109
|
return;
|
|
110
|
-
if (Array.isArray(this.
|
|
111
|
-
for (let i = 0; i < this.
|
|
112
|
-
const callable = this.
|
|
110
|
+
if (Array.isArray(this.h)) {
|
|
111
|
+
for (let i = 0; i < this.h.length; i++) {
|
|
112
|
+
const callable = this.h[i];
|
|
113
113
|
callable.call(callable);
|
|
114
114
|
}
|
|
115
115
|
} else {
|
|
116
|
-
this.
|
|
116
|
+
this.h.call(this.h);
|
|
117
117
|
}
|
|
118
|
-
this.
|
|
118
|
+
this.h = null;
|
|
119
119
|
}
|
|
120
120
|
handleError(error) {
|
|
121
|
-
if (!this.
|
|
121
|
+
if (!this.i)
|
|
122
122
|
throw error;
|
|
123
|
-
let i = 0, len = this.
|
|
123
|
+
let i = 0, len = this.i.length;
|
|
124
124
|
for (i = 0; i < len; i++) {
|
|
125
125
|
try {
|
|
126
|
-
this.
|
|
126
|
+
this.i[i](error);
|
|
127
127
|
break;
|
|
128
128
|
} catch (e) {
|
|
129
129
|
error = e;
|
|
@@ -140,7 +140,7 @@ function getContext(context, owner = currentOwner) {
|
|
|
140
140
|
if (!owner) {
|
|
141
141
|
throw new NoOwnerError();
|
|
142
142
|
}
|
|
143
|
-
const value = hasContext(context, owner) ? owner.
|
|
143
|
+
const value = hasContext(context, owner) ? owner.n[context.id] : context.defaultValue;
|
|
144
144
|
if (isUndefined(value)) {
|
|
145
145
|
throw new ContextNotFoundError();
|
|
146
146
|
}
|
|
@@ -150,24 +150,24 @@ function setContext(context, value, owner = currentOwner) {
|
|
|
150
150
|
if (!owner) {
|
|
151
151
|
throw new NoOwnerError();
|
|
152
152
|
}
|
|
153
|
-
owner.
|
|
154
|
-
...owner.
|
|
153
|
+
owner.n = {
|
|
154
|
+
...owner.n,
|
|
155
155
|
[context.id]: isUndefined(value) ? context.defaultValue : value
|
|
156
156
|
};
|
|
157
157
|
}
|
|
158
158
|
function hasContext(context, owner = currentOwner) {
|
|
159
|
-
return !isUndefined(owner == null ? void 0 : owner.
|
|
159
|
+
return !isUndefined(owner == null ? void 0 : owner.n[context.id]);
|
|
160
160
|
}
|
|
161
161
|
function onCleanup(disposable) {
|
|
162
162
|
if (!currentOwner)
|
|
163
163
|
return;
|
|
164
164
|
const node = currentOwner;
|
|
165
|
-
if (!node.
|
|
166
|
-
node.
|
|
167
|
-
} else if (Array.isArray(node.
|
|
168
|
-
node.
|
|
165
|
+
if (!node.h) {
|
|
166
|
+
node.h = disposable;
|
|
167
|
+
} else if (Array.isArray(node.h)) {
|
|
168
|
+
node.h.push(disposable);
|
|
169
169
|
} else {
|
|
170
|
-
node.
|
|
170
|
+
node.h = [node.h, disposable];
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
|
|
@@ -198,37 +198,37 @@ var Computation = class extends Owner {
|
|
|
198
198
|
b = null;
|
|
199
199
|
c = null;
|
|
200
200
|
d;
|
|
201
|
-
|
|
201
|
+
D;
|
|
202
202
|
// Used in __DEV__ mode, hopefully removed in production
|
|
203
|
-
|
|
203
|
+
V;
|
|
204
204
|
// Using false is an optimization as an alternative to _equals: () => false
|
|
205
205
|
// which could enable more efficient DIRTY notification
|
|
206
|
-
|
|
206
|
+
E = isEqual;
|
|
207
207
|
N;
|
|
208
208
|
/** Whether the computation is an error or has ancestors that are unresolved */
|
|
209
|
-
|
|
209
|
+
j = 0;
|
|
210
210
|
/** Which flags raised by sources are handled, vs. being passed through. */
|
|
211
211
|
A = DEFAULT_FLAGS;
|
|
212
|
-
E = null;
|
|
213
212
|
F = null;
|
|
214
|
-
G =
|
|
213
|
+
G = null;
|
|
214
|
+
H = -1;
|
|
215
215
|
constructor(initialValue, compute2, options) {
|
|
216
216
|
super(compute2 === null);
|
|
217
|
-
this.
|
|
217
|
+
this.D = compute2;
|
|
218
218
|
this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
|
|
219
219
|
this.d = initialValue;
|
|
220
220
|
if ((options == null ? void 0 : options.equals) !== void 0)
|
|
221
|
-
this.
|
|
221
|
+
this.E = options.equals;
|
|
222
222
|
if (options == null ? void 0 : options.unobserved)
|
|
223
223
|
this.N = options == null ? void 0 : options.unobserved;
|
|
224
224
|
}
|
|
225
225
|
O() {
|
|
226
|
-
if (this.
|
|
227
|
-
this.
|
|
226
|
+
if (this.D)
|
|
227
|
+
this.s();
|
|
228
228
|
if (!this.b || this.b.length)
|
|
229
229
|
track(this);
|
|
230
|
-
newFlags |= this.
|
|
231
|
-
if (this.
|
|
230
|
+
newFlags |= this.j & ~currentMask;
|
|
231
|
+
if (this.j & ERROR_BIT) {
|
|
232
232
|
throw this.d;
|
|
233
233
|
} else {
|
|
234
234
|
return this.d;
|
|
@@ -262,34 +262,34 @@ var Computation = class extends Owner {
|
|
|
262
262
|
* loading state changes
|
|
263
263
|
*/
|
|
264
264
|
loading() {
|
|
265
|
-
if (this.
|
|
266
|
-
this.
|
|
265
|
+
if (this.G === null) {
|
|
266
|
+
this.G = loadingState(this);
|
|
267
267
|
}
|
|
268
|
-
return this.
|
|
268
|
+
return this.G.read();
|
|
269
269
|
}
|
|
270
270
|
/**
|
|
271
271
|
* Return true if the computation is the computation threw an error
|
|
272
272
|
* Triggers re-execution of the computation when the error state changes
|
|
273
273
|
*/
|
|
274
274
|
error() {
|
|
275
|
-
if (this.
|
|
276
|
-
this.
|
|
275
|
+
if (this.F === null) {
|
|
276
|
+
this.F = errorState(this);
|
|
277
277
|
}
|
|
278
|
-
return this.
|
|
278
|
+
return this.F.read();
|
|
279
279
|
}
|
|
280
280
|
/** Update the computation with a new value. */
|
|
281
281
|
write(value, flags = 0, raw = false) {
|
|
282
282
|
const newValue = !raw && typeof value === "function" ? value(this.d) : value;
|
|
283
|
-
const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.
|
|
283
|
+
const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.E === false || !this.E(this.d, newValue));
|
|
284
284
|
if (valueChanged)
|
|
285
285
|
this.d = newValue;
|
|
286
|
-
const changedFlagsMask = this.
|
|
287
|
-
this.
|
|
288
|
-
this.
|
|
286
|
+
const changedFlagsMask = this.j ^ flags, changedFlags = changedFlagsMask & flags;
|
|
287
|
+
this.j = flags;
|
|
288
|
+
this.H = clock + 1;
|
|
289
289
|
if (this.c) {
|
|
290
290
|
for (let i = 0; i < this.c.length; i++) {
|
|
291
291
|
if (valueChanged) {
|
|
292
|
-
this.c[i].
|
|
292
|
+
this.c[i].t(STATE_DIRTY);
|
|
293
293
|
} else if (changedFlagsMask) {
|
|
294
294
|
this.c[i].P(changedFlagsMask, changedFlags);
|
|
295
295
|
}
|
|
@@ -300,13 +300,13 @@ var Computation = class extends Owner {
|
|
|
300
300
|
/**
|
|
301
301
|
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
|
302
302
|
*/
|
|
303
|
-
|
|
303
|
+
t(state) {
|
|
304
304
|
if (this.a >= state)
|
|
305
305
|
return;
|
|
306
306
|
this.a = state;
|
|
307
307
|
if (this.c) {
|
|
308
308
|
for (let i = 0; i < this.c.length; i++) {
|
|
309
|
-
this.c[i].
|
|
309
|
+
this.c[i].t(STATE_CHECK);
|
|
310
310
|
}
|
|
311
311
|
}
|
|
312
312
|
}
|
|
@@ -320,17 +320,17 @@ var Computation = class extends Owner {
|
|
|
320
320
|
if (this.a >= STATE_DIRTY)
|
|
321
321
|
return;
|
|
322
322
|
if (mask & this.A) {
|
|
323
|
-
this.
|
|
323
|
+
this.t(STATE_DIRTY);
|
|
324
324
|
return;
|
|
325
325
|
}
|
|
326
326
|
if (this.a >= STATE_CHECK)
|
|
327
327
|
return;
|
|
328
|
-
const prevFlags = this.
|
|
328
|
+
const prevFlags = this.j & mask;
|
|
329
329
|
const deltaFlags = prevFlags ^ newFlags2;
|
|
330
330
|
if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
|
|
331
|
-
this.
|
|
331
|
+
this.t(STATE_CHECK);
|
|
332
332
|
} else {
|
|
333
|
-
this.
|
|
333
|
+
this.j ^= deltaFlags;
|
|
334
334
|
if (this.c) {
|
|
335
335
|
for (let i = 0; i < this.c.length; i++) {
|
|
336
336
|
this.c[i].P(mask, newFlags2);
|
|
@@ -339,7 +339,7 @@ var Computation = class extends Owner {
|
|
|
339
339
|
}
|
|
340
340
|
}
|
|
341
341
|
Q(error) {
|
|
342
|
-
this.write(error, this.
|
|
342
|
+
this.write(error, this.j | ERROR_BIT);
|
|
343
343
|
}
|
|
344
344
|
/**
|
|
345
345
|
* This is the core part of the reactivity system, which makes sure that the values are updated
|
|
@@ -348,7 +348,7 @@ var Computation = class extends Owner {
|
|
|
348
348
|
*
|
|
349
349
|
* This function will ensure that the value and states we read from the computation are up to date
|
|
350
350
|
*/
|
|
351
|
-
|
|
351
|
+
s() {
|
|
352
352
|
if (this.a === STATE_DISPOSED) {
|
|
353
353
|
throw new Error("Tried to read a disposed computation");
|
|
354
354
|
}
|
|
@@ -358,8 +358,8 @@ var Computation = class extends Owner {
|
|
|
358
358
|
let observerFlags = 0;
|
|
359
359
|
if (this.a === STATE_CHECK) {
|
|
360
360
|
for (let i = 0; i < this.b.length; i++) {
|
|
361
|
-
this.b[i].
|
|
362
|
-
observerFlags |= this.b[i].
|
|
361
|
+
this.b[i].s();
|
|
362
|
+
observerFlags |= this.b[i].j;
|
|
363
363
|
if (this.a === STATE_DIRTY) {
|
|
364
364
|
break;
|
|
365
365
|
}
|
|
@@ -375,23 +375,23 @@ var Computation = class extends Owner {
|
|
|
375
375
|
/**
|
|
376
376
|
* Remove ourselves from the owner graph and the computation graph
|
|
377
377
|
*/
|
|
378
|
-
|
|
378
|
+
x() {
|
|
379
379
|
if (this.a === STATE_DISPOSED)
|
|
380
380
|
return;
|
|
381
381
|
if (this.b)
|
|
382
382
|
removeSourceObservers(this, 0);
|
|
383
|
-
super.
|
|
383
|
+
super.x();
|
|
384
384
|
}
|
|
385
385
|
};
|
|
386
386
|
function loadingState(node) {
|
|
387
|
-
const prevOwner = setOwner(node.
|
|
387
|
+
const prevOwner = setOwner(node.r);
|
|
388
388
|
const options = void 0;
|
|
389
389
|
const computation = new Computation(
|
|
390
390
|
void 0,
|
|
391
391
|
() => {
|
|
392
392
|
track(node);
|
|
393
|
-
node.
|
|
394
|
-
return !!(node.
|
|
393
|
+
node.s();
|
|
394
|
+
return !!(node.j & LOADING_BIT);
|
|
395
395
|
},
|
|
396
396
|
options
|
|
397
397
|
);
|
|
@@ -400,14 +400,14 @@ function loadingState(node) {
|
|
|
400
400
|
return computation;
|
|
401
401
|
}
|
|
402
402
|
function errorState(node) {
|
|
403
|
-
const prevOwner = setOwner(node.
|
|
403
|
+
const prevOwner = setOwner(node.r);
|
|
404
404
|
const options = void 0;
|
|
405
405
|
const computation = new Computation(
|
|
406
406
|
void 0,
|
|
407
407
|
() => {
|
|
408
408
|
track(node);
|
|
409
|
-
node.
|
|
410
|
-
return !!(node.
|
|
409
|
+
node.s();
|
|
410
|
+
return !!(node.j & ERROR_BIT);
|
|
411
411
|
},
|
|
412
412
|
options
|
|
413
413
|
);
|
|
@@ -425,7 +425,7 @@ function track(computation) {
|
|
|
425
425
|
newSources.push(computation);
|
|
426
426
|
}
|
|
427
427
|
if (updateCheck) {
|
|
428
|
-
updateCheck.d = computation.
|
|
428
|
+
updateCheck.d = computation.H > currentObserver.H;
|
|
429
429
|
}
|
|
430
430
|
}
|
|
431
431
|
}
|
|
@@ -437,7 +437,7 @@ function update(node) {
|
|
|
437
437
|
try {
|
|
438
438
|
node.dispose(false);
|
|
439
439
|
node.emptyDisposal();
|
|
440
|
-
const result = compute(node, node.
|
|
440
|
+
const result = compute(node, node.D, node);
|
|
441
441
|
node.write(result, newFlags, true);
|
|
442
442
|
} catch (error) {
|
|
443
443
|
if (error instanceof NotReadyError) {
|
|
@@ -549,50 +549,50 @@ function schedule() {
|
|
|
549
549
|
queueMicrotask(flushSync);
|
|
550
550
|
}
|
|
551
551
|
var Queue = class {
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
552
|
+
I = false;
|
|
553
|
+
u = [[], [], []];
|
|
554
|
+
z = [];
|
|
555
555
|
enqueue(type, node) {
|
|
556
|
-
this.
|
|
556
|
+
this.u[0].push(node);
|
|
557
557
|
if (type)
|
|
558
|
-
this.
|
|
558
|
+
this.u[type].push(node);
|
|
559
559
|
schedule();
|
|
560
560
|
}
|
|
561
561
|
run(type) {
|
|
562
|
-
if (this.
|
|
562
|
+
if (this.u[type].length) {
|
|
563
563
|
if (type === EFFECT_PURE) {
|
|
564
|
-
runPureQueue(this.
|
|
565
|
-
this.
|
|
564
|
+
runPureQueue(this.u[type]);
|
|
565
|
+
this.u[type] = [];
|
|
566
566
|
} else {
|
|
567
|
-
const effects = this.
|
|
568
|
-
this.
|
|
567
|
+
const effects = this.u[type];
|
|
568
|
+
this.u[type] = [];
|
|
569
569
|
runEffectQueue(effects);
|
|
570
570
|
}
|
|
571
571
|
}
|
|
572
|
-
for (let i = 0; i < this.
|
|
573
|
-
this.
|
|
572
|
+
for (let i = 0; i < this.z.length; i++) {
|
|
573
|
+
this.z[i].run(type);
|
|
574
574
|
}
|
|
575
575
|
}
|
|
576
576
|
flush() {
|
|
577
|
-
if (this.
|
|
577
|
+
if (this.I)
|
|
578
578
|
return;
|
|
579
|
-
this.
|
|
579
|
+
this.I = true;
|
|
580
580
|
try {
|
|
581
581
|
this.run(EFFECT_PURE);
|
|
582
582
|
incrementClock();
|
|
583
583
|
this.run(EFFECT_RENDER);
|
|
584
584
|
this.run(EFFECT_USER);
|
|
585
585
|
} finally {
|
|
586
|
-
this.
|
|
586
|
+
this.I = false;
|
|
587
587
|
}
|
|
588
588
|
}
|
|
589
589
|
addChild(child) {
|
|
590
|
-
this.
|
|
590
|
+
this.z.push(child);
|
|
591
591
|
}
|
|
592
592
|
removeChild(child) {
|
|
593
|
-
const index = this.
|
|
593
|
+
const index = this.z.indexOf(child);
|
|
594
594
|
if (index >= 0)
|
|
595
|
-
this.
|
|
595
|
+
this.z.splice(index, 1);
|
|
596
596
|
}
|
|
597
597
|
};
|
|
598
598
|
var globalQueue = new Queue();
|
|
@@ -609,14 +609,14 @@ function createBoundary(fn, queue) {
|
|
|
609
609
|
}
|
|
610
610
|
function runTop(node) {
|
|
611
611
|
const ancestors = [];
|
|
612
|
-
for (let current = node; current !== null; current = current.
|
|
612
|
+
for (let current = node; current !== null; current = current.r) {
|
|
613
613
|
if (current.a !== STATE_CLEAN) {
|
|
614
614
|
ancestors.push(current);
|
|
615
615
|
}
|
|
616
616
|
}
|
|
617
617
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
618
618
|
if (ancestors[i].a !== STATE_DISPOSED)
|
|
619
|
-
ancestors[i].
|
|
619
|
+
ancestors[i].s();
|
|
620
620
|
}
|
|
621
621
|
}
|
|
622
622
|
function runPureQueue(queue) {
|
|
@@ -626,59 +626,61 @@ function runPureQueue(queue) {
|
|
|
626
626
|
}
|
|
627
627
|
}
|
|
628
628
|
function runEffectQueue(queue) {
|
|
629
|
-
for (let i = 0; i < queue.length; i++)
|
|
630
|
-
|
|
631
|
-
queue[i].J(queue[i].d, queue[i].B);
|
|
632
|
-
queue[i].I = false;
|
|
633
|
-
queue[i].B = queue[i].d;
|
|
634
|
-
}
|
|
635
|
-
}
|
|
629
|
+
for (let i = 0; i < queue.length; i++)
|
|
630
|
+
queue[i].R();
|
|
636
631
|
}
|
|
637
632
|
|
|
638
633
|
// src/core/effect.ts
|
|
639
634
|
var Effect = class extends Computation {
|
|
640
635
|
J;
|
|
641
|
-
|
|
636
|
+
K = false;
|
|
642
637
|
B;
|
|
643
|
-
|
|
638
|
+
C;
|
|
644
639
|
e;
|
|
645
640
|
constructor(initialValue, compute2, effect, options) {
|
|
646
641
|
var _a;
|
|
647
642
|
super(initialValue, compute2, options);
|
|
648
643
|
this.J = effect;
|
|
649
644
|
this.B = initialValue;
|
|
650
|
-
this.
|
|
645
|
+
this.C = (options == null ? void 0 : options.render) ? EFFECT_RENDER : EFFECT_USER;
|
|
651
646
|
this.e = ((_a = getOwner()) == null ? void 0 : _a.e) || globalQueue;
|
|
652
|
-
this.
|
|
653
|
-
this.
|
|
647
|
+
this.s();
|
|
648
|
+
this.C === EFFECT_USER ? this.e.enqueue(this.C, this) : this.R();
|
|
654
649
|
}
|
|
655
650
|
write(value, flags = 0) {
|
|
656
651
|
var _a, _b;
|
|
657
|
-
const currentFlags = this.
|
|
658
|
-
this.
|
|
652
|
+
const currentFlags = this.j;
|
|
653
|
+
this.j = flags;
|
|
659
654
|
if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
660
|
-
(_b = (_a = this.e).
|
|
655
|
+
(_b = (_a = this.e).T) == null ? void 0 : _b.call(_a, this);
|
|
661
656
|
}
|
|
662
657
|
if (value === UNCHANGED)
|
|
663
658
|
return this.d;
|
|
664
659
|
this.d = value;
|
|
665
|
-
this.
|
|
660
|
+
this.K = true;
|
|
666
661
|
return value;
|
|
667
662
|
}
|
|
668
|
-
|
|
663
|
+
t(state) {
|
|
669
664
|
if (this.a >= state)
|
|
670
665
|
return;
|
|
671
666
|
if (this.a === STATE_CLEAN)
|
|
672
|
-
this.e.enqueue(this.
|
|
667
|
+
this.e.enqueue(this.C, this);
|
|
673
668
|
this.a = state;
|
|
674
669
|
}
|
|
675
670
|
Q(error) {
|
|
676
671
|
this.handleError(error);
|
|
677
672
|
}
|
|
678
|
-
|
|
673
|
+
x() {
|
|
679
674
|
this.J = void 0;
|
|
680
675
|
this.B = void 0;
|
|
681
|
-
super.
|
|
676
|
+
super.x();
|
|
677
|
+
}
|
|
678
|
+
R() {
|
|
679
|
+
if (this.K && this.a !== STATE_DISPOSED) {
|
|
680
|
+
this.J(this.d, this.B);
|
|
681
|
+
this.B = this.d;
|
|
682
|
+
this.K = false;
|
|
683
|
+
}
|
|
682
684
|
}
|
|
683
685
|
};
|
|
684
686
|
var EagerComputation = class extends Computation {
|
|
@@ -687,38 +689,38 @@ var EagerComputation = class extends Computation {
|
|
|
687
689
|
var _a;
|
|
688
690
|
super(initialValue, compute2, options);
|
|
689
691
|
this.e = ((_a = getOwner()) == null ? void 0 : _a.e) || globalQueue;
|
|
690
|
-
this.
|
|
692
|
+
this.s();
|
|
691
693
|
}
|
|
692
|
-
|
|
694
|
+
t(state) {
|
|
693
695
|
if (this.a >= state)
|
|
694
696
|
return;
|
|
695
697
|
if (this.a === STATE_CLEAN)
|
|
696
698
|
this.e.enqueue(EFFECT_PURE, this);
|
|
697
|
-
super.
|
|
699
|
+
super.t(state);
|
|
698
700
|
}
|
|
699
701
|
};
|
|
700
702
|
|
|
701
703
|
// src/core/suspense.ts
|
|
702
704
|
var SuspenseQueue = class extends Queue {
|
|
703
|
-
|
|
704
|
-
|
|
705
|
+
f = /* @__PURE__ */ new Set();
|
|
706
|
+
p = false;
|
|
705
707
|
L = new Computation(false, null);
|
|
706
708
|
run(type) {
|
|
707
|
-
if (type && this.
|
|
709
|
+
if (type && this.p)
|
|
708
710
|
return;
|
|
709
711
|
super.run(type);
|
|
710
712
|
}
|
|
711
|
-
|
|
712
|
-
if (node.
|
|
713
|
-
this.
|
|
714
|
-
if (!this.
|
|
715
|
-
this.
|
|
713
|
+
T(node) {
|
|
714
|
+
if (node.j & LOADING_BIT) {
|
|
715
|
+
this.f.add(node);
|
|
716
|
+
if (!this.p) {
|
|
717
|
+
this.p = true;
|
|
716
718
|
queueMicrotask(() => this.L.write(true));
|
|
717
719
|
}
|
|
718
720
|
} else {
|
|
719
|
-
this.
|
|
720
|
-
if (this.
|
|
721
|
-
this.
|
|
721
|
+
this.f.delete(node);
|
|
722
|
+
if (this.f.size === 0) {
|
|
723
|
+
this.p = false;
|
|
722
724
|
queueMicrotask(() => this.L.write(false));
|
|
723
725
|
}
|
|
724
726
|
}
|
|
@@ -727,7 +729,7 @@ var SuspenseQueue = class extends Queue {
|
|
|
727
729
|
function createSuspense(fn, fallbackFn) {
|
|
728
730
|
const queue = new SuspenseQueue();
|
|
729
731
|
const tree = createBoundary(fn, queue);
|
|
730
|
-
const equality = new Computation(null, () => queue.L.read() || queue.
|
|
732
|
+
const equality = new Computation(null, () => queue.L.read() || queue.p);
|
|
731
733
|
const comp = new Computation(null, () => equality.read() ? untrack(fallbackFn) : tree);
|
|
732
734
|
return comp.read.bind(comp);
|
|
733
735
|
}
|
|
@@ -838,7 +840,7 @@ function runWithOwner(owner, run) {
|
|
|
838
840
|
}
|
|
839
841
|
function catchError(fn, handler) {
|
|
840
842
|
const owner = new Owner();
|
|
841
|
-
owner.
|
|
843
|
+
owner.i = owner.i ? [handler, ...owner.i] : [handler];
|
|
842
844
|
try {
|
|
843
845
|
compute(owner, fn, null);
|
|
844
846
|
} catch (error) {
|
|
@@ -856,15 +858,22 @@ var STORE_NODE = "n";
|
|
|
856
858
|
var STORE_HAS = "h";
|
|
857
859
|
function wrap(value) {
|
|
858
860
|
let p = value[$PROXY];
|
|
859
|
-
if (!p)
|
|
861
|
+
if (!p) {
|
|
862
|
+
let target;
|
|
863
|
+
if (Array.isArray(value)) {
|
|
864
|
+
target = [];
|
|
865
|
+
target.v = value;
|
|
866
|
+
} else
|
|
867
|
+
target = { v: value };
|
|
860
868
|
Object.defineProperty(value, $PROXY, {
|
|
861
|
-
value: p = new Proxy(
|
|
869
|
+
value: p = new Proxy(target, proxyTraps),
|
|
862
870
|
writable: true
|
|
863
871
|
});
|
|
872
|
+
}
|
|
864
873
|
return p;
|
|
865
874
|
}
|
|
866
875
|
function isWrappable(obj) {
|
|
867
|
-
return obj != null && typeof obj === "object";
|
|
876
|
+
return obj != null && typeof obj === "object" && !Object.isFrozen(obj);
|
|
868
877
|
}
|
|
869
878
|
function unwrap(item, deep = true, set) {
|
|
870
879
|
let result, unwrapped, v, prop;
|
|
@@ -916,8 +925,10 @@ function getNode(nodes, property, value, equals = isEqual) {
|
|
|
916
925
|
});
|
|
917
926
|
}
|
|
918
927
|
function proxyDescriptor(target, property) {
|
|
928
|
+
if (property === $PROXY)
|
|
929
|
+
return { value: target[$PROXY], writable: true, configurable: true };
|
|
919
930
|
const desc = Reflect.getOwnPropertyDescriptor(target[STORE_VALUE], property);
|
|
920
|
-
if (!desc || desc.get || !desc.configurable
|
|
931
|
+
if (!desc || desc.get || !desc.configurable)
|
|
921
932
|
return desc;
|
|
922
933
|
delete desc.value;
|
|
923
934
|
delete desc.writable;
|
|
@@ -983,7 +994,10 @@ var proxyTraps = {
|
|
|
983
994
|
return true;
|
|
984
995
|
},
|
|
985
996
|
ownKeys,
|
|
986
|
-
getOwnPropertyDescriptor: proxyDescriptor
|
|
997
|
+
getOwnPropertyDescriptor: proxyDescriptor,
|
|
998
|
+
getPrototypeOf(target) {
|
|
999
|
+
return Object.getPrototypeOf(target[STORE_VALUE]);
|
|
1000
|
+
}
|
|
987
1001
|
};
|
|
988
1002
|
function setProperty(state, property, value, deleting = false) {
|
|
989
1003
|
var _a, _b, _c, _d, _e;
|
|
@@ -1139,6 +1153,7 @@ function reconcile(value, key) {
|
|
|
1139
1153
|
if (keyFn(value) !== keyFn(state))
|
|
1140
1154
|
throw new Error("Cannot reconcile states with different identity");
|
|
1141
1155
|
applyState(value, state, keyFn);
|
|
1156
|
+
return state;
|
|
1142
1157
|
};
|
|
1143
1158
|
}
|
|
1144
1159
|
|
|
@@ -1179,7 +1194,7 @@ function resolveSource(s) {
|
|
|
1179
1194
|
}
|
|
1180
1195
|
var $SOURCES = Symbol(0);
|
|
1181
1196
|
function merge(...sources) {
|
|
1182
|
-
if (sources.length === 1)
|
|
1197
|
+
if (sources.length === 1 && typeof sources[0] !== "function")
|
|
1183
1198
|
return sources[0];
|
|
1184
1199
|
let proxy = false;
|
|
1185
1200
|
const flattened = [];
|
|
@@ -1293,117 +1308,117 @@ function omit(props, ...keys) {
|
|
|
1293
1308
|
// src/map.ts
|
|
1294
1309
|
function mapArray(list, map, options) {
|
|
1295
1310
|
const keyFn = typeof (options == null ? void 0 : options.keyed) === "function" ? options.keyed : void 0;
|
|
1296
|
-
return
|
|
1297
|
-
new
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
j: map.length > 1 ? [] : void 0
|
|
1310
|
-
}),
|
|
1311
|
-
options
|
|
1312
|
-
)
|
|
1313
|
-
);
|
|
1311
|
+
return updateKeyedMap.bind({
|
|
1312
|
+
S: new Owner(),
|
|
1313
|
+
w: 0,
|
|
1314
|
+
U: list,
|
|
1315
|
+
q: [],
|
|
1316
|
+
M: map,
|
|
1317
|
+
k: [],
|
|
1318
|
+
f: [],
|
|
1319
|
+
y: keyFn,
|
|
1320
|
+
g: keyFn || (options == null ? void 0 : options.keyed) === false ? [] : void 0,
|
|
1321
|
+
l: map.length > 1 ? [] : void 0,
|
|
1322
|
+
p: options == null ? void 0 : options.fallback
|
|
1323
|
+
});
|
|
1314
1324
|
}
|
|
1315
1325
|
function updateKeyedMap() {
|
|
1316
|
-
const newItems = this.
|
|
1326
|
+
const newItems = this.U() || [], newLen = newItems.length;
|
|
1317
1327
|
newItems[$TRACK];
|
|
1318
|
-
runWithOwner(this.
|
|
1319
|
-
let i, j, mapper = this.
|
|
1320
|
-
this.
|
|
1321
|
-
this.
|
|
1328
|
+
runWithOwner(this.S, () => {
|
|
1329
|
+
let i, j, mapper = this.g ? () => {
|
|
1330
|
+
this.g[j] = new Computation(newItems[j], null);
|
|
1331
|
+
this.l[j] = new Computation(j, null);
|
|
1322
1332
|
return this.M(
|
|
1323
|
-
Computation.prototype.read.bind(this.
|
|
1324
|
-
Computation.prototype.read.bind(this.
|
|
1333
|
+
Computation.prototype.read.bind(this.g[j]),
|
|
1334
|
+
Computation.prototype.read.bind(this.l[j])
|
|
1325
1335
|
);
|
|
1326
|
-
} : this.
|
|
1336
|
+
} : this.l ? () => {
|
|
1327
1337
|
const item = newItems[j];
|
|
1328
|
-
this.
|
|
1329
|
-
return this.M(() => item, Computation.prototype.read.bind(this.
|
|
1338
|
+
this.l[j] = new Computation(j, null);
|
|
1339
|
+
return this.M(() => item, Computation.prototype.read.bind(this.l[j]));
|
|
1330
1340
|
} : () => {
|
|
1331
1341
|
const item = newItems[j];
|
|
1332
1342
|
return this.M(() => item);
|
|
1333
1343
|
};
|
|
1334
1344
|
if (newLen === 0) {
|
|
1335
|
-
if (this.
|
|
1336
|
-
this.
|
|
1345
|
+
if (this.w !== 0) {
|
|
1346
|
+
this.S.dispose(false);
|
|
1347
|
+
this.f = [];
|
|
1348
|
+
this.q = [];
|
|
1337
1349
|
this.k = [];
|
|
1338
|
-
this.
|
|
1339
|
-
this.
|
|
1340
|
-
this.
|
|
1341
|
-
|
|
1342
|
-
|
|
1350
|
+
this.w = 0;
|
|
1351
|
+
this.g && (this.g = []);
|
|
1352
|
+
this.l && (this.l = []);
|
|
1353
|
+
}
|
|
1354
|
+
if (this.p && !this.k[0]) {
|
|
1355
|
+
this.k[0] = compute(this.f[0] = new Owner(), this.p, null);
|
|
1343
1356
|
}
|
|
1344
|
-
} else if (this.
|
|
1345
|
-
this.
|
|
1357
|
+
} else if (this.w === 0) {
|
|
1358
|
+
if (this.f[0])
|
|
1359
|
+
this.f[0].dispose();
|
|
1360
|
+
this.k = new Array(newLen);
|
|
1346
1361
|
for (j = 0; j < newLen; j++) {
|
|
1347
|
-
this.
|
|
1348
|
-
this.
|
|
1362
|
+
this.q[j] = newItems[j];
|
|
1363
|
+
this.k[j] = compute(this.f[j] = new Owner(), mapper, null);
|
|
1349
1364
|
}
|
|
1350
|
-
this.
|
|
1365
|
+
this.w = newLen;
|
|
1351
1366
|
} else {
|
|
1352
|
-
let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.
|
|
1353
|
-
for (start = 0, end = Math.min(this.
|
|
1354
|
-
if (this.
|
|
1355
|
-
this.
|
|
1367
|
+
let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.g ? new Array(newLen) : void 0, tempIndexes = this.l ? new Array(newLen) : void 0;
|
|
1368
|
+
for (start = 0, end = Math.min(this.w, newLen); start < end && (this.q[start] === newItems[start] || this.g && compare(this.y, this.q[start], newItems[start])); start++) {
|
|
1369
|
+
if (this.g)
|
|
1370
|
+
this.g[start].write(newItems[start]);
|
|
1356
1371
|
}
|
|
1357
|
-
for (end = this.
|
|
1358
|
-
temp[newEnd] = this.
|
|
1359
|
-
tempNodes[newEnd] = this.
|
|
1360
|
-
tempRows && (tempRows[newEnd] = this.
|
|
1361
|
-
tempIndexes && (tempIndexes[newEnd] = this.
|
|
1372
|
+
for (end = this.w - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.q[end] === newItems[newEnd] || this.g && compare(this.y, this.q[end], newItems[newEnd])); end--, newEnd--) {
|
|
1373
|
+
temp[newEnd] = this.k[end];
|
|
1374
|
+
tempNodes[newEnd] = this.f[end];
|
|
1375
|
+
tempRows && (tempRows[newEnd] = this.g[end]);
|
|
1376
|
+
tempIndexes && (tempIndexes[newEnd] = this.l[end]);
|
|
1362
1377
|
}
|
|
1363
1378
|
newIndices = /* @__PURE__ */ new Map();
|
|
1364
1379
|
newIndicesNext = new Array(newEnd + 1);
|
|
1365
1380
|
for (j = newEnd; j >= start; j--) {
|
|
1366
1381
|
item = newItems[j];
|
|
1367
|
-
key = this.
|
|
1382
|
+
key = this.y ? this.y(item) : item;
|
|
1368
1383
|
i = newIndices.get(key);
|
|
1369
1384
|
newIndicesNext[j] = i === void 0 ? -1 : i;
|
|
1370
1385
|
newIndices.set(key, j);
|
|
1371
1386
|
}
|
|
1372
1387
|
for (i = start; i <= end; i++) {
|
|
1373
|
-
item = this.
|
|
1374
|
-
key = this.
|
|
1388
|
+
item = this.q[i];
|
|
1389
|
+
key = this.y ? this.y(item) : item;
|
|
1375
1390
|
j = newIndices.get(key);
|
|
1376
1391
|
if (j !== void 0 && j !== -1) {
|
|
1377
|
-
temp[j] = this.
|
|
1378
|
-
tempNodes[j] = this.
|
|
1379
|
-
tempRows && (tempRows[j] = this.
|
|
1380
|
-
tempIndexes && (tempIndexes[j] = this.
|
|
1392
|
+
temp[j] = this.k[i];
|
|
1393
|
+
tempNodes[j] = this.f[i];
|
|
1394
|
+
tempRows && (tempRows[j] = this.g[i]);
|
|
1395
|
+
tempIndexes && (tempIndexes[j] = this.l[i]);
|
|
1381
1396
|
j = newIndicesNext[j];
|
|
1382
1397
|
newIndices.set(key, j);
|
|
1383
1398
|
} else
|
|
1384
|
-
this.
|
|
1399
|
+
this.f[i].dispose();
|
|
1385
1400
|
}
|
|
1386
1401
|
for (j = start; j < newLen; j++) {
|
|
1387
1402
|
if (j in temp) {
|
|
1388
|
-
this.
|
|
1389
|
-
this.
|
|
1403
|
+
this.k[j] = temp[j];
|
|
1404
|
+
this.f[j] = tempNodes[j];
|
|
1390
1405
|
if (tempRows) {
|
|
1391
|
-
this.
|
|
1392
|
-
this.
|
|
1406
|
+
this.g[j] = tempRows[j];
|
|
1407
|
+
this.g[j].write(newItems[j]);
|
|
1393
1408
|
}
|
|
1394
1409
|
if (tempIndexes) {
|
|
1395
|
-
this.
|
|
1396
|
-
this.
|
|
1410
|
+
this.l[j] = tempIndexes[j];
|
|
1411
|
+
this.l[j].write(j);
|
|
1397
1412
|
}
|
|
1398
1413
|
} else {
|
|
1399
|
-
this.
|
|
1414
|
+
this.k[j] = compute(this.f[j] = new Owner(), mapper, null);
|
|
1400
1415
|
}
|
|
1401
1416
|
}
|
|
1402
|
-
this.
|
|
1403
|
-
this.
|
|
1417
|
+
this.k = this.k.slice(0, this.w = newLen);
|
|
1418
|
+
this.q = newItems.slice(0);
|
|
1404
1419
|
}
|
|
1405
1420
|
});
|
|
1406
|
-
return this.
|
|
1421
|
+
return this.k;
|
|
1407
1422
|
}
|
|
1408
1423
|
function compare(key, a, b) {
|
|
1409
1424
|
return key ? key(a) === key(b) : true;
|
|
@@ -1419,6 +1434,7 @@ exports.NoOwnerError = NoOwnerError;
|
|
|
1419
1434
|
exports.NotReadyError = NotReadyError;
|
|
1420
1435
|
exports.Owner = Owner;
|
|
1421
1436
|
exports.Queue = Queue;
|
|
1437
|
+
exports.SUPPORTS_PROXY = SUPPORTS_PROXY;
|
|
1422
1438
|
exports.catchError = catchError;
|
|
1423
1439
|
exports.createAsync = createAsync;
|
|
1424
1440
|
exports.createBoundary = createBoundary;
|