@solidjs/signals 0.0.7 → 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 +215 -80
- package/dist/node.cjs +495 -356
- package/dist/prod.js +488 -356
- 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 +0 -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.
|
|
442
|
+
const prevOwner = setOwner(node.r);
|
|
440
443
|
const options = void 0;
|
|
441
444
|
const computation = new Computation(
|
|
442
445
|
void 0,
|
|
443
446
|
() => {
|
|
444
447
|
track(node);
|
|
445
|
-
node.
|
|
446
|
-
return !!(node.
|
|
448
|
+
node.x();
|
|
449
|
+
return !!(node.h & LOADING_BIT);
|
|
447
450
|
},
|
|
448
451
|
options
|
|
449
452
|
);
|
|
450
|
-
computation.
|
|
451
|
-
setOwner(prevOwner);
|
|
452
|
-
return computation;
|
|
453
|
-
}
|
|
454
|
-
function errorState(node) {
|
|
455
|
-
const prevOwner = setOwner(node.o);
|
|
456
|
-
const options = void 0;
|
|
457
|
-
const computation = new Computation(
|
|
458
|
-
void 0,
|
|
459
|
-
() => {
|
|
460
|
-
track(node);
|
|
461
|
-
node.t();
|
|
462
|
-
return !!(node.f & ERROR_BIT);
|
|
463
|
-
},
|
|
464
|
-
options
|
|
465
|
-
);
|
|
466
|
-
computation.D = ERROR_BIT;
|
|
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,93 +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
621
|
let rerun = false;
|
|
625
|
-
for (let i = 0; i < this.
|
|
626
|
-
rerun = this.
|
|
622
|
+
for (let i = 0; i < this.E.length; i++) {
|
|
623
|
+
rerun = this.E[i].run(type) || rerun;
|
|
627
624
|
}
|
|
628
|
-
if (type === EFFECT_PURE && this.
|
|
625
|
+
if (type === EFFECT_PURE && this.t[type].length)
|
|
629
626
|
return true;
|
|
630
627
|
}
|
|
631
628
|
flush() {
|
|
632
|
-
if (this.
|
|
629
|
+
if (this.I)
|
|
633
630
|
return;
|
|
634
|
-
this.
|
|
631
|
+
this.I = true;
|
|
635
632
|
try {
|
|
636
633
|
while (this.run(EFFECT_PURE)) {
|
|
637
634
|
}
|
|
638
|
-
;
|
|
639
635
|
incrementClock();
|
|
640
636
|
scheduled = false;
|
|
641
637
|
this.run(EFFECT_RENDER);
|
|
642
638
|
this.run(EFFECT_USER);
|
|
643
639
|
} finally {
|
|
644
|
-
this.
|
|
640
|
+
this.I = false;
|
|
645
641
|
}
|
|
646
642
|
}
|
|
647
643
|
addChild(child) {
|
|
648
|
-
this.
|
|
644
|
+
this.E.push(child);
|
|
649
645
|
}
|
|
650
646
|
removeChild(child) {
|
|
651
|
-
const index = this.
|
|
647
|
+
const index = this.E.indexOf(child);
|
|
652
648
|
if (index >= 0)
|
|
653
|
-
this.
|
|
649
|
+
this.E.splice(index, 1);
|
|
654
650
|
}
|
|
655
651
|
};
|
|
656
652
|
var globalQueue = new Queue();
|
|
657
|
-
var globalTasks = [];
|
|
658
653
|
function flushSync() {
|
|
659
654
|
while (scheduled) {
|
|
660
655
|
globalQueue.flush();
|
|
661
|
-
for (let i = 0; i < globalTasks.length; i++)
|
|
662
|
-
globalTasks[i]();
|
|
663
|
-
globalTasks.length = 0;
|
|
664
656
|
}
|
|
665
657
|
}
|
|
666
|
-
function queueTask(fn) {
|
|
667
|
-
globalTasks.push(fn);
|
|
668
|
-
schedule();
|
|
669
|
-
}
|
|
670
658
|
function createBoundary(fn, queue) {
|
|
671
659
|
const owner = new Owner();
|
|
672
|
-
const parentQueue = owner.
|
|
673
|
-
parentQueue.addChild(owner.
|
|
674
|
-
onCleanup(() => parentQueue.removeChild(owner.
|
|
660
|
+
const parentQueue = owner.g || globalQueue;
|
|
661
|
+
parentQueue.addChild(owner.g = queue);
|
|
662
|
+
onCleanup(() => parentQueue.removeChild(owner.g));
|
|
675
663
|
return compute(owner, fn, null);
|
|
676
664
|
}
|
|
677
665
|
function runTop(node) {
|
|
678
666
|
const ancestors = [];
|
|
679
|
-
for (let current = node; current !== null; current = current.
|
|
667
|
+
for (let current = node; current !== null; current = current.r) {
|
|
680
668
|
if (current.a !== STATE_CLEAN) {
|
|
681
669
|
ancestors.push(current);
|
|
682
670
|
}
|
|
683
671
|
}
|
|
684
672
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
685
673
|
if (ancestors[i].a !== STATE_DISPOSED)
|
|
686
|
-
ancestors[i].
|
|
674
|
+
ancestors[i].x();
|
|
687
675
|
}
|
|
688
676
|
}
|
|
689
677
|
function runPureQueue(queue) {
|
|
@@ -694,110 +682,138 @@ function runPureQueue(queue) {
|
|
|
694
682
|
}
|
|
695
683
|
function runEffectQueue(queue) {
|
|
696
684
|
for (let i = 0; i < queue.length; i++)
|
|
697
|
-
queue[i].
|
|
685
|
+
queue[i].V();
|
|
698
686
|
}
|
|
699
687
|
|
|
700
688
|
// src/core/effect.ts
|
|
701
689
|
var Effect = class extends Computation {
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
F;
|
|
690
|
+
J;
|
|
691
|
+
A;
|
|
705
692
|
B;
|
|
706
|
-
|
|
707
|
-
|
|
693
|
+
P = false;
|
|
694
|
+
K;
|
|
695
|
+
C;
|
|
696
|
+
g;
|
|
697
|
+
constructor(initialValue, compute2, effect, error, options) {
|
|
708
698
|
super(initialValue, compute2, options);
|
|
709
|
-
this.
|
|
710
|
-
this.
|
|
711
|
-
this.
|
|
712
|
-
this.
|
|
713
|
-
this.
|
|
714
|
-
|
|
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
|
+
}
|
|
715
708
|
}
|
|
716
709
|
write(value, flags = 0) {
|
|
717
|
-
const currentFlags = this.
|
|
718
|
-
this.
|
|
719
|
-
if (this.
|
|
720
|
-
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);
|
|
721
714
|
}
|
|
722
715
|
if (value === UNCHANGED)
|
|
723
|
-
return this.
|
|
724
|
-
this.
|
|
725
|
-
this.
|
|
716
|
+
return this.e;
|
|
717
|
+
this.e = value;
|
|
718
|
+
this.P = true;
|
|
726
719
|
return value;
|
|
727
720
|
}
|
|
728
|
-
|
|
729
|
-
if (this.a >= state)
|
|
721
|
+
q(state, skipQueue) {
|
|
722
|
+
if (this.a >= state || skipQueue)
|
|
730
723
|
return;
|
|
731
724
|
if (this.a === STATE_CLEAN)
|
|
732
|
-
this.
|
|
725
|
+
this.g.enqueue(this.C, this);
|
|
733
726
|
this.a = state;
|
|
734
727
|
}
|
|
735
|
-
|
|
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
|
+
}
|
|
736
741
|
this.handleError(error);
|
|
737
742
|
}
|
|
738
|
-
|
|
743
|
+
y() {
|
|
744
|
+
if (this.a === STATE_DISPOSED)
|
|
745
|
+
return;
|
|
746
|
+
this.J = void 0;
|
|
739
747
|
this.K = void 0;
|
|
740
|
-
this.
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
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
|
+
}
|
|
748
764
|
}
|
|
749
765
|
}
|
|
750
766
|
};
|
|
751
767
|
var EagerComputation = class extends Computation {
|
|
752
|
-
|
|
768
|
+
g;
|
|
753
769
|
constructor(initialValue, compute2, options) {
|
|
754
770
|
super(initialValue, compute2, options);
|
|
755
|
-
this.
|
|
756
|
-
this.
|
|
771
|
+
this.g = getOwner()?.g || globalQueue;
|
|
772
|
+
this.x();
|
|
757
773
|
}
|
|
758
|
-
|
|
759
|
-
if (this.a >= state)
|
|
774
|
+
q(state, skipQueue) {
|
|
775
|
+
if (this.a >= state && !this.H)
|
|
760
776
|
return;
|
|
761
|
-
if (this.a === STATE_CLEAN)
|
|
762
|
-
this.
|
|
763
|
-
super.
|
|
777
|
+
if (this.a === STATE_CLEAN && !skipQueue)
|
|
778
|
+
this.g.enqueue(EFFECT_PURE, this);
|
|
779
|
+
super.q(state, skipQueue);
|
|
764
780
|
}
|
|
765
781
|
};
|
|
766
782
|
|
|
767
783
|
// src/core/suspense.ts
|
|
768
784
|
var SuspenseQueue = class extends Queue {
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
785
|
+
c = /* @__PURE__ */ new Set();
|
|
786
|
+
o = false;
|
|
787
|
+
R = new Computation(false, null);
|
|
772
788
|
run(type) {
|
|
773
|
-
if (type && this.
|
|
789
|
+
if (type && this.o)
|
|
774
790
|
return;
|
|
775
791
|
return super.run(type);
|
|
776
792
|
}
|
|
777
|
-
|
|
778
|
-
if (node.
|
|
779
|
-
this.
|
|
780
|
-
if (!this.
|
|
781
|
-
this.
|
|
782
|
-
|
|
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);
|
|
783
799
|
}
|
|
784
800
|
} else {
|
|
785
|
-
this.
|
|
786
|
-
if (this.
|
|
787
|
-
this.
|
|
788
|
-
|
|
801
|
+
this.c.delete(node);
|
|
802
|
+
if (this.c.size === 0) {
|
|
803
|
+
this.o = false;
|
|
804
|
+
this.R.write(false);
|
|
789
805
|
}
|
|
790
806
|
}
|
|
791
807
|
}
|
|
792
808
|
};
|
|
793
809
|
var LiveComputation = class extends EagerComputation {
|
|
794
810
|
write(value, flags = 0) {
|
|
795
|
-
const currentFlags = this.
|
|
811
|
+
const currentFlags = this.h;
|
|
796
812
|
super.write(value, flags);
|
|
797
813
|
if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
798
|
-
this.
|
|
814
|
+
this.g.Q?.(this);
|
|
799
815
|
}
|
|
800
|
-
return this.
|
|
816
|
+
return this.e;
|
|
801
817
|
}
|
|
802
818
|
};
|
|
803
819
|
function createSuspense(fn, fallback) {
|
|
@@ -806,7 +822,7 @@ function createSuspense(fn, fallback) {
|
|
|
806
822
|
const child = new Computation(null, fn);
|
|
807
823
|
return new LiveComputation(null, () => flatten(child.wait()));
|
|
808
824
|
}, queue);
|
|
809
|
-
const equality = new Computation(null, () => queue.
|
|
825
|
+
const equality = new Computation(null, () => queue.R.read() || queue.o);
|
|
810
826
|
const comp = new Computation(null, () => equality.read() ? fallback() : tree.read());
|
|
811
827
|
return comp.read.bind(comp);
|
|
812
828
|
}
|
|
@@ -837,10 +853,10 @@ function createMemo(compute2, value, options) {
|
|
|
837
853
|
return () => {
|
|
838
854
|
if (node) {
|
|
839
855
|
resolvedValue = node.wait();
|
|
840
|
-
if (!node.
|
|
856
|
+
if (!node.d?.length && node.n?.r !== node) {
|
|
841
857
|
node.dispose();
|
|
842
858
|
node = void 0;
|
|
843
|
-
} else if (!node.
|
|
859
|
+
} else if (!node.r && !node.b?.length) {
|
|
844
860
|
node.dispose();
|
|
845
861
|
node.a = STATE_UNINITIALIZED;
|
|
846
862
|
}
|
|
@@ -851,10 +867,10 @@ function createMemo(compute2, value, options) {
|
|
|
851
867
|
function createAsync(compute2, value, options) {
|
|
852
868
|
const lhs = new EagerComputation(
|
|
853
869
|
{
|
|
854
|
-
|
|
870
|
+
e: value
|
|
855
871
|
},
|
|
856
872
|
(p) => {
|
|
857
|
-
const value2 = p?.
|
|
873
|
+
const value2 = p?.e;
|
|
858
874
|
const source = compute2(value2);
|
|
859
875
|
const isPromise = source instanceof Promise;
|
|
860
876
|
const iterator = source[Symbol.asyncIterator];
|
|
@@ -863,10 +879,18 @@ function createAsync(compute2, value, options) {
|
|
|
863
879
|
wait() {
|
|
864
880
|
return source;
|
|
865
881
|
},
|
|
866
|
-
|
|
882
|
+
e: source
|
|
867
883
|
};
|
|
868
884
|
}
|
|
869
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
|
+
};
|
|
870
894
|
signal.write(UNCHANGED, LOADING_BIT);
|
|
871
895
|
if (isPromise) {
|
|
872
896
|
source.then(
|
|
@@ -897,16 +921,17 @@ function createAsync(compute2, value, options) {
|
|
|
897
921
|
);
|
|
898
922
|
return () => lhs.wait().wait();
|
|
899
923
|
}
|
|
900
|
-
function createEffect(compute2, effect, value, options) {
|
|
924
|
+
function createEffect(compute2, effect, error, value, options) {
|
|
901
925
|
void new Effect(
|
|
902
926
|
value,
|
|
903
927
|
compute2,
|
|
904
928
|
effect,
|
|
929
|
+
error,
|
|
905
930
|
void 0
|
|
906
931
|
);
|
|
907
932
|
}
|
|
908
933
|
function createRenderEffect(compute2, effect, value, options) {
|
|
909
|
-
void new Effect(value, compute2, effect, {
|
|
934
|
+
void new Effect(value, compute2, effect, void 0, {
|
|
910
935
|
render: true,
|
|
911
936
|
...void 0
|
|
912
937
|
});
|
|
@@ -927,14 +952,14 @@ function createErrorBoundary(fn, fallback) {
|
|
|
927
952
|
const owner = new Owner();
|
|
928
953
|
const error = new Computation(null, null);
|
|
929
954
|
const reset = new Computation(null, null, { equals: false });
|
|
930
|
-
const handler = (err) => error.write({
|
|
931
|
-
owner.
|
|
955
|
+
const handler = (err) => error.write({ A: err });
|
|
956
|
+
owner.m = owner.m ? [handler, ...owner.m] : [handler];
|
|
932
957
|
const guarded = compute(
|
|
933
958
|
owner,
|
|
934
959
|
() => {
|
|
935
960
|
const c = new Computation(null, () => (reset.read(), fn()));
|
|
936
961
|
const f = new Computation(null, () => flatten(c.read()));
|
|
937
|
-
f.
|
|
962
|
+
f.O = function(error2) {
|
|
938
963
|
this.handleError(error2);
|
|
939
964
|
};
|
|
940
965
|
return f;
|
|
@@ -947,13 +972,78 @@ function createErrorBoundary(fn, fallback) {
|
|
|
947
972
|
if (!error.read())
|
|
948
973
|
return resolved;
|
|
949
974
|
}
|
|
950
|
-
return fallback(error.read().
|
|
975
|
+
return fallback(error.read().A, () => {
|
|
951
976
|
error.write(null);
|
|
952
977
|
reset.write(null);
|
|
953
978
|
});
|
|
954
979
|
});
|
|
955
980
|
return decision.read.bind(decision);
|
|
956
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
|
+
}
|
|
957
1047
|
|
|
958
1048
|
// src/store/store.ts
|
|
959
1049
|
var $RAW = Symbol(0);
|
|
@@ -963,7 +1053,7 @@ var $PROXY = Symbol(0);
|
|
|
963
1053
|
var STORE_VALUE = "v";
|
|
964
1054
|
var STORE_NODE = "n";
|
|
965
1055
|
var STORE_HAS = "h";
|
|
966
|
-
function
|
|
1056
|
+
function wrap2(value) {
|
|
967
1057
|
let p = value[$PROXY];
|
|
968
1058
|
if (!p) {
|
|
969
1059
|
let target;
|
|
@@ -1071,8 +1161,8 @@ var proxyTraps = {
|
|
|
1071
1161
|
return desc.get.call(receiver);
|
|
1072
1162
|
}
|
|
1073
1163
|
if (Writing.has(storeValue)) {
|
|
1074
|
-
const value2 = tracked ? tracked.
|
|
1075
|
-
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;
|
|
1076
1166
|
}
|
|
1077
1167
|
let value = tracked ? nodes[property].read() : storeValue[property];
|
|
1078
1168
|
if (!tracked) {
|
|
@@ -1080,10 +1170,10 @@ var proxyTraps = {
|
|
|
1080
1170
|
let proto;
|
|
1081
1171
|
return !Array.isArray(storeValue) && (proto = Object.getPrototypeOf(storeValue)) && proto !== Object.prototype ? value.bind(storeValue) : value;
|
|
1082
1172
|
} else if (getObserver()) {
|
|
1083
|
-
value = getNode(nodes, property, isWrappable(value) ?
|
|
1173
|
+
value = getNode(nodes, property, isWrappable(value) ? wrap2(value) : value).read();
|
|
1084
1174
|
}
|
|
1085
1175
|
}
|
|
1086
|
-
return isWrappable(value) ?
|
|
1176
|
+
return isWrappable(value) ? wrap2(value) : value;
|
|
1087
1177
|
},
|
|
1088
1178
|
has(target, property) {
|
|
1089
1179
|
if (property === $RAW || property === $PROXY || property === $TRACK || property === "__proto__")
|
|
@@ -1125,13 +1215,16 @@ function setProperty(state, property, value, deleting = false) {
|
|
|
1125
1215
|
const nodes = getNodes(target, STORE_NODE);
|
|
1126
1216
|
let node;
|
|
1127
1217
|
if (node = nodes[property])
|
|
1128
|
-
node.write(isWrappable(value) ?
|
|
1218
|
+
node.write(isWrappable(value) ? wrap2(value) : value);
|
|
1129
1219
|
Array.isArray(state) && state.length !== len && (node = nodes.length) && node.write(state.length);
|
|
1130
1220
|
(node = nodes[$TRACK]) && node.write(void 0);
|
|
1131
1221
|
}
|
|
1132
1222
|
function createStore(first, second) {
|
|
1133
|
-
const derived = typeof first === "function", store = derived ? second : first
|
|
1134
|
-
|
|
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);
|
|
1135
1228
|
const setStore = (fn) => {
|
|
1136
1229
|
try {
|
|
1137
1230
|
Writing.add(unwrappedStore);
|
|
@@ -1140,15 +1233,8 @@ function createStore(first, second) {
|
|
|
1140
1233
|
Writing.clear();
|
|
1141
1234
|
}
|
|
1142
1235
|
};
|
|
1143
|
-
if (derived) {
|
|
1144
|
-
new EagerComputation(void 0, () => setStore(first));
|
|
1145
|
-
}
|
|
1146
1236
|
return [wrappedStore, setStore];
|
|
1147
1237
|
}
|
|
1148
|
-
function createProjection(fn, initialValue = {}) {
|
|
1149
|
-
const [store] = createStore(fn, initialValue);
|
|
1150
|
-
return store;
|
|
1151
|
-
}
|
|
1152
1238
|
|
|
1153
1239
|
// src/store/reconcile.ts
|
|
1154
1240
|
function applyState(next, state, keyFn) {
|
|
@@ -1169,7 +1255,7 @@ function applyState(next, state, keyFn) {
|
|
|
1169
1255
|
if (next.length && previous.length && next[0] && keyFn(next[0]) != null) {
|
|
1170
1256
|
let i, j, start, end, newEnd, item, newIndicesNext, keyVal;
|
|
1171
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++) {
|
|
1172
|
-
applyState(next[start],
|
|
1258
|
+
applyState(next[start], wrap2(previous[start]), keyFn);
|
|
1173
1259
|
}
|
|
1174
1260
|
const temp = new Array(next.length), newIndices = /* @__PURE__ */ new Map();
|
|
1175
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--) {
|
|
@@ -1178,11 +1264,11 @@ function applyState(next, state, keyFn) {
|
|
|
1178
1264
|
if (start > newEnd || start > end) {
|
|
1179
1265
|
for (j = start; j <= newEnd; j++) {
|
|
1180
1266
|
changed = true;
|
|
1181
|
-
target[STORE_NODE][j]?.write(
|
|
1267
|
+
target[STORE_NODE][j]?.write(wrap2(next[j]));
|
|
1182
1268
|
}
|
|
1183
1269
|
for (; j < next.length; j++) {
|
|
1184
1270
|
changed = true;
|
|
1185
|
-
const wrapped =
|
|
1271
|
+
const wrapped = wrap2(temp[j]);
|
|
1186
1272
|
target[STORE_NODE][j]?.write(wrapped);
|
|
1187
1273
|
applyState(next[j], wrapped, keyFn);
|
|
1188
1274
|
}
|
|
@@ -1210,17 +1296,17 @@ function applyState(next, state, keyFn) {
|
|
|
1210
1296
|
}
|
|
1211
1297
|
for (j = start; j < next.length; j++) {
|
|
1212
1298
|
if (j in temp) {
|
|
1213
|
-
const wrapped =
|
|
1299
|
+
const wrapped = wrap2(temp[j]);
|
|
1214
1300
|
target[STORE_NODE][j]?.write(wrapped);
|
|
1215
1301
|
applyState(next[j], wrapped, keyFn);
|
|
1216
1302
|
} else
|
|
1217
|
-
target[STORE_NODE][j]?.write(
|
|
1303
|
+
target[STORE_NODE][j]?.write(wrap2(next[j]));
|
|
1218
1304
|
}
|
|
1219
1305
|
if (start < next.length)
|
|
1220
1306
|
changed = true;
|
|
1221
1307
|
} else if (previous.length && next.length) {
|
|
1222
1308
|
for (let i = 0, len = next.length; i < len; i++) {
|
|
1223
|
-
isWrappable(previous[i]) && applyState(next[i],
|
|
1309
|
+
isWrappable(previous[i]) && applyState(next[i], wrap2(previous[i]), keyFn);
|
|
1224
1310
|
}
|
|
1225
1311
|
}
|
|
1226
1312
|
if (previous.length !== next.length) {
|
|
@@ -1240,9 +1326,9 @@ function applyState(next, state, keyFn) {
|
|
|
1240
1326
|
if (previousValue === nextValue)
|
|
1241
1327
|
continue;
|
|
1242
1328
|
if (!previousValue || !isWrappable(previousValue) || keyFn(previousValue) != null && keyFn(previousValue) !== keyFn(nextValue))
|
|
1243
|
-
node.write(isWrappable(nextValue) ?
|
|
1329
|
+
node.write(isWrappable(nextValue) ? wrap2(nextValue) : nextValue);
|
|
1244
1330
|
else
|
|
1245
|
-
applyState(nextValue,
|
|
1331
|
+
applyState(nextValue, wrap2(previousValue), keyFn);
|
|
1246
1332
|
}
|
|
1247
1333
|
}
|
|
1248
1334
|
if (nodes = target[STORE_HAS]) {
|
|
@@ -1414,123 +1500,169 @@ function omit(props, ...keys) {
|
|
|
1414
1500
|
function mapArray(list, map, options) {
|
|
1415
1501
|
const keyFn = typeof options?.keyed === "function" ? options.keyed : void 0;
|
|
1416
1502
|
return updateKeyedMap.bind({
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
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
|
|
1428
1514
|
});
|
|
1429
1515
|
}
|
|
1430
1516
|
function updateKeyedMap() {
|
|
1431
|
-
const newItems = this.
|
|
1517
|
+
const newItems = this.W() || [], newLen = newItems.length;
|
|
1432
1518
|
newItems[$TRACK];
|
|
1433
|
-
runWithOwner(this.
|
|
1434
|
-
let i, j, mapper = this.
|
|
1435
|
-
this.
|
|
1436
|
-
this.
|
|
1437
|
-
return this.
|
|
1438
|
-
Computation.prototype.read.bind(this.
|
|
1439
|
-
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
|
|
1440
1526
|
);
|
|
1441
|
-
} : this.
|
|
1527
|
+
} : this.k ? () => {
|
|
1442
1528
|
const item = newItems[j];
|
|
1443
|
-
this.
|
|
1444
|
-
return this.
|
|
1529
|
+
this.k[j] = new Computation(j, null);
|
|
1530
|
+
return this.G(() => item, Computation.prototype.read.bind(this.k[j]));
|
|
1445
1531
|
} : () => {
|
|
1446
1532
|
const item = newItems[j];
|
|
1447
|
-
return this.
|
|
1533
|
+
return this.G(() => item);
|
|
1448
1534
|
};
|
|
1449
1535
|
if (newLen === 0) {
|
|
1450
|
-
if (this.
|
|
1451
|
-
this.
|
|
1452
|
-
this.
|
|
1453
|
-
this.
|
|
1454
|
-
this.
|
|
1455
|
-
this.
|
|
1456
|
-
this.
|
|
1457
|
-
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 = []);
|
|
1458
1544
|
}
|
|
1459
|
-
if (this.
|
|
1460
|
-
this.
|
|
1461
|
-
this.
|
|
1462
|
-
this.
|
|
1545
|
+
if (this.o && !this.f[0]) {
|
|
1546
|
+
this.f[0] = compute(
|
|
1547
|
+
this.c[0] = new Owner(),
|
|
1548
|
+
this.o,
|
|
1463
1549
|
null
|
|
1464
1550
|
);
|
|
1465
1551
|
}
|
|
1466
|
-
} else if (this.
|
|
1467
|
-
if (this.
|
|
1468
|
-
this.
|
|
1469
|
-
this.
|
|
1552
|
+
} else if (this.i === 0) {
|
|
1553
|
+
if (this.c[0])
|
|
1554
|
+
this.c[0].dispose();
|
|
1555
|
+
this.f = new Array(newLen);
|
|
1470
1556
|
for (j = 0; j < newLen; j++) {
|
|
1471
|
-
this.
|
|
1472
|
-
this.
|
|
1557
|
+
this.u[j] = newItems[j];
|
|
1558
|
+
this.f[j] = compute(this.c[j] = new Owner(), mapper, null);
|
|
1473
1559
|
}
|
|
1474
|
-
this.
|
|
1560
|
+
this.i = newLen;
|
|
1475
1561
|
} else {
|
|
1476
|
-
let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.
|
|
1477
|
-
for (start = 0, end = Math.min(this.
|
|
1478
|
-
if (this.
|
|
1479
|
-
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]);
|
|
1480
1566
|
}
|
|
1481
|
-
for (end = this.
|
|
1482
|
-
temp[newEnd] = this.
|
|
1483
|
-
tempNodes[newEnd] = this.
|
|
1484
|
-
tempRows && (tempRows[newEnd] = this.
|
|
1485
|
-
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]);
|
|
1486
1572
|
}
|
|
1487
1573
|
newIndices = /* @__PURE__ */ new Map();
|
|
1488
1574
|
newIndicesNext = new Array(newEnd + 1);
|
|
1489
1575
|
for (j = newEnd; j >= start; j--) {
|
|
1490
1576
|
item = newItems[j];
|
|
1491
|
-
key = this.
|
|
1577
|
+
key = this.D ? this.D(item) : item;
|
|
1492
1578
|
i = newIndices.get(key);
|
|
1493
1579
|
newIndicesNext[j] = i === void 0 ? -1 : i;
|
|
1494
1580
|
newIndices.set(key, j);
|
|
1495
1581
|
}
|
|
1496
1582
|
for (i = start; i <= end; i++) {
|
|
1497
|
-
item = this.
|
|
1498
|
-
key = this.
|
|
1583
|
+
item = this.u[i];
|
|
1584
|
+
key = this.D ? this.D(item) : item;
|
|
1499
1585
|
j = newIndices.get(key);
|
|
1500
1586
|
if (j !== void 0 && j !== -1) {
|
|
1501
|
-
temp[j] = this.
|
|
1502
|
-
tempNodes[j] = this.
|
|
1503
|
-
tempRows && (tempRows[j] = this.
|
|
1504
|
-
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]);
|
|
1505
1591
|
j = newIndicesNext[j];
|
|
1506
1592
|
newIndices.set(key, j);
|
|
1507
1593
|
} else
|
|
1508
|
-
this.
|
|
1594
|
+
this.c[i].dispose();
|
|
1509
1595
|
}
|
|
1510
1596
|
for (j = start; j < newLen; j++) {
|
|
1511
1597
|
if (j in temp) {
|
|
1512
|
-
this.
|
|
1513
|
-
this.
|
|
1598
|
+
this.f[j] = temp[j];
|
|
1599
|
+
this.c[j] = tempNodes[j];
|
|
1514
1600
|
if (tempRows) {
|
|
1515
|
-
this.
|
|
1516
|
-
this.
|
|
1601
|
+
this.j[j] = tempRows[j];
|
|
1602
|
+
this.j[j].write(newItems[j]);
|
|
1517
1603
|
}
|
|
1518
1604
|
if (tempIndexes) {
|
|
1519
|
-
this.
|
|
1520
|
-
this.
|
|
1605
|
+
this.k[j] = tempIndexes[j];
|
|
1606
|
+
this.k[j].write(j);
|
|
1521
1607
|
}
|
|
1522
1608
|
} else {
|
|
1523
|
-
this.
|
|
1609
|
+
this.f[j] = compute(this.c[j] = new Owner(), mapper, null);
|
|
1524
1610
|
}
|
|
1525
1611
|
}
|
|
1526
|
-
this.
|
|
1527
|
-
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;
|
|
1528
1660
|
}
|
|
1529
1661
|
});
|
|
1530
|
-
return this.
|
|
1662
|
+
return this.f;
|
|
1531
1663
|
}
|
|
1532
1664
|
function compare(key, a, b) {
|
|
1533
1665
|
return key ? key(a) === key(b) : true;
|
|
1534
1666
|
}
|
|
1535
1667
|
|
|
1536
|
-
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 };
|