@solidjs/signals 0.0.6 → 0.0.8
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 +222 -82
- package/dist/node.cjs +501 -357
- package/dist/prod.js +494 -357
- package/dist/types/core/core.d.ts +13 -9
- package/dist/types/core/effect.d.ts +7 -4
- package/dist/types/core/error.d.ts +3 -0
- package/dist/types/core/index.d.ts +2 -2
- package/dist/types/core/scheduler.d.ts +2 -3
- package/dist/types/core/suspense.d.ts +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/map.d.ts +9 -1
- package/dist/types/signals.d.ts +24 -3
- package/dist/types/store/index.d.ts +2 -1
- package/dist/types/store/projection.d.ts +6 -0
- package/dist/types/store/store.d.ts +0 -6
- package/package.json +1 -1
package/dist/prod.js
CHANGED
|
@@ -13,6 +13,12 @@ var ContextNotFoundError = class extends Error {
|
|
|
13
13
|
);
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
+
var EffectError = class extends Error {
|
|
17
|
+
constructor(effect, cause) {
|
|
18
|
+
super("");
|
|
19
|
+
this.cause = cause;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
16
22
|
|
|
17
23
|
// src/core/constants.ts
|
|
18
24
|
var STATE_CLEAN = 0;
|
|
@@ -99,82 +105,82 @@ var Owner = class {
|
|
|
99
105
|
// We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
|
|
100
106
|
// However, the children are actually added in reverse creation order
|
|
101
107
|
// See comment at the top of the file for an example of the _nextSibling traversal
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
108
|
+
r = null;
|
|
109
|
+
n = null;
|
|
110
|
+
s = null;
|
|
105
111
|
a = STATE_CLEAN;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
112
|
+
l = null;
|
|
113
|
+
p = defaultContext;
|
|
114
|
+
m = null;
|
|
115
|
+
g = null;
|
|
110
116
|
constructor(signal = false) {
|
|
111
117
|
if (currentOwner && !signal)
|
|
112
118
|
currentOwner.append(this);
|
|
113
119
|
}
|
|
114
120
|
append(child) {
|
|
115
|
-
child.
|
|
116
|
-
child.
|
|
117
|
-
if (this.
|
|
118
|
-
this.
|
|
119
|
-
child.
|
|
120
|
-
this.
|
|
121
|
-
if (child.
|
|
122
|
-
child.
|
|
121
|
+
child.r = this;
|
|
122
|
+
child.s = this;
|
|
123
|
+
if (this.n)
|
|
124
|
+
this.n.s = child;
|
|
125
|
+
child.n = this.n;
|
|
126
|
+
this.n = child;
|
|
127
|
+
if (child.p !== this.p) {
|
|
128
|
+
child.p = { ...this.p, ...child.p };
|
|
123
129
|
}
|
|
124
|
-
if (this.
|
|
125
|
-
child.
|
|
130
|
+
if (this.m) {
|
|
131
|
+
child.m = !child.m ? this.m : [...child.m, ...this.m];
|
|
126
132
|
}
|
|
127
|
-
if (this.
|
|
128
|
-
child.
|
|
133
|
+
if (this.g)
|
|
134
|
+
child.g = this.g;
|
|
129
135
|
}
|
|
130
136
|
dispose(self = true) {
|
|
131
137
|
if (this.a === STATE_DISPOSED)
|
|
132
138
|
return;
|
|
133
|
-
let head = self ? this.
|
|
134
|
-
while (current && current.
|
|
139
|
+
let head = self ? this.s || this.r : this, current = this.n, next = null;
|
|
140
|
+
while (current && current.r === this) {
|
|
135
141
|
current.dispose(true);
|
|
136
|
-
current.
|
|
137
|
-
next = current.
|
|
138
|
-
current.
|
|
142
|
+
current.y();
|
|
143
|
+
next = current.n;
|
|
144
|
+
current.n = null;
|
|
139
145
|
current = next;
|
|
140
146
|
}
|
|
141
147
|
if (self)
|
|
142
|
-
this.
|
|
148
|
+
this.y();
|
|
143
149
|
if (current)
|
|
144
|
-
current.
|
|
150
|
+
current.s = !self ? this : this.s;
|
|
145
151
|
if (head)
|
|
146
|
-
head.
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (this.
|
|
150
|
-
this.
|
|
151
|
-
this.
|
|
152
|
-
this.
|
|
153
|
-
this.
|
|
154
|
-
this.
|
|
152
|
+
head.n = current;
|
|
153
|
+
}
|
|
154
|
+
y() {
|
|
155
|
+
if (this.s)
|
|
156
|
+
this.s.n = null;
|
|
157
|
+
this.r = null;
|
|
158
|
+
this.s = null;
|
|
159
|
+
this.p = defaultContext;
|
|
160
|
+
this.m = null;
|
|
155
161
|
this.a = STATE_DISPOSED;
|
|
156
162
|
this.emptyDisposal();
|
|
157
163
|
}
|
|
158
164
|
emptyDisposal() {
|
|
159
|
-
if (!this.
|
|
165
|
+
if (!this.l)
|
|
160
166
|
return;
|
|
161
|
-
if (Array.isArray(this.
|
|
162
|
-
for (let i = 0; i < this.
|
|
163
|
-
const callable = this.
|
|
167
|
+
if (Array.isArray(this.l)) {
|
|
168
|
+
for (let i = 0; i < this.l.length; i++) {
|
|
169
|
+
const callable = this.l[i];
|
|
164
170
|
callable.call(callable);
|
|
165
171
|
}
|
|
166
172
|
} else {
|
|
167
|
-
this.
|
|
173
|
+
this.l.call(this.l);
|
|
168
174
|
}
|
|
169
|
-
this.
|
|
175
|
+
this.l = null;
|
|
170
176
|
}
|
|
171
177
|
handleError(error) {
|
|
172
|
-
if (!this.
|
|
178
|
+
if (!this.m)
|
|
173
179
|
throw error;
|
|
174
|
-
let i = 0, len = this.
|
|
180
|
+
let i = 0, len = this.m.length;
|
|
175
181
|
for (i = 0; i < len; i++) {
|
|
176
182
|
try {
|
|
177
|
-
this.
|
|
183
|
+
this.m[i](error);
|
|
178
184
|
break;
|
|
179
185
|
} catch (e) {
|
|
180
186
|
error = e;
|
|
@@ -191,7 +197,7 @@ function getContext(context, owner = currentOwner) {
|
|
|
191
197
|
if (!owner) {
|
|
192
198
|
throw new NoOwnerError();
|
|
193
199
|
}
|
|
194
|
-
const value = hasContext(context, owner) ? owner.
|
|
200
|
+
const value = hasContext(context, owner) ? owner.p[context.id] : context.defaultValue;
|
|
195
201
|
if (isUndefined(value)) {
|
|
196
202
|
throw new ContextNotFoundError();
|
|
197
203
|
}
|
|
@@ -201,24 +207,24 @@ function setContext(context, value, owner = currentOwner) {
|
|
|
201
207
|
if (!owner) {
|
|
202
208
|
throw new NoOwnerError();
|
|
203
209
|
}
|
|
204
|
-
owner.
|
|
205
|
-
...owner.
|
|
210
|
+
owner.p = {
|
|
211
|
+
...owner.p,
|
|
206
212
|
[context.id]: isUndefined(value) ? context.defaultValue : value
|
|
207
213
|
};
|
|
208
214
|
}
|
|
209
215
|
function hasContext(context, owner = currentOwner) {
|
|
210
|
-
return !isUndefined(owner?.
|
|
216
|
+
return !isUndefined(owner?.p[context.id]);
|
|
211
217
|
}
|
|
212
218
|
function onCleanup(fn) {
|
|
213
219
|
if (!currentOwner)
|
|
214
220
|
return fn;
|
|
215
221
|
const node = currentOwner;
|
|
216
|
-
if (!node.
|
|
217
|
-
node.
|
|
218
|
-
} else if (Array.isArray(node.
|
|
219
|
-
node.
|
|
222
|
+
if (!node.l) {
|
|
223
|
+
node.l = fn;
|
|
224
|
+
} else if (Array.isArray(node.l)) {
|
|
225
|
+
node.l.push(fn);
|
|
220
226
|
} else {
|
|
221
|
-
node.
|
|
227
|
+
node.l = [node.l, fn];
|
|
222
228
|
}
|
|
223
229
|
return fn;
|
|
224
230
|
}
|
|
@@ -242,48 +248,51 @@ var updateCheck = null;
|
|
|
242
248
|
function getObserver() {
|
|
243
249
|
return currentObserver;
|
|
244
250
|
}
|
|
251
|
+
function getClock() {
|
|
252
|
+
return clock;
|
|
253
|
+
}
|
|
245
254
|
function incrementClock() {
|
|
246
255
|
clock++;
|
|
247
256
|
}
|
|
248
257
|
var UNCHANGED = Symbol(0);
|
|
249
258
|
var Computation = class extends Owner {
|
|
250
|
-
|
|
259
|
+
d = null;
|
|
251
260
|
b = null;
|
|
252
|
-
|
|
253
|
-
|
|
261
|
+
e;
|
|
262
|
+
w;
|
|
254
263
|
// Used in __DEV__ mode, hopefully removed in production
|
|
255
|
-
|
|
264
|
+
Y;
|
|
256
265
|
// Using false is an optimization as an alternative to _equals: () => false
|
|
257
266
|
// which could enable more efficient DIRTY notification
|
|
258
|
-
|
|
259
|
-
|
|
267
|
+
L = isEqual;
|
|
268
|
+
S;
|
|
260
269
|
/** Whether the computation is an error or has ancestors that are unresolved */
|
|
261
|
-
|
|
270
|
+
h = 0;
|
|
262
271
|
/** Which flags raised by sources are handled, vs. being passed through. */
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
272
|
+
M = DEFAULT_FLAGS;
|
|
273
|
+
N = null;
|
|
274
|
+
z = -1;
|
|
275
|
+
H = false;
|
|
267
276
|
constructor(initialValue, compute2, options) {
|
|
268
277
|
super(compute2 === null);
|
|
269
|
-
this.
|
|
278
|
+
this.w = compute2;
|
|
270
279
|
this.a = compute2 ? STATE_UNINITIALIZED : STATE_CLEAN;
|
|
271
|
-
this.
|
|
280
|
+
this.e = initialValue;
|
|
272
281
|
if (options?.equals !== void 0)
|
|
273
|
-
this.
|
|
282
|
+
this.L = options.equals;
|
|
274
283
|
if (options?.unobserved)
|
|
275
|
-
this.
|
|
284
|
+
this.S = options?.unobserved;
|
|
276
285
|
}
|
|
277
|
-
|
|
278
|
-
if (this.
|
|
279
|
-
this.
|
|
280
|
-
if (!this.
|
|
286
|
+
T() {
|
|
287
|
+
if (this.w)
|
|
288
|
+
this.x();
|
|
289
|
+
if (!this.w || this.d?.length)
|
|
281
290
|
track(this);
|
|
282
|
-
newFlags |= this.
|
|
283
|
-
if (this.
|
|
284
|
-
throw this.
|
|
291
|
+
newFlags |= this.h & ~currentMask;
|
|
292
|
+
if (this.h & ERROR_BIT) {
|
|
293
|
+
throw this.e;
|
|
285
294
|
} else {
|
|
286
|
-
return this.
|
|
295
|
+
return this.e;
|
|
287
296
|
}
|
|
288
297
|
}
|
|
289
298
|
/**
|
|
@@ -291,7 +300,7 @@ var Computation = class extends Owner {
|
|
|
291
300
|
* Automatically re-executes the surrounding computation when the value changes
|
|
292
301
|
*/
|
|
293
302
|
read() {
|
|
294
|
-
return this.
|
|
303
|
+
return this.T();
|
|
295
304
|
}
|
|
296
305
|
/**
|
|
297
306
|
* Return the current value of this computation
|
|
@@ -301,10 +310,13 @@ var Computation = class extends Owner {
|
|
|
301
310
|
* before continuing
|
|
302
311
|
*/
|
|
303
312
|
wait() {
|
|
313
|
+
if (this.w && this.h & ERROR_BIT && this.z <= clock) {
|
|
314
|
+
update(this);
|
|
315
|
+
}
|
|
304
316
|
if (!syncResolve && this.loading()) {
|
|
305
317
|
throw new NotReadyError();
|
|
306
318
|
}
|
|
307
|
-
return this.
|
|
319
|
+
return this.T();
|
|
308
320
|
}
|
|
309
321
|
/**
|
|
310
322
|
* Return true if the computation is the value is dependent on an unresolved promise
|
|
@@ -314,51 +326,42 @@ var Computation = class extends Owner {
|
|
|
314
326
|
* loading state changes
|
|
315
327
|
*/
|
|
316
328
|
loading() {
|
|
317
|
-
if (this.
|
|
318
|
-
this.
|
|
319
|
-
}
|
|
320
|
-
return this.H.read();
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Return true if the computation is the computation threw an error
|
|
324
|
-
* Triggers re-execution of the computation when the error state changes
|
|
325
|
-
*/
|
|
326
|
-
error() {
|
|
327
|
-
if (this.z === null) {
|
|
328
|
-
this.z = errorState(this);
|
|
329
|
+
if (this.N === null) {
|
|
330
|
+
this.N = loadingState(this);
|
|
329
331
|
}
|
|
330
|
-
return this.
|
|
332
|
+
return this.N.read();
|
|
331
333
|
}
|
|
332
334
|
/** Update the computation with a new value. */
|
|
333
335
|
write(value, flags = 0, raw = false) {
|
|
334
|
-
const newValue = !raw && typeof value === "function" ? value(this.
|
|
335
|
-
const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.a === STATE_UNINITIALIZED || this.
|
|
336
|
+
const newValue = !raw && typeof value === "function" ? value(this.e) : value;
|
|
337
|
+
const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.a === STATE_UNINITIALIZED || this.L === false || !this.L(this.e, newValue));
|
|
336
338
|
if (valueChanged)
|
|
337
|
-
this.
|
|
338
|
-
const changedFlagsMask = this.
|
|
339
|
-
this.
|
|
340
|
-
this.
|
|
339
|
+
this.e = newValue;
|
|
340
|
+
const changedFlagsMask = this.h ^ flags, changedFlags = changedFlagsMask & flags;
|
|
341
|
+
this.h = flags;
|
|
342
|
+
this.z = clock + 1;
|
|
341
343
|
if (this.b) {
|
|
342
344
|
for (let i = 0; i < this.b.length; i++) {
|
|
343
345
|
if (valueChanged) {
|
|
344
|
-
this.b[i].
|
|
346
|
+
this.b[i].q(STATE_DIRTY);
|
|
345
347
|
} else if (changedFlagsMask) {
|
|
346
|
-
this.b[i].
|
|
348
|
+
this.b[i].U(changedFlagsMask, changedFlags);
|
|
347
349
|
}
|
|
348
350
|
}
|
|
349
351
|
}
|
|
350
|
-
return this.
|
|
352
|
+
return this.e;
|
|
351
353
|
}
|
|
352
354
|
/**
|
|
353
355
|
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
|
354
356
|
*/
|
|
355
|
-
|
|
356
|
-
if (this.a >= state)
|
|
357
|
+
q(state, skipQueue) {
|
|
358
|
+
if (this.a >= state && !this.H)
|
|
357
359
|
return;
|
|
360
|
+
this.H = !!skipQueue;
|
|
358
361
|
this.a = state;
|
|
359
362
|
if (this.b) {
|
|
360
363
|
for (let i = 0; i < this.b.length; i++) {
|
|
361
|
-
this.b[i].
|
|
364
|
+
this.b[i].q(STATE_CHECK, skipQueue);
|
|
362
365
|
}
|
|
363
366
|
}
|
|
364
367
|
}
|
|
@@ -368,30 +371,30 @@ var Computation = class extends Owner {
|
|
|
368
371
|
* @param mask A bitmask for which flag(s) were changed.
|
|
369
372
|
* @param newFlags The source's new flags, masked to just the changed ones.
|
|
370
373
|
*/
|
|
371
|
-
|
|
374
|
+
U(mask, newFlags2) {
|
|
372
375
|
if (this.a >= STATE_DIRTY)
|
|
373
376
|
return;
|
|
374
|
-
if (mask & this.
|
|
375
|
-
this.
|
|
377
|
+
if (mask & this.M) {
|
|
378
|
+
this.q(STATE_DIRTY);
|
|
376
379
|
return;
|
|
377
380
|
}
|
|
378
381
|
if (this.a >= STATE_CHECK)
|
|
379
382
|
return;
|
|
380
|
-
const prevFlags = this.
|
|
383
|
+
const prevFlags = this.h & mask;
|
|
381
384
|
const deltaFlags = prevFlags ^ newFlags2;
|
|
382
385
|
if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
|
|
383
|
-
this.
|
|
386
|
+
this.q(STATE_CHECK);
|
|
384
387
|
} else {
|
|
385
|
-
this.
|
|
388
|
+
this.h ^= deltaFlags;
|
|
386
389
|
if (this.b) {
|
|
387
390
|
for (let i = 0; i < this.b.length; i++) {
|
|
388
|
-
this.b[i].
|
|
391
|
+
this.b[i].U(mask, newFlags2);
|
|
389
392
|
}
|
|
390
393
|
}
|
|
391
394
|
}
|
|
392
395
|
}
|
|
393
|
-
|
|
394
|
-
this.write(error, this.
|
|
396
|
+
O(error) {
|
|
397
|
+
this.write(error, this.h & ~LOADING_BIT | ERROR_BIT);
|
|
395
398
|
}
|
|
396
399
|
/**
|
|
397
400
|
* This is the core part of the reactivity system, which makes sure that the values are updated
|
|
@@ -400,7 +403,7 @@ var Computation = class extends Owner {
|
|
|
400
403
|
*
|
|
401
404
|
* This function will ensure that the value and states we read from the computation are up to date
|
|
402
405
|
*/
|
|
403
|
-
|
|
406
|
+
x() {
|
|
404
407
|
if (this.a === STATE_DISPOSED) {
|
|
405
408
|
throw new Error("Tried to read a disposed computation");
|
|
406
409
|
}
|
|
@@ -409,9 +412,9 @@ var Computation = class extends Owner {
|
|
|
409
412
|
}
|
|
410
413
|
let observerFlags = 0;
|
|
411
414
|
if (this.a === STATE_CHECK) {
|
|
412
|
-
for (let i = 0; i < this.
|
|
413
|
-
this.
|
|
414
|
-
observerFlags |= this.
|
|
415
|
+
for (let i = 0; i < this.d.length; i++) {
|
|
416
|
+
this.d[i].x();
|
|
417
|
+
observerFlags |= this.d[i].h;
|
|
415
418
|
if (this.a === STATE_DIRTY) {
|
|
416
419
|
break;
|
|
417
420
|
}
|
|
@@ -427,49 +430,33 @@ var Computation = class extends Owner {
|
|
|
427
430
|
/**
|
|
428
431
|
* Remove ourselves from the owner graph and the computation graph
|
|
429
432
|
*/
|
|
430
|
-
|
|
433
|
+
y() {
|
|
431
434
|
if (this.a === STATE_DISPOSED)
|
|
432
435
|
return;
|
|
433
|
-
if (this.
|
|
436
|
+
if (this.d)
|
|
434
437
|
removeSourceObservers(this, 0);
|
|
435
|
-
super.
|
|
438
|
+
super.y();
|
|
436
439
|
}
|
|
437
440
|
};
|
|
438
441
|
function loadingState(node) {
|
|
439
|
-
const prevOwner = setOwner(node.
|
|
440
|
-
const options = void 0;
|
|
441
|
-
const computation = new Computation(
|
|
442
|
-
void 0,
|
|
443
|
-
() => {
|
|
444
|
-
track(node);
|
|
445
|
-
node.s();
|
|
446
|
-
return !!(node.f & LOADING_BIT);
|
|
447
|
-
},
|
|
448
|
-
options
|
|
449
|
-
);
|
|
450
|
-
computation.D = ERROR_BIT | LOADING_BIT;
|
|
451
|
-
setOwner(prevOwner);
|
|
452
|
-
return computation;
|
|
453
|
-
}
|
|
454
|
-
function errorState(node) {
|
|
455
|
-
const prevOwner = setOwner(node.o);
|
|
442
|
+
const prevOwner = setOwner(node.r);
|
|
456
443
|
const options = void 0;
|
|
457
444
|
const computation = new Computation(
|
|
458
445
|
void 0,
|
|
459
446
|
() => {
|
|
460
447
|
track(node);
|
|
461
|
-
node.
|
|
462
|
-
return !!(node.
|
|
448
|
+
node.x();
|
|
449
|
+
return !!(node.h & LOADING_BIT);
|
|
463
450
|
},
|
|
464
451
|
options
|
|
465
452
|
);
|
|
466
|
-
computation.
|
|
453
|
+
computation.M = ERROR_BIT | LOADING_BIT;
|
|
467
454
|
setOwner(prevOwner);
|
|
468
455
|
return computation;
|
|
469
456
|
}
|
|
470
457
|
function track(computation) {
|
|
471
458
|
if (currentObserver) {
|
|
472
|
-
if (!newSources && currentObserver.
|
|
459
|
+
if (!newSources && currentObserver.d && currentObserver.d[newSourcesIndex] === computation) {
|
|
473
460
|
newSourcesIndex++;
|
|
474
461
|
} else if (!newSources)
|
|
475
462
|
newSources = [computation];
|
|
@@ -477,7 +464,7 @@ function track(computation) {
|
|
|
477
464
|
newSources.push(computation);
|
|
478
465
|
}
|
|
479
466
|
if (updateCheck) {
|
|
480
|
-
updateCheck.
|
|
467
|
+
updateCheck.e = computation.z > currentObserver.z;
|
|
481
468
|
}
|
|
482
469
|
}
|
|
483
470
|
}
|
|
@@ -489,55 +476,56 @@ function update(node) {
|
|
|
489
476
|
try {
|
|
490
477
|
node.dispose(false);
|
|
491
478
|
node.emptyDisposal();
|
|
492
|
-
const result = compute(node, node.
|
|
479
|
+
const result = compute(node, node.w, node);
|
|
493
480
|
node.write(result, newFlags, true);
|
|
494
481
|
} catch (error) {
|
|
495
482
|
if (error instanceof NotReadyError) {
|
|
496
483
|
node.write(UNCHANGED, newFlags | LOADING_BIT);
|
|
497
484
|
} else {
|
|
498
|
-
node.
|
|
485
|
+
node.O(error);
|
|
499
486
|
}
|
|
500
487
|
} finally {
|
|
501
488
|
if (newSources) {
|
|
502
|
-
if (node.
|
|
489
|
+
if (node.d)
|
|
503
490
|
removeSourceObservers(node, newSourcesIndex);
|
|
504
|
-
if (node.
|
|
505
|
-
node.
|
|
491
|
+
if (node.d && newSourcesIndex > 0) {
|
|
492
|
+
node.d.length = newSourcesIndex + newSources.length;
|
|
506
493
|
for (let i = 0; i < newSources.length; i++) {
|
|
507
|
-
node.
|
|
494
|
+
node.d[newSourcesIndex + i] = newSources[i];
|
|
508
495
|
}
|
|
509
496
|
} else {
|
|
510
|
-
node.
|
|
497
|
+
node.d = newSources;
|
|
511
498
|
}
|
|
512
499
|
let source;
|
|
513
|
-
for (let i = newSourcesIndex; i < node.
|
|
514
|
-
source = node.
|
|
500
|
+
for (let i = newSourcesIndex; i < node.d.length; i++) {
|
|
501
|
+
source = node.d[i];
|
|
515
502
|
if (!source.b)
|
|
516
503
|
source.b = [node];
|
|
517
504
|
else
|
|
518
505
|
source.b.push(node);
|
|
519
506
|
}
|
|
520
|
-
} else if (node.
|
|
507
|
+
} else if (node.d && newSourcesIndex < node.d.length) {
|
|
521
508
|
removeSourceObservers(node, newSourcesIndex);
|
|
522
|
-
node.
|
|
509
|
+
node.d.length = newSourcesIndex;
|
|
523
510
|
}
|
|
524
511
|
newSources = prevSources;
|
|
525
512
|
newSourcesIndex = prevSourcesIndex;
|
|
526
513
|
newFlags = prevFlags;
|
|
514
|
+
node.z = clock + 1;
|
|
527
515
|
node.a = STATE_CLEAN;
|
|
528
516
|
}
|
|
529
517
|
}
|
|
530
518
|
function removeSourceObservers(node, index) {
|
|
531
519
|
let source;
|
|
532
520
|
let swap;
|
|
533
|
-
for (let i = index; i < node.
|
|
534
|
-
source = node.
|
|
521
|
+
for (let i = index; i < node.d.length; i++) {
|
|
522
|
+
source = node.d[i];
|
|
535
523
|
if (source.b) {
|
|
536
524
|
swap = source.b.indexOf(node);
|
|
537
525
|
source.b[swap] = source.b[source.b.length - 1];
|
|
538
526
|
source.b.pop();
|
|
539
527
|
if (!source.b.length)
|
|
540
|
-
source.
|
|
528
|
+
source.S?.();
|
|
541
529
|
}
|
|
542
530
|
}
|
|
543
531
|
}
|
|
@@ -551,10 +539,10 @@ function untrack(fn) {
|
|
|
551
539
|
}
|
|
552
540
|
function hasUpdated(fn) {
|
|
553
541
|
const current = updateCheck;
|
|
554
|
-
updateCheck = {
|
|
542
|
+
updateCheck = { e: false };
|
|
555
543
|
try {
|
|
556
544
|
fn();
|
|
557
|
-
return updateCheck.
|
|
545
|
+
return updateCheck.e;
|
|
558
546
|
} finally {
|
|
559
547
|
updateCheck = current;
|
|
560
548
|
}
|
|
@@ -567,7 +555,7 @@ function isPending(fn) {
|
|
|
567
555
|
return e instanceof NotReadyError;
|
|
568
556
|
}
|
|
569
557
|
}
|
|
570
|
-
function
|
|
558
|
+
function resolveSync(fn) {
|
|
571
559
|
const prevFlags = newFlags;
|
|
572
560
|
syncResolve = true;
|
|
573
561
|
try {
|
|
@@ -578,12 +566,21 @@ function latest(fn) {
|
|
|
578
566
|
syncResolve = false;
|
|
579
567
|
}
|
|
580
568
|
}
|
|
569
|
+
function catchError(fn) {
|
|
570
|
+
try {
|
|
571
|
+
fn();
|
|
572
|
+
} catch (e) {
|
|
573
|
+
if (e instanceof NotReadyError)
|
|
574
|
+
throw e;
|
|
575
|
+
return e;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
581
578
|
function compute(owner, compute2, observer) {
|
|
582
579
|
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask;
|
|
583
580
|
currentObserver = observer;
|
|
584
|
-
currentMask = observer?.
|
|
581
|
+
currentMask = observer?.M ?? DEFAULT_FLAGS;
|
|
585
582
|
try {
|
|
586
|
-
return compute2(observer ? observer.
|
|
583
|
+
return compute2(observer ? observer.e : void 0);
|
|
587
584
|
} finally {
|
|
588
585
|
setOwner(prevOwner);
|
|
589
586
|
currentObserver = prevObserver;
|
|
@@ -597,88 +594,84 @@ function schedule() {
|
|
|
597
594
|
if (scheduled)
|
|
598
595
|
return;
|
|
599
596
|
scheduled = true;
|
|
600
|
-
if (!globalQueue.
|
|
597
|
+
if (!globalQueue.I)
|
|
601
598
|
queueMicrotask(flushSync);
|
|
602
599
|
}
|
|
603
600
|
var Queue = class {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
601
|
+
I = false;
|
|
602
|
+
t = [[], [], []];
|
|
603
|
+
E = [];
|
|
607
604
|
enqueue(type, node) {
|
|
608
|
-
this.
|
|
605
|
+
this.t[0].push(node);
|
|
609
606
|
if (type)
|
|
610
|
-
this.
|
|
607
|
+
this.t[type].push(node);
|
|
611
608
|
schedule();
|
|
612
609
|
}
|
|
613
610
|
run(type) {
|
|
614
|
-
if (this.
|
|
611
|
+
if (this.t[type].length) {
|
|
615
612
|
if (type === EFFECT_PURE) {
|
|
616
|
-
runPureQueue(this.
|
|
617
|
-
this.
|
|
613
|
+
runPureQueue(this.t[type]);
|
|
614
|
+
this.t[type] = [];
|
|
618
615
|
} else {
|
|
619
|
-
const effects = this.
|
|
620
|
-
this.
|
|
616
|
+
const effects = this.t[type];
|
|
617
|
+
this.t[type] = [];
|
|
621
618
|
runEffectQueue(effects);
|
|
622
619
|
}
|
|
623
620
|
}
|
|
624
|
-
|
|
625
|
-
|
|
621
|
+
let rerun = false;
|
|
622
|
+
for (let i = 0; i < this.E.length; i++) {
|
|
623
|
+
rerun = this.E[i].run(type) || rerun;
|
|
626
624
|
}
|
|
625
|
+
if (type === EFFECT_PURE && this.t[type].length)
|
|
626
|
+
return true;
|
|
627
627
|
}
|
|
628
628
|
flush() {
|
|
629
|
-
if (this.
|
|
629
|
+
if (this.I)
|
|
630
630
|
return;
|
|
631
|
-
this.
|
|
631
|
+
this.I = true;
|
|
632
632
|
try {
|
|
633
|
-
this.run(EFFECT_PURE)
|
|
633
|
+
while (this.run(EFFECT_PURE)) {
|
|
634
|
+
}
|
|
634
635
|
incrementClock();
|
|
635
636
|
scheduled = false;
|
|
636
637
|
this.run(EFFECT_RENDER);
|
|
637
638
|
this.run(EFFECT_USER);
|
|
638
639
|
} finally {
|
|
639
|
-
this.
|
|
640
|
+
this.I = false;
|
|
640
641
|
}
|
|
641
642
|
}
|
|
642
643
|
addChild(child) {
|
|
643
|
-
this.
|
|
644
|
+
this.E.push(child);
|
|
644
645
|
}
|
|
645
646
|
removeChild(child) {
|
|
646
|
-
const index = this.
|
|
647
|
+
const index = this.E.indexOf(child);
|
|
647
648
|
if (index >= 0)
|
|
648
|
-
this.
|
|
649
|
+
this.E.splice(index, 1);
|
|
649
650
|
}
|
|
650
651
|
};
|
|
651
652
|
var globalQueue = new Queue();
|
|
652
|
-
var globalTasks = [];
|
|
653
653
|
function flushSync() {
|
|
654
654
|
while (scheduled) {
|
|
655
655
|
globalQueue.flush();
|
|
656
|
-
for (let i = 0; i < globalTasks.length; i++)
|
|
657
|
-
globalTasks[i]();
|
|
658
|
-
globalTasks.length = 0;
|
|
659
656
|
}
|
|
660
657
|
}
|
|
661
|
-
function queueTask(fn) {
|
|
662
|
-
globalTasks.push(fn);
|
|
663
|
-
schedule();
|
|
664
|
-
}
|
|
665
658
|
function createBoundary(fn, queue) {
|
|
666
659
|
const owner = new Owner();
|
|
667
|
-
const parentQueue = owner.
|
|
668
|
-
parentQueue.addChild(owner.
|
|
669
|
-
onCleanup(() => parentQueue.removeChild(owner.
|
|
660
|
+
const parentQueue = owner.g || globalQueue;
|
|
661
|
+
parentQueue.addChild(owner.g = queue);
|
|
662
|
+
onCleanup(() => parentQueue.removeChild(owner.g));
|
|
670
663
|
return compute(owner, fn, null);
|
|
671
664
|
}
|
|
672
665
|
function runTop(node) {
|
|
673
666
|
const ancestors = [];
|
|
674
|
-
for (let current = node; current !== null; current = current.
|
|
667
|
+
for (let current = node; current !== null; current = current.r) {
|
|
675
668
|
if (current.a !== STATE_CLEAN) {
|
|
676
669
|
ancestors.push(current);
|
|
677
670
|
}
|
|
678
671
|
}
|
|
679
672
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
680
673
|
if (ancestors[i].a !== STATE_DISPOSED)
|
|
681
|
-
ancestors[i].
|
|
674
|
+
ancestors[i].x();
|
|
682
675
|
}
|
|
683
676
|
}
|
|
684
677
|
function runPureQueue(queue) {
|
|
@@ -689,110 +682,138 @@ function runPureQueue(queue) {
|
|
|
689
682
|
}
|
|
690
683
|
function runEffectQueue(queue) {
|
|
691
684
|
for (let i = 0; i < queue.length; i++)
|
|
692
|
-
queue[i].
|
|
685
|
+
queue[i].V();
|
|
693
686
|
}
|
|
694
687
|
|
|
695
688
|
// src/core/effect.ts
|
|
696
689
|
var Effect = class extends Computation {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
F;
|
|
690
|
+
J;
|
|
691
|
+
A;
|
|
700
692
|
B;
|
|
701
|
-
|
|
702
|
-
|
|
693
|
+
P = false;
|
|
694
|
+
K;
|
|
695
|
+
C;
|
|
696
|
+
g;
|
|
697
|
+
constructor(initialValue, compute2, effect, error, options) {
|
|
703
698
|
super(initialValue, compute2, options);
|
|
704
|
-
this.
|
|
705
|
-
this.
|
|
706
|
-
this.
|
|
707
|
-
this.
|
|
708
|
-
this.
|
|
709
|
-
|
|
699
|
+
this.J = effect;
|
|
700
|
+
this.A = error;
|
|
701
|
+
this.K = initialValue;
|
|
702
|
+
this.C = options?.render ? EFFECT_RENDER : EFFECT_USER;
|
|
703
|
+
this.g = getOwner()?.g || globalQueue;
|
|
704
|
+
if (!options?.defer) {
|
|
705
|
+
this.x();
|
|
706
|
+
this.C === EFFECT_USER ? this.g.enqueue(this.C, this) : this.V();
|
|
707
|
+
}
|
|
710
708
|
}
|
|
711
709
|
write(value, flags = 0) {
|
|
712
|
-
const currentFlags = this.
|
|
713
|
-
this.
|
|
714
|
-
if (this.
|
|
715
|
-
this.
|
|
710
|
+
const currentFlags = this.h;
|
|
711
|
+
this.h = flags;
|
|
712
|
+
if (this.C === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
713
|
+
this.g.Q?.(this);
|
|
716
714
|
}
|
|
717
715
|
if (value === UNCHANGED)
|
|
718
|
-
return this.
|
|
719
|
-
this.
|
|
720
|
-
this.
|
|
716
|
+
return this.e;
|
|
717
|
+
this.e = value;
|
|
718
|
+
this.P = true;
|
|
721
719
|
return value;
|
|
722
720
|
}
|
|
723
|
-
|
|
724
|
-
if (this.a >= state)
|
|
721
|
+
q(state, skipQueue) {
|
|
722
|
+
if (this.a >= state || skipQueue)
|
|
725
723
|
return;
|
|
726
724
|
if (this.a === STATE_CLEAN)
|
|
727
|
-
this.
|
|
725
|
+
this.g.enqueue(this.C, this);
|
|
728
726
|
this.a = state;
|
|
729
727
|
}
|
|
730
|
-
|
|
728
|
+
O(error) {
|
|
729
|
+
this.B?.();
|
|
730
|
+
if (this.h & LOADING_BIT) {
|
|
731
|
+
this.h = 0;
|
|
732
|
+
this.g.Q?.(this);
|
|
733
|
+
}
|
|
734
|
+
if (this.C === EFFECT_USER) {
|
|
735
|
+
try {
|
|
736
|
+
return this.A ? this.B = this.A(error) : console.error(new EffectError(this.J, error));
|
|
737
|
+
} catch (e) {
|
|
738
|
+
error = e;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
731
741
|
this.handleError(error);
|
|
732
742
|
}
|
|
733
|
-
|
|
743
|
+
y() {
|
|
744
|
+
if (this.a === STATE_DISPOSED)
|
|
745
|
+
return;
|
|
746
|
+
this.J = void 0;
|
|
734
747
|
this.K = void 0;
|
|
735
|
-
this.
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
this.
|
|
748
|
+
this.A = void 0;
|
|
749
|
+
this.B?.();
|
|
750
|
+
this.B = void 0;
|
|
751
|
+
super.y();
|
|
752
|
+
}
|
|
753
|
+
V() {
|
|
754
|
+
if (this.P && this.a !== STATE_DISPOSED) {
|
|
755
|
+
this.B?.();
|
|
756
|
+
try {
|
|
757
|
+
this.B = this.J(this.e, this.K);
|
|
758
|
+
} catch (e) {
|
|
759
|
+
this.handleError(e);
|
|
760
|
+
} finally {
|
|
761
|
+
this.K = this.e;
|
|
762
|
+
this.P = false;
|
|
763
|
+
}
|
|
743
764
|
}
|
|
744
765
|
}
|
|
745
766
|
};
|
|
746
767
|
var EagerComputation = class extends Computation {
|
|
747
|
-
|
|
768
|
+
g;
|
|
748
769
|
constructor(initialValue, compute2, options) {
|
|
749
770
|
super(initialValue, compute2, options);
|
|
750
|
-
this.
|
|
751
|
-
this.
|
|
771
|
+
this.g = getOwner()?.g || globalQueue;
|
|
772
|
+
this.x();
|
|
752
773
|
}
|
|
753
|
-
|
|
754
|
-
if (this.a >= state)
|
|
774
|
+
q(state, skipQueue) {
|
|
775
|
+
if (this.a >= state && !this.H)
|
|
755
776
|
return;
|
|
756
|
-
if (this.a === STATE_CLEAN)
|
|
757
|
-
this.
|
|
758
|
-
super.
|
|
777
|
+
if (this.a === STATE_CLEAN && !skipQueue)
|
|
778
|
+
this.g.enqueue(EFFECT_PURE, this);
|
|
779
|
+
super.q(state, skipQueue);
|
|
759
780
|
}
|
|
760
781
|
};
|
|
761
782
|
|
|
762
783
|
// src/core/suspense.ts
|
|
763
784
|
var SuspenseQueue = class extends Queue {
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
785
|
+
c = /* @__PURE__ */ new Set();
|
|
786
|
+
o = false;
|
|
787
|
+
R = new Computation(false, null);
|
|
767
788
|
run(type) {
|
|
768
|
-
if (type && this.
|
|
789
|
+
if (type && this.o)
|
|
769
790
|
return;
|
|
770
|
-
super.run(type);
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
if (node.
|
|
774
|
-
this.
|
|
775
|
-
if (!this.
|
|
776
|
-
this.
|
|
777
|
-
|
|
791
|
+
return super.run(type);
|
|
792
|
+
}
|
|
793
|
+
Q(node) {
|
|
794
|
+
if (node.h & LOADING_BIT) {
|
|
795
|
+
this.c.add(node);
|
|
796
|
+
if (!this.o) {
|
|
797
|
+
this.o = true;
|
|
798
|
+
this.R.write(true);
|
|
778
799
|
}
|
|
779
800
|
} else {
|
|
780
|
-
this.
|
|
781
|
-
if (this.
|
|
782
|
-
this.
|
|
783
|
-
|
|
801
|
+
this.c.delete(node);
|
|
802
|
+
if (this.c.size === 0) {
|
|
803
|
+
this.o = false;
|
|
804
|
+
this.R.write(false);
|
|
784
805
|
}
|
|
785
806
|
}
|
|
786
807
|
}
|
|
787
808
|
};
|
|
788
809
|
var LiveComputation = class extends EagerComputation {
|
|
789
810
|
write(value, flags = 0) {
|
|
790
|
-
const currentFlags = this.
|
|
811
|
+
const currentFlags = this.h;
|
|
791
812
|
super.write(value, flags);
|
|
792
813
|
if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
793
|
-
this.
|
|
814
|
+
this.g.Q?.(this);
|
|
794
815
|
}
|
|
795
|
-
return this.
|
|
816
|
+
return this.e;
|
|
796
817
|
}
|
|
797
818
|
};
|
|
798
819
|
function createSuspense(fn, fallback) {
|
|
@@ -801,7 +822,7 @@ function createSuspense(fn, fallback) {
|
|
|
801
822
|
const child = new Computation(null, fn);
|
|
802
823
|
return new LiveComputation(null, () => flatten(child.wait()));
|
|
803
824
|
}, queue);
|
|
804
|
-
const equality = new Computation(null, () => queue.
|
|
825
|
+
const equality = new Computation(null, () => queue.R.read() || queue.o);
|
|
805
826
|
const comp = new Computation(null, () => equality.read() ? fallback() : tree.read());
|
|
806
827
|
return comp.read.bind(comp);
|
|
807
828
|
}
|
|
@@ -832,10 +853,10 @@ function createMemo(compute2, value, options) {
|
|
|
832
853
|
return () => {
|
|
833
854
|
if (node) {
|
|
834
855
|
resolvedValue = node.wait();
|
|
835
|
-
if (!node.
|
|
856
|
+
if (!node.d?.length && node.n?.r !== node) {
|
|
836
857
|
node.dispose();
|
|
837
858
|
node = void 0;
|
|
838
|
-
} else if (!node.
|
|
859
|
+
} else if (!node.r && !node.b?.length) {
|
|
839
860
|
node.dispose();
|
|
840
861
|
node.a = STATE_UNINITIALIZED;
|
|
841
862
|
}
|
|
@@ -846,10 +867,10 @@ function createMemo(compute2, value, options) {
|
|
|
846
867
|
function createAsync(compute2, value, options) {
|
|
847
868
|
const lhs = new EagerComputation(
|
|
848
869
|
{
|
|
849
|
-
|
|
870
|
+
e: value
|
|
850
871
|
},
|
|
851
872
|
(p) => {
|
|
852
|
-
const value2 = p?.
|
|
873
|
+
const value2 = p?.e;
|
|
853
874
|
const source = compute2(value2);
|
|
854
875
|
const isPromise = source instanceof Promise;
|
|
855
876
|
const iterator = source[Symbol.asyncIterator];
|
|
@@ -858,10 +879,18 @@ function createAsync(compute2, value, options) {
|
|
|
858
879
|
wait() {
|
|
859
880
|
return source;
|
|
860
881
|
},
|
|
861
|
-
|
|
882
|
+
e: source
|
|
862
883
|
};
|
|
863
884
|
}
|
|
864
885
|
const signal = new Computation(value2, null, options);
|
|
886
|
+
const w = signal.wait;
|
|
887
|
+
signal.wait = function() {
|
|
888
|
+
if (signal.h & ERROR_BIT && signal.z <= getClock()) {
|
|
889
|
+
lhs.q(STATE_DIRTY);
|
|
890
|
+
throw new NotReadyError();
|
|
891
|
+
}
|
|
892
|
+
return w.call(this);
|
|
893
|
+
};
|
|
865
894
|
signal.write(UNCHANGED, LOADING_BIT);
|
|
866
895
|
if (isPromise) {
|
|
867
896
|
source.then(
|
|
@@ -892,16 +921,17 @@ function createAsync(compute2, value, options) {
|
|
|
892
921
|
);
|
|
893
922
|
return () => lhs.wait().wait();
|
|
894
923
|
}
|
|
895
|
-
function createEffect(compute2, effect, value, options) {
|
|
924
|
+
function createEffect(compute2, effect, error, value, options) {
|
|
896
925
|
void new Effect(
|
|
897
926
|
value,
|
|
898
927
|
compute2,
|
|
899
928
|
effect,
|
|
929
|
+
error,
|
|
900
930
|
void 0
|
|
901
931
|
);
|
|
902
932
|
}
|
|
903
933
|
function createRenderEffect(compute2, effect, value, options) {
|
|
904
|
-
void new Effect(value, compute2, effect, {
|
|
934
|
+
void new Effect(value, compute2, effect, void 0, {
|
|
905
935
|
render: true,
|
|
906
936
|
...void 0
|
|
907
937
|
});
|
|
@@ -922,14 +952,14 @@ function createErrorBoundary(fn, fallback) {
|
|
|
922
952
|
const owner = new Owner();
|
|
923
953
|
const error = new Computation(null, null);
|
|
924
954
|
const reset = new Computation(null, null, { equals: false });
|
|
925
|
-
const handler = (err) => error.write({
|
|
926
|
-
owner.
|
|
955
|
+
const handler = (err) => error.write({ A: err });
|
|
956
|
+
owner.m = owner.m ? [handler, ...owner.m] : [handler];
|
|
927
957
|
const guarded = compute(
|
|
928
958
|
owner,
|
|
929
959
|
() => {
|
|
930
960
|
const c = new Computation(null, () => (reset.read(), fn()));
|
|
931
961
|
const f = new Computation(null, () => flatten(c.read()));
|
|
932
|
-
f.
|
|
962
|
+
f.O = function(error2) {
|
|
933
963
|
this.handleError(error2);
|
|
934
964
|
};
|
|
935
965
|
return f;
|
|
@@ -942,13 +972,78 @@ function createErrorBoundary(fn, fallback) {
|
|
|
942
972
|
if (!error.read())
|
|
943
973
|
return resolved;
|
|
944
974
|
}
|
|
945
|
-
return fallback(error.read().
|
|
975
|
+
return fallback(error.read().A, () => {
|
|
946
976
|
error.write(null);
|
|
947
977
|
reset.write(null);
|
|
948
978
|
});
|
|
949
979
|
});
|
|
950
980
|
return decision.read.bind(decision);
|
|
951
981
|
}
|
|
982
|
+
function resolve(fn) {
|
|
983
|
+
return new Promise((res, rej) => {
|
|
984
|
+
let node = new EagerComputation(void 0, () => {
|
|
985
|
+
try {
|
|
986
|
+
res(fn());
|
|
987
|
+
} catch (err) {
|
|
988
|
+
if (err instanceof NotReadyError)
|
|
989
|
+
throw err;
|
|
990
|
+
rej(err);
|
|
991
|
+
}
|
|
992
|
+
node.dispose(true);
|
|
993
|
+
});
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
function createReaction(effect, error, options) {
|
|
997
|
+
const node = new Effect(void 0, () => {
|
|
998
|
+
}, effect, error, {
|
|
999
|
+
defer: true,
|
|
1000
|
+
...void 0
|
|
1001
|
+
});
|
|
1002
|
+
return (tracking) => {
|
|
1003
|
+
node.w = tracking;
|
|
1004
|
+
node.a = STATE_DIRTY;
|
|
1005
|
+
node.x();
|
|
1006
|
+
node.w = null;
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
// src/store/projection.ts
|
|
1011
|
+
var ProjectionComputation = class extends EagerComputation {
|
|
1012
|
+
q(state, skipQueue) {
|
|
1013
|
+
if (this.a >= state && !this.H)
|
|
1014
|
+
return;
|
|
1015
|
+
if (this.a === STATE_CLEAN && !skipQueue)
|
|
1016
|
+
this.g.enqueue(EFFECT_PURE, this);
|
|
1017
|
+
super.q(state, true);
|
|
1018
|
+
}
|
|
1019
|
+
};
|
|
1020
|
+
function createProjection(fn, initialValue = {}) {
|
|
1021
|
+
const [store, setStore] = createStore(initialValue);
|
|
1022
|
+
const node = new ProjectionComputation(void 0, () => {
|
|
1023
|
+
setStore(fn);
|
|
1024
|
+
});
|
|
1025
|
+
const wrapped = /* @__PURE__ */ new WeakMap();
|
|
1026
|
+
return wrap(store, node, wrapped);
|
|
1027
|
+
}
|
|
1028
|
+
function wrap(source, node, wrapped) {
|
|
1029
|
+
if (wrapped.has(source))
|
|
1030
|
+
return wrapped.get(source);
|
|
1031
|
+
const wrap3 = new Proxy(source, {
|
|
1032
|
+
get(target, property) {
|
|
1033
|
+
node.read();
|
|
1034
|
+
const v = target[property];
|
|
1035
|
+
return isWrappable(v) ? wrap3(v, node, wrapped) : v;
|
|
1036
|
+
},
|
|
1037
|
+
set() {
|
|
1038
|
+
throw new Error("Projections are readonly");
|
|
1039
|
+
},
|
|
1040
|
+
deleteProperty() {
|
|
1041
|
+
throw new Error("Projections are readonly");
|
|
1042
|
+
}
|
|
1043
|
+
});
|
|
1044
|
+
wrapped.set(source, wrap3);
|
|
1045
|
+
return wrap3;
|
|
1046
|
+
}
|
|
952
1047
|
|
|
953
1048
|
// src/store/store.ts
|
|
954
1049
|
var $RAW = Symbol(0);
|
|
@@ -958,7 +1053,7 @@ var $PROXY = Symbol(0);
|
|
|
958
1053
|
var STORE_VALUE = "v";
|
|
959
1054
|
var STORE_NODE = "n";
|
|
960
1055
|
var STORE_HAS = "h";
|
|
961
|
-
function
|
|
1056
|
+
function wrap2(value) {
|
|
962
1057
|
let p = value[$PROXY];
|
|
963
1058
|
if (!p) {
|
|
964
1059
|
let target;
|
|
@@ -1066,8 +1161,8 @@ var proxyTraps = {
|
|
|
1066
1161
|
return desc.get.call(receiver);
|
|
1067
1162
|
}
|
|
1068
1163
|
if (Writing.has(storeValue)) {
|
|
1069
|
-
const value2 = tracked ? tracked.
|
|
1070
|
-
return isWrappable(value2) ? (Writing.add(value2[$RAW] || value2),
|
|
1164
|
+
const value2 = tracked ? tracked.e : storeValue[property];
|
|
1165
|
+
return isWrappable(value2) ? (Writing.add(value2[$RAW] || value2), wrap2(value2)) : value2;
|
|
1071
1166
|
}
|
|
1072
1167
|
let value = tracked ? nodes[property].read() : storeValue[property];
|
|
1073
1168
|
if (!tracked) {
|
|
@@ -1075,10 +1170,10 @@ var proxyTraps = {
|
|
|
1075
1170
|
let proto;
|
|
1076
1171
|
return !Array.isArray(storeValue) && (proto = Object.getPrototypeOf(storeValue)) && proto !== Object.prototype ? value.bind(storeValue) : value;
|
|
1077
1172
|
} else if (getObserver()) {
|
|
1078
|
-
value = getNode(nodes, property, isWrappable(value) ?
|
|
1173
|
+
value = getNode(nodes, property, isWrappable(value) ? wrap2(value) : value).read();
|
|
1079
1174
|
}
|
|
1080
1175
|
}
|
|
1081
|
-
return isWrappable(value) ?
|
|
1176
|
+
return isWrappable(value) ? wrap2(value) : value;
|
|
1082
1177
|
},
|
|
1083
1178
|
has(target, property) {
|
|
1084
1179
|
if (property === $RAW || property === $PROXY || property === $TRACK || property === "__proto__")
|
|
@@ -1120,13 +1215,16 @@ function setProperty(state, property, value, deleting = false) {
|
|
|
1120
1215
|
const nodes = getNodes(target, STORE_NODE);
|
|
1121
1216
|
let node;
|
|
1122
1217
|
if (node = nodes[property])
|
|
1123
|
-
node.write(isWrappable(value) ?
|
|
1218
|
+
node.write(isWrappable(value) ? wrap2(value) : value);
|
|
1124
1219
|
Array.isArray(state) && state.length !== len && (node = nodes.length) && node.write(state.length);
|
|
1125
1220
|
(node = nodes[$TRACK]) && node.write(void 0);
|
|
1126
1221
|
}
|
|
1127
1222
|
function createStore(first, second) {
|
|
1128
|
-
const derived = typeof first === "function", store = derived ? second : first
|
|
1129
|
-
|
|
1223
|
+
const derived = typeof first === "function", store = derived ? second : first;
|
|
1224
|
+
if (derived)
|
|
1225
|
+
return createProjection(first, store);
|
|
1226
|
+
const unwrappedStore = unwrap(store, false);
|
|
1227
|
+
const wrappedStore = wrap2(unwrappedStore);
|
|
1130
1228
|
const setStore = (fn) => {
|
|
1131
1229
|
try {
|
|
1132
1230
|
Writing.add(unwrappedStore);
|
|
@@ -1135,15 +1233,8 @@ function createStore(first, second) {
|
|
|
1135
1233
|
Writing.clear();
|
|
1136
1234
|
}
|
|
1137
1235
|
};
|
|
1138
|
-
if (derived) {
|
|
1139
|
-
new EagerComputation(void 0, () => setStore(first));
|
|
1140
|
-
}
|
|
1141
1236
|
return [wrappedStore, setStore];
|
|
1142
1237
|
}
|
|
1143
|
-
function createProjection(fn, initialValue = {}) {
|
|
1144
|
-
const [store] = createStore(fn, initialValue);
|
|
1145
|
-
return store;
|
|
1146
|
-
}
|
|
1147
1238
|
|
|
1148
1239
|
// src/store/reconcile.ts
|
|
1149
1240
|
function applyState(next, state, keyFn) {
|
|
@@ -1164,7 +1255,7 @@ function applyState(next, state, keyFn) {
|
|
|
1164
1255
|
if (next.length && previous.length && next[0] && keyFn(next[0]) != null) {
|
|
1165
1256
|
let i, j, start, end, newEnd, item, newIndicesNext, keyVal;
|
|
1166
1257
|
for (start = 0, end = Math.min(previous.length, next.length); start < end && (previous[start] === next[start] || previous[start] && next[start] && keyFn(previous[start]) === keyFn(next[start])); start++) {
|
|
1167
|
-
applyState(next[start],
|
|
1258
|
+
applyState(next[start], wrap2(previous[start]), keyFn);
|
|
1168
1259
|
}
|
|
1169
1260
|
const temp = new Array(next.length), newIndices = /* @__PURE__ */ new Map();
|
|
1170
1261
|
for (end = previous.length - 1, newEnd = next.length - 1; end >= start && newEnd >= start && (previous[end] === next[newEnd] || previous[end] && next[newEnd] && keyFn(previous[end]) === keyFn(next[newEnd])); end--, newEnd--) {
|
|
@@ -1173,11 +1264,11 @@ function applyState(next, state, keyFn) {
|
|
|
1173
1264
|
if (start > newEnd || start > end) {
|
|
1174
1265
|
for (j = start; j <= newEnd; j++) {
|
|
1175
1266
|
changed = true;
|
|
1176
|
-
target[STORE_NODE][j]?.write(
|
|
1267
|
+
target[STORE_NODE][j]?.write(wrap2(next[j]));
|
|
1177
1268
|
}
|
|
1178
1269
|
for (; j < next.length; j++) {
|
|
1179
1270
|
changed = true;
|
|
1180
|
-
const wrapped =
|
|
1271
|
+
const wrapped = wrap2(temp[j]);
|
|
1181
1272
|
target[STORE_NODE][j]?.write(wrapped);
|
|
1182
1273
|
applyState(next[j], wrapped, keyFn);
|
|
1183
1274
|
}
|
|
@@ -1205,17 +1296,17 @@ function applyState(next, state, keyFn) {
|
|
|
1205
1296
|
}
|
|
1206
1297
|
for (j = start; j < next.length; j++) {
|
|
1207
1298
|
if (j in temp) {
|
|
1208
|
-
const wrapped =
|
|
1299
|
+
const wrapped = wrap2(temp[j]);
|
|
1209
1300
|
target[STORE_NODE][j]?.write(wrapped);
|
|
1210
1301
|
applyState(next[j], wrapped, keyFn);
|
|
1211
1302
|
} else
|
|
1212
|
-
target[STORE_NODE][j]?.write(
|
|
1303
|
+
target[STORE_NODE][j]?.write(wrap2(next[j]));
|
|
1213
1304
|
}
|
|
1214
1305
|
if (start < next.length)
|
|
1215
1306
|
changed = true;
|
|
1216
1307
|
} else if (previous.length && next.length) {
|
|
1217
1308
|
for (let i = 0, len = next.length; i < len; i++) {
|
|
1218
|
-
isWrappable(previous[i]) && applyState(next[i],
|
|
1309
|
+
isWrappable(previous[i]) && applyState(next[i], wrap2(previous[i]), keyFn);
|
|
1219
1310
|
}
|
|
1220
1311
|
}
|
|
1221
1312
|
if (previous.length !== next.length) {
|
|
@@ -1235,9 +1326,9 @@ function applyState(next, state, keyFn) {
|
|
|
1235
1326
|
if (previousValue === nextValue)
|
|
1236
1327
|
continue;
|
|
1237
1328
|
if (!previousValue || !isWrappable(previousValue) || keyFn(previousValue) != null && keyFn(previousValue) !== keyFn(nextValue))
|
|
1238
|
-
node.write(isWrappable(nextValue) ?
|
|
1329
|
+
node.write(isWrappable(nextValue) ? wrap2(nextValue) : nextValue);
|
|
1239
1330
|
else
|
|
1240
|
-
applyState(nextValue,
|
|
1331
|
+
applyState(nextValue, wrap2(previousValue), keyFn);
|
|
1241
1332
|
}
|
|
1242
1333
|
}
|
|
1243
1334
|
if (nodes = target[STORE_HAS]) {
|
|
@@ -1409,123 +1500,169 @@ function omit(props, ...keys) {
|
|
|
1409
1500
|
function mapArray(list, map, options) {
|
|
1410
1501
|
const keyFn = typeof options?.keyed === "function" ? options.keyed : void 0;
|
|
1411
1502
|
return updateKeyedMap.bind({
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1503
|
+
F: new Owner(),
|
|
1504
|
+
i: 0,
|
|
1505
|
+
W: list,
|
|
1506
|
+
u: [],
|
|
1507
|
+
G: map,
|
|
1508
|
+
f: [],
|
|
1509
|
+
c: [],
|
|
1510
|
+
D: keyFn,
|
|
1511
|
+
j: keyFn || options?.keyed === false ? [] : void 0,
|
|
1512
|
+
k: map.length > 1 ? [] : void 0,
|
|
1513
|
+
o: options?.fallback
|
|
1423
1514
|
});
|
|
1424
1515
|
}
|
|
1425
1516
|
function updateKeyedMap() {
|
|
1426
|
-
const newItems = this.
|
|
1517
|
+
const newItems = this.W() || [], newLen = newItems.length;
|
|
1427
1518
|
newItems[$TRACK];
|
|
1428
|
-
runWithOwner(this.
|
|
1429
|
-
let i, j, mapper = this.
|
|
1430
|
-
this.
|
|
1431
|
-
this.
|
|
1432
|
-
return this.
|
|
1433
|
-
Computation.prototype.read.bind(this.
|
|
1434
|
-
this.
|
|
1519
|
+
runWithOwner(this.F, () => {
|
|
1520
|
+
let i, j, mapper = this.j ? () => {
|
|
1521
|
+
this.j[j] = new Computation(newItems[j], null);
|
|
1522
|
+
this.k && (this.k[j] = new Computation(j, null));
|
|
1523
|
+
return this.G(
|
|
1524
|
+
Computation.prototype.read.bind(this.j[j]),
|
|
1525
|
+
this.k ? Computation.prototype.read.bind(this.k[j]) : void 0
|
|
1435
1526
|
);
|
|
1436
|
-
} : this.
|
|
1527
|
+
} : this.k ? () => {
|
|
1437
1528
|
const item = newItems[j];
|
|
1438
|
-
this.
|
|
1439
|
-
return this.
|
|
1529
|
+
this.k[j] = new Computation(j, null);
|
|
1530
|
+
return this.G(() => item, Computation.prototype.read.bind(this.k[j]));
|
|
1440
1531
|
} : () => {
|
|
1441
1532
|
const item = newItems[j];
|
|
1442
|
-
return this.
|
|
1533
|
+
return this.G(() => item);
|
|
1443
1534
|
};
|
|
1444
1535
|
if (newLen === 0) {
|
|
1445
|
-
if (this.
|
|
1446
|
-
this.
|
|
1447
|
-
this.
|
|
1448
|
-
this.
|
|
1449
|
-
this.
|
|
1450
|
-
this.
|
|
1451
|
-
this.
|
|
1452
|
-
this.
|
|
1536
|
+
if (this.i !== 0) {
|
|
1537
|
+
this.F.dispose(false);
|
|
1538
|
+
this.c = [];
|
|
1539
|
+
this.u = [];
|
|
1540
|
+
this.f = [];
|
|
1541
|
+
this.i = 0;
|
|
1542
|
+
this.j && (this.j = []);
|
|
1543
|
+
this.k && (this.k = []);
|
|
1453
1544
|
}
|
|
1454
|
-
if (this.
|
|
1455
|
-
this.
|
|
1456
|
-
this.
|
|
1457
|
-
this.
|
|
1545
|
+
if (this.o && !this.f[0]) {
|
|
1546
|
+
this.f[0] = compute(
|
|
1547
|
+
this.c[0] = new Owner(),
|
|
1548
|
+
this.o,
|
|
1458
1549
|
null
|
|
1459
1550
|
);
|
|
1460
1551
|
}
|
|
1461
|
-
} else if (this.
|
|
1462
|
-
if (this.
|
|
1463
|
-
this.
|
|
1464
|
-
this.
|
|
1552
|
+
} else if (this.i === 0) {
|
|
1553
|
+
if (this.c[0])
|
|
1554
|
+
this.c[0].dispose();
|
|
1555
|
+
this.f = new Array(newLen);
|
|
1465
1556
|
for (j = 0; j < newLen; j++) {
|
|
1466
|
-
this.
|
|
1467
|
-
this.
|
|
1557
|
+
this.u[j] = newItems[j];
|
|
1558
|
+
this.f[j] = compute(this.c[j] = new Owner(), mapper, null);
|
|
1468
1559
|
}
|
|
1469
|
-
this.
|
|
1560
|
+
this.i = newLen;
|
|
1470
1561
|
} else {
|
|
1471
|
-
let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.
|
|
1472
|
-
for (start = 0, end = Math.min(this.
|
|
1473
|
-
if (this.
|
|
1474
|
-
this.
|
|
1562
|
+
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;
|
|
1563
|
+
for (start = 0, end = Math.min(this.i, newLen); start < end && (this.u[start] === newItems[start] || this.j && compare(this.D, this.u[start], newItems[start])); start++) {
|
|
1564
|
+
if (this.j)
|
|
1565
|
+
this.j[start].write(newItems[start]);
|
|
1475
1566
|
}
|
|
1476
|
-
for (end = this.
|
|
1477
|
-
temp[newEnd] = this.
|
|
1478
|
-
tempNodes[newEnd] = this.
|
|
1479
|
-
tempRows && (tempRows[newEnd] = this.
|
|
1480
|
-
tempIndexes && (tempIndexes[newEnd] = this.
|
|
1567
|
+
for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.u[end] === newItems[newEnd] || this.j && compare(this.D, this.u[end], newItems[newEnd])); end--, newEnd--) {
|
|
1568
|
+
temp[newEnd] = this.f[end];
|
|
1569
|
+
tempNodes[newEnd] = this.c[end];
|
|
1570
|
+
tempRows && (tempRows[newEnd] = this.j[end]);
|
|
1571
|
+
tempIndexes && (tempIndexes[newEnd] = this.k[end]);
|
|
1481
1572
|
}
|
|
1482
1573
|
newIndices = /* @__PURE__ */ new Map();
|
|
1483
1574
|
newIndicesNext = new Array(newEnd + 1);
|
|
1484
1575
|
for (j = newEnd; j >= start; j--) {
|
|
1485
1576
|
item = newItems[j];
|
|
1486
|
-
key = this.
|
|
1577
|
+
key = this.D ? this.D(item) : item;
|
|
1487
1578
|
i = newIndices.get(key);
|
|
1488
1579
|
newIndicesNext[j] = i === void 0 ? -1 : i;
|
|
1489
1580
|
newIndices.set(key, j);
|
|
1490
1581
|
}
|
|
1491
1582
|
for (i = start; i <= end; i++) {
|
|
1492
|
-
item = this.
|
|
1493
|
-
key = this.
|
|
1583
|
+
item = this.u[i];
|
|
1584
|
+
key = this.D ? this.D(item) : item;
|
|
1494
1585
|
j = newIndices.get(key);
|
|
1495
1586
|
if (j !== void 0 && j !== -1) {
|
|
1496
|
-
temp[j] = this.
|
|
1497
|
-
tempNodes[j] = this.
|
|
1498
|
-
tempRows && (tempRows[j] = this.
|
|
1499
|
-
tempIndexes && (tempIndexes[j] = this.
|
|
1587
|
+
temp[j] = this.f[i];
|
|
1588
|
+
tempNodes[j] = this.c[i];
|
|
1589
|
+
tempRows && (tempRows[j] = this.j[i]);
|
|
1590
|
+
tempIndexes && (tempIndexes[j] = this.k[i]);
|
|
1500
1591
|
j = newIndicesNext[j];
|
|
1501
1592
|
newIndices.set(key, j);
|
|
1502
1593
|
} else
|
|
1503
|
-
this.
|
|
1594
|
+
this.c[i].dispose();
|
|
1504
1595
|
}
|
|
1505
1596
|
for (j = start; j < newLen; j++) {
|
|
1506
1597
|
if (j in temp) {
|
|
1507
|
-
this.
|
|
1508
|
-
this.
|
|
1598
|
+
this.f[j] = temp[j];
|
|
1599
|
+
this.c[j] = tempNodes[j];
|
|
1509
1600
|
if (tempRows) {
|
|
1510
|
-
this.
|
|
1511
|
-
this.
|
|
1601
|
+
this.j[j] = tempRows[j];
|
|
1602
|
+
this.j[j].write(newItems[j]);
|
|
1512
1603
|
}
|
|
1513
1604
|
if (tempIndexes) {
|
|
1514
|
-
this.
|
|
1515
|
-
this.
|
|
1605
|
+
this.k[j] = tempIndexes[j];
|
|
1606
|
+
this.k[j].write(j);
|
|
1516
1607
|
}
|
|
1517
1608
|
} else {
|
|
1518
|
-
this.
|
|
1609
|
+
this.f[j] = compute(this.c[j] = new Owner(), mapper, null);
|
|
1519
1610
|
}
|
|
1520
1611
|
}
|
|
1521
|
-
this.
|
|
1522
|
-
this.
|
|
1612
|
+
this.f = this.f.slice(0, this.i = newLen);
|
|
1613
|
+
this.u = newItems.slice(0);
|
|
1614
|
+
}
|
|
1615
|
+
});
|
|
1616
|
+
return this.f;
|
|
1617
|
+
}
|
|
1618
|
+
function repeat(count, map, options) {
|
|
1619
|
+
return updateRepeat.bind({
|
|
1620
|
+
F: new Owner(),
|
|
1621
|
+
i: 0,
|
|
1622
|
+
X: count,
|
|
1623
|
+
G: map,
|
|
1624
|
+
c: [],
|
|
1625
|
+
f: [],
|
|
1626
|
+
o: options?.fallback
|
|
1627
|
+
});
|
|
1628
|
+
}
|
|
1629
|
+
function updateRepeat() {
|
|
1630
|
+
const newLen = this.X();
|
|
1631
|
+
runWithOwner(this.F, () => {
|
|
1632
|
+
if (newLen === 0) {
|
|
1633
|
+
if (this.i !== 0) {
|
|
1634
|
+
this.F.dispose(false);
|
|
1635
|
+
this.c = [];
|
|
1636
|
+
this.f = [];
|
|
1637
|
+
this.i = 0;
|
|
1638
|
+
}
|
|
1639
|
+
if (this.o && !this.f[0]) {
|
|
1640
|
+
this.f[0] = compute(
|
|
1641
|
+
this.c[0] = new Owner(),
|
|
1642
|
+
this.o,
|
|
1643
|
+
null
|
|
1644
|
+
);
|
|
1645
|
+
}
|
|
1646
|
+
} else {
|
|
1647
|
+
if (this.i === 0 && this.c[0])
|
|
1648
|
+
this.c[0].dispose();
|
|
1649
|
+
for (let i = this.i; i < newLen; i++) {
|
|
1650
|
+
this.f[i] = compute(
|
|
1651
|
+
this.c[i] = new Owner(),
|
|
1652
|
+
() => this.G(i),
|
|
1653
|
+
null
|
|
1654
|
+
);
|
|
1655
|
+
}
|
|
1656
|
+
for (let i = newLen; i < this.i; i++)
|
|
1657
|
+
this.c[i].dispose();
|
|
1658
|
+
this.f = this.f.slice(0, newLen);
|
|
1659
|
+
this.i = newLen;
|
|
1523
1660
|
}
|
|
1524
1661
|
});
|
|
1525
|
-
return this.
|
|
1662
|
+
return this.f;
|
|
1526
1663
|
}
|
|
1527
1664
|
function compare(key, a, b) {
|
|
1528
1665
|
return key ? key(a) === key(b) : true;
|
|
1529
1666
|
}
|
|
1530
1667
|
|
|
1531
|
-
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable,
|
|
1668
|
+
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createProjection, createReaction, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, resolveSync, runWithOwner, setContext, untrack, unwrap };
|