@solidjs/signals 0.2.5 → 0.3.0
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 +170 -175
- package/dist/node.cjs +394 -401
- package/dist/prod.js +392 -397
- package/dist/types/core/{suspense.d.ts → boundaries.d.ts} +3 -3
- package/dist/types/core/core.d.ts +1 -13
- package/dist/types/core/index.d.ts +4 -3
- package/dist/types/core/owner.d.ts +6 -1
- package/dist/types/core/scheduler.d.ts +1 -1
- package/dist/types/core/utils.d.ts +3 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/signals.d.ts +3 -11
- package/package.json +1 -1
package/dist/prod.js
CHANGED
|
@@ -72,8 +72,8 @@ var Queue = class {
|
|
|
72
72
|
for (let i = 0; i < this.F.length; i++) {
|
|
73
73
|
rerun = this.F[i].run(type) || rerun;
|
|
74
74
|
}
|
|
75
|
-
if (type === EFFECT_PURE
|
|
76
|
-
return
|
|
75
|
+
if (type === EFFECT_PURE)
|
|
76
|
+
return rerun || !!this.s[type].length;
|
|
77
77
|
}
|
|
78
78
|
flush() {
|
|
79
79
|
if (this.J)
|
|
@@ -107,14 +107,14 @@ function flushSync() {
|
|
|
107
107
|
}
|
|
108
108
|
function runTop(node) {
|
|
109
109
|
const ancestors = [];
|
|
110
|
-
for (let current = node; current !== null; current = current.
|
|
110
|
+
for (let current = node; current !== null; current = current.x) {
|
|
111
111
|
if (current.a !== STATE_CLEAN) {
|
|
112
112
|
ancestors.push(current);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
116
116
|
if (ancestors[i].a !== STATE_DISPOSED)
|
|
117
|
-
ancestors[i].
|
|
117
|
+
ancestors[i].y();
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
function runPureQueue(queue) {
|
|
@@ -125,13 +125,33 @@ function runPureQueue(queue) {
|
|
|
125
125
|
}
|
|
126
126
|
function runEffectQueue(queue) {
|
|
127
127
|
for (let i = 0; i < queue.length; i++)
|
|
128
|
-
queue[i].
|
|
128
|
+
queue[i].T();
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
// src/core/utils.ts
|
|
132
132
|
function isUndefined(value) {
|
|
133
133
|
return typeof value === "undefined";
|
|
134
134
|
}
|
|
135
|
+
function tryCatch(fn) {
|
|
136
|
+
try {
|
|
137
|
+
const v = fn();
|
|
138
|
+
if (v instanceof Promise) {
|
|
139
|
+
return v.then(
|
|
140
|
+
(v2) => [void 0, v2],
|
|
141
|
+
(e) => {
|
|
142
|
+
if (e instanceof NotReadyError)
|
|
143
|
+
throw e;
|
|
144
|
+
return [e];
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
return [void 0, v];
|
|
149
|
+
} catch (e) {
|
|
150
|
+
if (e instanceof NotReadyError)
|
|
151
|
+
throw e;
|
|
152
|
+
return [e];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
135
155
|
|
|
136
156
|
// src/core/owner.ts
|
|
137
157
|
var currentOwner = null;
|
|
@@ -144,34 +164,46 @@ function setOwner(owner) {
|
|
|
144
164
|
currentOwner = owner;
|
|
145
165
|
return out;
|
|
146
166
|
}
|
|
167
|
+
function formatId(prefix, id) {
|
|
168
|
+
const num = id.toString(36), len = num.length - 1;
|
|
169
|
+
return prefix + (len ? String.fromCharCode(64 + len) : "") + num;
|
|
170
|
+
}
|
|
147
171
|
var Owner = class {
|
|
148
172
|
// We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
|
|
149
173
|
// However, the children are actually added in reverse creation order
|
|
150
174
|
// See comment at the top of the file for an example of the _nextSibling traversal
|
|
175
|
+
x = null;
|
|
176
|
+
l = null;
|
|
151
177
|
t = null;
|
|
152
|
-
n = null;
|
|
153
|
-
u = null;
|
|
154
178
|
a = STATE_CLEAN;
|
|
155
|
-
l = null;
|
|
156
|
-
p = defaultContext;
|
|
157
179
|
m = null;
|
|
180
|
+
o = defaultContext;
|
|
181
|
+
n = null;
|
|
158
182
|
h = globalQueue;
|
|
159
|
-
|
|
160
|
-
|
|
183
|
+
O = null;
|
|
184
|
+
X = 0;
|
|
185
|
+
id = null;
|
|
186
|
+
constructor(id = null, skipAppend = false) {
|
|
187
|
+
this.id = id;
|
|
188
|
+
if (currentOwner && !skipAppend)
|
|
161
189
|
currentOwner.append(this);
|
|
162
190
|
}
|
|
163
191
|
append(child) {
|
|
192
|
+
child.x = this;
|
|
164
193
|
child.t = this;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
child.n = this.n;
|
|
169
|
-
this.n = child;
|
|
170
|
-
if (child.p !== this.p) {
|
|
171
|
-
child.p = { ...this.p, ...child.p };
|
|
194
|
+
if (this.id) {
|
|
195
|
+
child.O = this.l ? this.l.O + 1 : 0;
|
|
196
|
+
child.id = formatId(this.id, child.O);
|
|
172
197
|
}
|
|
173
|
-
if (this.
|
|
174
|
-
|
|
198
|
+
if (this.l)
|
|
199
|
+
this.l.t = child;
|
|
200
|
+
child.l = this.l;
|
|
201
|
+
this.l = child;
|
|
202
|
+
if (child.o !== this.o) {
|
|
203
|
+
child.o = { ...this.o, ...child.o };
|
|
204
|
+
}
|
|
205
|
+
if (this.n) {
|
|
206
|
+
child.n = !child.n ? this.n : [...child.n, ...this.n];
|
|
175
207
|
}
|
|
176
208
|
if (this.h)
|
|
177
209
|
child.h = this.h;
|
|
@@ -179,51 +211,54 @@ var Owner = class {
|
|
|
179
211
|
dispose(self = true) {
|
|
180
212
|
if (this.a === STATE_DISPOSED)
|
|
181
213
|
return;
|
|
182
|
-
let head = self ? this.
|
|
183
|
-
while (current && current.
|
|
214
|
+
let head = self ? this.t || this.x : this, current = this.l, next = null;
|
|
215
|
+
while (current && current.x === this) {
|
|
184
216
|
current.dispose(true);
|
|
185
|
-
current.
|
|
186
|
-
next = current.
|
|
187
|
-
current.
|
|
217
|
+
current.z();
|
|
218
|
+
next = current.l;
|
|
219
|
+
current.l = null;
|
|
188
220
|
current = next;
|
|
189
221
|
}
|
|
190
222
|
if (self)
|
|
191
|
-
this.
|
|
223
|
+
this.z();
|
|
192
224
|
if (current)
|
|
193
|
-
current.
|
|
225
|
+
current.t = !self ? this : this.t;
|
|
194
226
|
if (head)
|
|
195
|
-
head.
|
|
227
|
+
head.l = current;
|
|
196
228
|
}
|
|
197
|
-
|
|
198
|
-
if (this.
|
|
199
|
-
this.
|
|
229
|
+
z() {
|
|
230
|
+
if (this.t)
|
|
231
|
+
this.t.l = null;
|
|
232
|
+
this.x = null;
|
|
200
233
|
this.t = null;
|
|
201
|
-
this.
|
|
202
|
-
this.
|
|
203
|
-
this.m = null;
|
|
234
|
+
this.o = defaultContext;
|
|
235
|
+
this.n = null;
|
|
204
236
|
this.a = STATE_DISPOSED;
|
|
205
237
|
this.emptyDisposal();
|
|
206
238
|
}
|
|
207
239
|
emptyDisposal() {
|
|
208
|
-
if (!this.
|
|
240
|
+
if (!this.m)
|
|
209
241
|
return;
|
|
210
|
-
if (Array.isArray(this.
|
|
211
|
-
for (let i = 0; i < this.
|
|
212
|
-
const callable = this.
|
|
242
|
+
if (Array.isArray(this.m)) {
|
|
243
|
+
for (let i = 0; i < this.m.length; i++) {
|
|
244
|
+
const callable = this.m[i];
|
|
213
245
|
callable.call(callable);
|
|
214
246
|
}
|
|
215
247
|
} else {
|
|
216
|
-
this.
|
|
248
|
+
this.m.call(this.m);
|
|
217
249
|
}
|
|
218
|
-
this.
|
|
250
|
+
this.m = null;
|
|
251
|
+
}
|
|
252
|
+
addErrorHandler(handler) {
|
|
253
|
+
this.n = this.n ? [handler, ...this.n] : [handler];
|
|
219
254
|
}
|
|
220
255
|
handleError(error) {
|
|
221
|
-
if (!this.
|
|
256
|
+
if (!this.n)
|
|
222
257
|
throw error;
|
|
223
|
-
let i = 0, len = this.
|
|
258
|
+
let i = 0, len = this.n.length;
|
|
224
259
|
for (i = 0; i < len; i++) {
|
|
225
260
|
try {
|
|
226
|
-
this.
|
|
261
|
+
this.n[i](error, this);
|
|
227
262
|
break;
|
|
228
263
|
} catch (e) {
|
|
229
264
|
error = e;
|
|
@@ -232,6 +267,11 @@ var Owner = class {
|
|
|
232
267
|
if (i === len)
|
|
233
268
|
throw error;
|
|
234
269
|
}
|
|
270
|
+
getNextChildId() {
|
|
271
|
+
if (this.id)
|
|
272
|
+
return formatId(this.id + "-", this.X++);
|
|
273
|
+
throw new Error("Cannot get child id from owner without an id");
|
|
274
|
+
}
|
|
235
275
|
};
|
|
236
276
|
function createContext(defaultValue, description) {
|
|
237
277
|
return { id: Symbol(description), defaultValue };
|
|
@@ -240,7 +280,7 @@ function getContext(context, owner = currentOwner) {
|
|
|
240
280
|
if (!owner) {
|
|
241
281
|
throw new NoOwnerError();
|
|
242
282
|
}
|
|
243
|
-
const value = hasContext(context, owner) ? owner.
|
|
283
|
+
const value = hasContext(context, owner) ? owner.o[context.id] : context.defaultValue;
|
|
244
284
|
if (isUndefined(value)) {
|
|
245
285
|
throw new ContextNotFoundError();
|
|
246
286
|
}
|
|
@@ -250,24 +290,24 @@ function setContext(context, value, owner = currentOwner) {
|
|
|
250
290
|
if (!owner) {
|
|
251
291
|
throw new NoOwnerError();
|
|
252
292
|
}
|
|
253
|
-
owner.
|
|
254
|
-
...owner.
|
|
293
|
+
owner.o = {
|
|
294
|
+
...owner.o,
|
|
255
295
|
[context.id]: isUndefined(value) ? context.defaultValue : value
|
|
256
296
|
};
|
|
257
297
|
}
|
|
258
298
|
function hasContext(context, owner = currentOwner) {
|
|
259
|
-
return !isUndefined(owner?.
|
|
299
|
+
return !isUndefined(owner?.o[context.id]);
|
|
260
300
|
}
|
|
261
301
|
function onCleanup(fn) {
|
|
262
302
|
if (!currentOwner)
|
|
263
303
|
return fn;
|
|
264
304
|
const node = currentOwner;
|
|
265
|
-
if (!node.
|
|
266
|
-
node.
|
|
267
|
-
} else if (Array.isArray(node.
|
|
268
|
-
node.
|
|
305
|
+
if (!node.m) {
|
|
306
|
+
node.m = fn;
|
|
307
|
+
} else if (Array.isArray(node.m)) {
|
|
308
|
+
node.m.push(fn);
|
|
269
309
|
} else {
|
|
270
|
-
node.
|
|
310
|
+
node.m = [node.m, fn];
|
|
271
311
|
}
|
|
272
312
|
return fn;
|
|
273
313
|
}
|
|
@@ -295,46 +335,44 @@ function getObserver() {
|
|
|
295
335
|
}
|
|
296
336
|
var UNCHANGED = Symbol(0);
|
|
297
337
|
var Computation = class extends Owner {
|
|
298
|
-
|
|
299
|
-
|
|
338
|
+
c = null;
|
|
339
|
+
f = null;
|
|
300
340
|
g;
|
|
301
341
|
G;
|
|
302
|
-
|
|
342
|
+
A;
|
|
303
343
|
// Used in __DEV__ mode, hopefully removed in production
|
|
304
344
|
$;
|
|
305
345
|
// Using false is an optimization as an alternative to _equals: () => false
|
|
306
346
|
// which could enable more efficient DIRTY notification
|
|
307
|
-
|
|
308
|
-
|
|
347
|
+
P = isEqual;
|
|
348
|
+
U;
|
|
309
349
|
/** Whether the computation is an error or has ancestors that are unresolved */
|
|
310
|
-
|
|
350
|
+
d = 0;
|
|
311
351
|
/** Which flags raised by sources are handled, vs. being passed through. */
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
y = -1;
|
|
352
|
+
Q = DEFAULT_FLAGS;
|
|
353
|
+
B = -1;
|
|
315
354
|
K = false;
|
|
316
355
|
constructor(initialValue, compute2, options) {
|
|
317
|
-
super(compute2 === null);
|
|
318
|
-
this.
|
|
356
|
+
super(null, compute2 === null);
|
|
357
|
+
this.A = compute2;
|
|
319
358
|
this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
|
|
320
|
-
this.
|
|
359
|
+
this.d = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
|
|
321
360
|
this.g = initialValue;
|
|
322
361
|
if (options?.equals !== void 0)
|
|
323
|
-
this.
|
|
362
|
+
this.P = options.equals;
|
|
324
363
|
if (options?.unobserved)
|
|
325
|
-
this.
|
|
364
|
+
this.U = options?.unobserved;
|
|
326
365
|
}
|
|
327
|
-
|
|
328
|
-
if (this.
|
|
329
|
-
if (this.
|
|
366
|
+
V() {
|
|
367
|
+
if (this.A) {
|
|
368
|
+
if (this.d & ERROR_BIT && this.B <= getClock())
|
|
330
369
|
update(this);
|
|
331
370
|
else
|
|
332
|
-
this.
|
|
371
|
+
this.y();
|
|
333
372
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
if (this.f & ERROR_BIT) {
|
|
373
|
+
track(this);
|
|
374
|
+
newFlags |= this.d & ~currentMask;
|
|
375
|
+
if (this.d & ERROR_BIT) {
|
|
338
376
|
throw this.G;
|
|
339
377
|
} else {
|
|
340
378
|
return this.g;
|
|
@@ -345,7 +383,7 @@ var Computation = class extends Owner {
|
|
|
345
383
|
* Automatically re-executes the surrounding computation when the value changes
|
|
346
384
|
*/
|
|
347
385
|
read() {
|
|
348
|
-
return this.
|
|
386
|
+
return this.V();
|
|
349
387
|
}
|
|
350
388
|
/**
|
|
351
389
|
* Return the current value of this computation
|
|
@@ -355,46 +393,37 @@ var Computation = class extends Owner {
|
|
|
355
393
|
* before continuing
|
|
356
394
|
*/
|
|
357
395
|
wait() {
|
|
358
|
-
if (this.
|
|
396
|
+
if (this.A && this.d & ERROR_BIT && this.B <= getClock()) {
|
|
359
397
|
update(this);
|
|
398
|
+
} else {
|
|
399
|
+
this.y();
|
|
360
400
|
}
|
|
361
|
-
|
|
401
|
+
track(this);
|
|
402
|
+
if ((notStale || this.d & UNINITIALIZED_BIT) && this.d & LOADING_BIT) {
|
|
362
403
|
throw new NotReadyError();
|
|
363
404
|
}
|
|
364
|
-
if (staleCheck && this.
|
|
405
|
+
if (staleCheck && this.d & LOADING_BIT) {
|
|
365
406
|
staleCheck.g = true;
|
|
366
|
-
return this.W();
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* Return true if the computation is the value is dependent on an unresolved promise
|
|
370
|
-
* Triggers re-execution of the computation when the loading state changes
|
|
371
|
-
*
|
|
372
|
-
* This is useful especially when effects want to re-execute when a computation's
|
|
373
|
-
* loading state changes
|
|
374
|
-
*/
|
|
375
|
-
loading() {
|
|
376
|
-
if (this.Q === null) {
|
|
377
|
-
this.Q = loadingState(this);
|
|
378
407
|
}
|
|
379
|
-
return this.
|
|
408
|
+
return this.V();
|
|
380
409
|
}
|
|
381
410
|
/** Update the computation with a new value. */
|
|
382
411
|
write(value, flags = 0, raw = false) {
|
|
383
412
|
const newValue = !raw && typeof value === "function" ? value(this.g) : value;
|
|
384
|
-
const valueChanged = newValue !== UNCHANGED && (!!(this.
|
|
413
|
+
const valueChanged = newValue !== UNCHANGED && (!!(this.d & UNINITIALIZED_BIT) || this.d & LOADING_BIT & ~flags || this.P === false || !this.P(this.g, newValue));
|
|
385
414
|
if (valueChanged) {
|
|
386
415
|
this.g = newValue;
|
|
387
416
|
this.G = void 0;
|
|
388
417
|
}
|
|
389
|
-
const changedFlagsMask = this.
|
|
390
|
-
this.
|
|
391
|
-
this.
|
|
392
|
-
if (this.
|
|
393
|
-
for (let i = 0; i < this.
|
|
418
|
+
const changedFlagsMask = this.d ^ flags, changedFlags = changedFlagsMask & flags;
|
|
419
|
+
this.d = flags;
|
|
420
|
+
this.B = getClock() + 1;
|
|
421
|
+
if (this.f) {
|
|
422
|
+
for (let i = 0; i < this.f.length; i++) {
|
|
394
423
|
if (valueChanged) {
|
|
395
|
-
this.
|
|
424
|
+
this.f[i].r(STATE_DIRTY);
|
|
396
425
|
} else if (changedFlagsMask) {
|
|
397
|
-
this.
|
|
426
|
+
this.f[i].W(changedFlagsMask, changedFlags);
|
|
398
427
|
}
|
|
399
428
|
}
|
|
400
429
|
}
|
|
@@ -403,14 +432,14 @@ var Computation = class extends Owner {
|
|
|
403
432
|
/**
|
|
404
433
|
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
|
405
434
|
*/
|
|
406
|
-
|
|
435
|
+
r(state, skipQueue) {
|
|
407
436
|
if (this.a >= state && !this.K)
|
|
408
437
|
return;
|
|
409
438
|
this.K = !!skipQueue;
|
|
410
439
|
this.a = state;
|
|
411
|
-
if (this.
|
|
412
|
-
for (let i = 0; i < this.
|
|
413
|
-
this.
|
|
440
|
+
if (this.f) {
|
|
441
|
+
for (let i = 0; i < this.f.length; i++) {
|
|
442
|
+
this.f[i].r(STATE_CHECK, skipQueue);
|
|
414
443
|
}
|
|
415
444
|
}
|
|
416
445
|
}
|
|
@@ -420,31 +449,31 @@ var Computation = class extends Owner {
|
|
|
420
449
|
* @param mask A bitmask for which flag(s) were changed.
|
|
421
450
|
* @param newFlags The source's new flags, masked to just the changed ones.
|
|
422
451
|
*/
|
|
423
|
-
|
|
452
|
+
W(mask, newFlags2) {
|
|
424
453
|
if (this.a >= STATE_DIRTY)
|
|
425
454
|
return;
|
|
426
|
-
if (mask & this.
|
|
427
|
-
this.
|
|
455
|
+
if (mask & this.Q) {
|
|
456
|
+
this.r(STATE_DIRTY);
|
|
428
457
|
return;
|
|
429
458
|
}
|
|
430
459
|
if (this.a >= STATE_CHECK)
|
|
431
460
|
return;
|
|
432
|
-
const prevFlags = this.
|
|
461
|
+
const prevFlags = this.d & mask;
|
|
433
462
|
const deltaFlags = prevFlags ^ newFlags2;
|
|
434
463
|
if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
|
|
435
|
-
this.
|
|
464
|
+
this.r(STATE_CHECK);
|
|
436
465
|
} else {
|
|
437
|
-
this.
|
|
438
|
-
if (this.
|
|
439
|
-
for (let i = 0; i < this.
|
|
440
|
-
this.
|
|
466
|
+
this.d ^= deltaFlags;
|
|
467
|
+
if (this.f) {
|
|
468
|
+
for (let i = 0; i < this.f.length; i++) {
|
|
469
|
+
this.f[i].W(mask, newFlags2);
|
|
441
470
|
}
|
|
442
471
|
}
|
|
443
472
|
}
|
|
444
473
|
}
|
|
445
474
|
H(error) {
|
|
446
475
|
this.G = error;
|
|
447
|
-
this.write(UNCHANGED, this.
|
|
476
|
+
this.write(UNCHANGED, this.d & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
|
|
448
477
|
}
|
|
449
478
|
/**
|
|
450
479
|
* This is the core part of the reactivity system, which makes sure that the values are updated
|
|
@@ -453,18 +482,21 @@ var Computation = class extends Owner {
|
|
|
453
482
|
*
|
|
454
483
|
* This function will ensure that the value and states we read from the computation are up to date
|
|
455
484
|
*/
|
|
456
|
-
|
|
485
|
+
y() {
|
|
486
|
+
if (!this.A) {
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
457
489
|
if (this.a === STATE_DISPOSED) {
|
|
458
|
-
|
|
490
|
+
return;
|
|
459
491
|
}
|
|
460
492
|
if (this.a === STATE_CLEAN) {
|
|
461
493
|
return;
|
|
462
494
|
}
|
|
463
495
|
let observerFlags = 0;
|
|
464
496
|
if (this.a === STATE_CHECK) {
|
|
465
|
-
for (let i = 0; i < this.
|
|
466
|
-
this.
|
|
467
|
-
observerFlags |= this.
|
|
497
|
+
for (let i = 0; i < this.c.length; i++) {
|
|
498
|
+
this.c[i].y();
|
|
499
|
+
observerFlags |= this.c[i].d;
|
|
468
500
|
if (this.a === STATE_DIRTY) {
|
|
469
501
|
break;
|
|
470
502
|
}
|
|
@@ -480,33 +512,17 @@ var Computation = class extends Owner {
|
|
|
480
512
|
/**
|
|
481
513
|
* Remove ourselves from the owner graph and the computation graph
|
|
482
514
|
*/
|
|
483
|
-
|
|
515
|
+
z() {
|
|
484
516
|
if (this.a === STATE_DISPOSED)
|
|
485
517
|
return;
|
|
486
|
-
if (this.
|
|
518
|
+
if (this.c)
|
|
487
519
|
removeSourceObservers(this, 0);
|
|
488
|
-
super.
|
|
520
|
+
super.z();
|
|
489
521
|
}
|
|
490
522
|
};
|
|
491
|
-
function loadingState(node) {
|
|
492
|
-
const prevOwner = setOwner(node.t);
|
|
493
|
-
const options = void 0;
|
|
494
|
-
const computation = new Computation(
|
|
495
|
-
void 0,
|
|
496
|
-
() => {
|
|
497
|
-
track(node);
|
|
498
|
-
node.z();
|
|
499
|
-
return !!(node.f & LOADING_BIT);
|
|
500
|
-
},
|
|
501
|
-
options
|
|
502
|
-
);
|
|
503
|
-
computation.P = ERROR_BIT | LOADING_BIT;
|
|
504
|
-
setOwner(prevOwner);
|
|
505
|
-
return computation;
|
|
506
|
-
}
|
|
507
523
|
function track(computation) {
|
|
508
524
|
if (currentObserver) {
|
|
509
|
-
if (!newSources && currentObserver.
|
|
525
|
+
if (!newSources && currentObserver.c && currentObserver.c[newSourcesIndex] === computation) {
|
|
510
526
|
newSourcesIndex++;
|
|
511
527
|
} else if (!newSources)
|
|
512
528
|
newSources = [computation];
|
|
@@ -514,7 +530,7 @@ function track(computation) {
|
|
|
514
530
|
newSources.push(computation);
|
|
515
531
|
}
|
|
516
532
|
if (updateCheck) {
|
|
517
|
-
updateCheck.g = computation.
|
|
533
|
+
updateCheck.g = computation.B > currentObserver.B;
|
|
518
534
|
}
|
|
519
535
|
}
|
|
520
536
|
}
|
|
@@ -526,56 +542,56 @@ function update(node) {
|
|
|
526
542
|
try {
|
|
527
543
|
node.dispose(false);
|
|
528
544
|
node.emptyDisposal();
|
|
529
|
-
const result = compute(node, node.
|
|
545
|
+
const result = compute(node, node.A, node);
|
|
530
546
|
node.write(result, newFlags, true);
|
|
531
547
|
} catch (error) {
|
|
532
548
|
if (error instanceof NotReadyError) {
|
|
533
|
-
node.write(UNCHANGED, newFlags | LOADING_BIT | node.
|
|
549
|
+
node.write(UNCHANGED, newFlags | LOADING_BIT | node.d & UNINITIALIZED_BIT);
|
|
534
550
|
} else {
|
|
535
551
|
node.H(error);
|
|
536
552
|
}
|
|
537
553
|
} finally {
|
|
538
554
|
if (newSources) {
|
|
539
|
-
if (node.
|
|
555
|
+
if (node.c)
|
|
540
556
|
removeSourceObservers(node, newSourcesIndex);
|
|
541
|
-
if (node.
|
|
542
|
-
node.
|
|
557
|
+
if (node.c && newSourcesIndex > 0) {
|
|
558
|
+
node.c.length = newSourcesIndex + newSources.length;
|
|
543
559
|
for (let i = 0; i < newSources.length; i++) {
|
|
544
|
-
node.
|
|
560
|
+
node.c[newSourcesIndex + i] = newSources[i];
|
|
545
561
|
}
|
|
546
562
|
} else {
|
|
547
|
-
node.
|
|
563
|
+
node.c = newSources;
|
|
548
564
|
}
|
|
549
565
|
let source;
|
|
550
|
-
for (let i = newSourcesIndex; i < node.
|
|
551
|
-
source = node.
|
|
552
|
-
if (!source.
|
|
553
|
-
source.
|
|
566
|
+
for (let i = newSourcesIndex; i < node.c.length; i++) {
|
|
567
|
+
source = node.c[i];
|
|
568
|
+
if (!source.f)
|
|
569
|
+
source.f = [node];
|
|
554
570
|
else
|
|
555
|
-
source.
|
|
571
|
+
source.f.push(node);
|
|
556
572
|
}
|
|
557
|
-
} else if (node.
|
|
573
|
+
} else if (node.c && newSourcesIndex < node.c.length) {
|
|
558
574
|
removeSourceObservers(node, newSourcesIndex);
|
|
559
|
-
node.
|
|
575
|
+
node.c.length = newSourcesIndex;
|
|
560
576
|
}
|
|
561
577
|
newSources = prevSources;
|
|
562
578
|
newSourcesIndex = prevSourcesIndex;
|
|
563
579
|
newFlags = prevFlags;
|
|
564
|
-
node.
|
|
580
|
+
node.B = getClock() + 1;
|
|
565
581
|
node.a = STATE_CLEAN;
|
|
566
582
|
}
|
|
567
583
|
}
|
|
568
584
|
function removeSourceObservers(node, index) {
|
|
569
585
|
let source;
|
|
570
586
|
let swap;
|
|
571
|
-
for (let i = index; i < node.
|
|
572
|
-
source = node.
|
|
573
|
-
if (source.
|
|
574
|
-
swap = source.
|
|
575
|
-
source.
|
|
576
|
-
source.
|
|
577
|
-
if (!source.
|
|
578
|
-
source.
|
|
587
|
+
for (let i = index; i < node.c.length; i++) {
|
|
588
|
+
source = node.c[i];
|
|
589
|
+
if (source.f) {
|
|
590
|
+
swap = source.f.indexOf(node);
|
|
591
|
+
source.f[swap] = source.f[source.f.length - 1];
|
|
592
|
+
source.f.pop();
|
|
593
|
+
if (!source.f.length)
|
|
594
|
+
source.U?.();
|
|
579
595
|
}
|
|
580
596
|
}
|
|
581
597
|
}
|
|
@@ -597,8 +613,7 @@ function hasUpdated(fn) {
|
|
|
597
613
|
updateCheck = current;
|
|
598
614
|
}
|
|
599
615
|
}
|
|
600
|
-
function
|
|
601
|
-
const argLength = arguments.length;
|
|
616
|
+
function pendingCheck(fn, loadingValue) {
|
|
602
617
|
const current = staleCheck;
|
|
603
618
|
staleCheck = { g: false };
|
|
604
619
|
try {
|
|
@@ -607,13 +622,20 @@ function isPending(fn, loadingValue) {
|
|
|
607
622
|
} catch (err) {
|
|
608
623
|
if (!(err instanceof NotReadyError))
|
|
609
624
|
return false;
|
|
610
|
-
if (
|
|
625
|
+
if (loadingValue !== void 0)
|
|
611
626
|
return loadingValue;
|
|
612
627
|
throw err;
|
|
613
628
|
} finally {
|
|
614
629
|
staleCheck = current;
|
|
615
630
|
}
|
|
616
631
|
}
|
|
632
|
+
function isPending(fn, loadingValue) {
|
|
633
|
+
if (!currentObserver)
|
|
634
|
+
return pendingCheck(fn, loadingValue);
|
|
635
|
+
const c = new Computation(void 0, () => pendingCheck(fn, loadingValue));
|
|
636
|
+
c.Q |= LOADING_BIT;
|
|
637
|
+
return c.read();
|
|
638
|
+
}
|
|
617
639
|
function latest(fn, fallback) {
|
|
618
640
|
const argLength = arguments.length;
|
|
619
641
|
const prevFlags = newFlags;
|
|
@@ -630,19 +652,10 @@ function latest(fn, fallback) {
|
|
|
630
652
|
notStale = prevNotStale;
|
|
631
653
|
}
|
|
632
654
|
}
|
|
633
|
-
function catchError(fn) {
|
|
634
|
-
try {
|
|
635
|
-
fn();
|
|
636
|
-
} catch (e) {
|
|
637
|
-
if (e instanceof NotReadyError)
|
|
638
|
-
throw e;
|
|
639
|
-
return e;
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
655
|
function runWithObserver(observer, run) {
|
|
643
656
|
const prevSources = newSources, prevSourcesIndex = newSourcesIndex, prevFlags = newFlags;
|
|
644
657
|
newSources = null;
|
|
645
|
-
newSourcesIndex = observer.
|
|
658
|
+
newSourcesIndex = observer.c ? observer.c.length : 0;
|
|
646
659
|
newFlags = 0;
|
|
647
660
|
try {
|
|
648
661
|
return compute(observer, run, observer);
|
|
@@ -650,7 +663,7 @@ function runWithObserver(observer, run) {
|
|
|
650
663
|
if (error instanceof NotReadyError) {
|
|
651
664
|
observer.write(
|
|
652
665
|
UNCHANGED,
|
|
653
|
-
newFlags | LOADING_BIT | observer.
|
|
666
|
+
newFlags | LOADING_BIT | observer.d & UNINITIALIZED_BIT
|
|
654
667
|
);
|
|
655
668
|
} else {
|
|
656
669
|
observer.H(error);
|
|
@@ -658,20 +671,20 @@ function runWithObserver(observer, run) {
|
|
|
658
671
|
} finally {
|
|
659
672
|
if (newSources) {
|
|
660
673
|
if (newSourcesIndex > 0) {
|
|
661
|
-
observer.
|
|
674
|
+
observer.c.length = newSourcesIndex + newSources.length;
|
|
662
675
|
for (let i = 0; i < newSources.length; i++) {
|
|
663
|
-
observer.
|
|
676
|
+
observer.c[newSourcesIndex + i] = newSources[i];
|
|
664
677
|
}
|
|
665
678
|
} else {
|
|
666
|
-
observer.
|
|
679
|
+
observer.c = newSources;
|
|
667
680
|
}
|
|
668
681
|
let source;
|
|
669
|
-
for (let i = newSourcesIndex; i < observer.
|
|
670
|
-
source = observer.
|
|
671
|
-
if (!source.
|
|
672
|
-
source.
|
|
682
|
+
for (let i = newSourcesIndex; i < observer.c.length; i++) {
|
|
683
|
+
source = observer.c[i];
|
|
684
|
+
if (!source.f)
|
|
685
|
+
source.f = [observer];
|
|
673
686
|
else
|
|
674
|
-
source.
|
|
687
|
+
source.f.push(observer);
|
|
675
688
|
}
|
|
676
689
|
}
|
|
677
690
|
newSources = prevSources;
|
|
@@ -682,7 +695,7 @@ function runWithObserver(observer, run) {
|
|
|
682
695
|
function compute(owner, fn, observer) {
|
|
683
696
|
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask, prevNotStale = notStale;
|
|
684
697
|
currentObserver = observer;
|
|
685
|
-
currentMask = observer?.
|
|
698
|
+
currentMask = observer?.Q ?? DEFAULT_FLAGS;
|
|
686
699
|
notStale = true;
|
|
687
700
|
try {
|
|
688
701
|
return fn(observer ? observer.g : void 0);
|
|
@@ -755,13 +768,6 @@ function flattenArray(children, results = [], options) {
|
|
|
755
768
|
throw notReady;
|
|
756
769
|
return needsUnwrap;
|
|
757
770
|
}
|
|
758
|
-
function createBoundary(fn, queue) {
|
|
759
|
-
const owner = new Owner();
|
|
760
|
-
const parentQueue = owner.h;
|
|
761
|
-
parentQueue.addChild(owner.h = queue);
|
|
762
|
-
onCleanup(() => parentQueue.removeChild(owner.h));
|
|
763
|
-
return compute(owner, fn, null);
|
|
764
|
-
}
|
|
765
771
|
|
|
766
772
|
// src/core/effect.ts
|
|
767
773
|
var Effect = class extends Computation {
|
|
@@ -770,24 +776,24 @@ var Effect = class extends Computation {
|
|
|
770
776
|
C;
|
|
771
777
|
R = false;
|
|
772
778
|
N;
|
|
773
|
-
|
|
779
|
+
u;
|
|
774
780
|
constructor(initialValue, compute2, effect, error, options) {
|
|
775
781
|
super(initialValue, compute2, options);
|
|
776
782
|
this.L = effect;
|
|
777
783
|
this.M = error;
|
|
778
784
|
this.N = initialValue;
|
|
779
|
-
this.
|
|
780
|
-
if (this.
|
|
781
|
-
this.
|
|
785
|
+
this.u = options?.render ? EFFECT_RENDER : EFFECT_USER;
|
|
786
|
+
if (this.u === EFFECT_RENDER) {
|
|
787
|
+
this.A = (p) => getClock() > this.h.created && !(this.d & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
|
|
782
788
|
}
|
|
783
|
-
this.
|
|
784
|
-
!options?.defer && (this.
|
|
789
|
+
this.y();
|
|
790
|
+
!options?.defer && (this.u === EFFECT_USER ? this.h.enqueue(this.u, this) : this.T());
|
|
785
791
|
}
|
|
786
792
|
write(value, flags = 0) {
|
|
787
793
|
if (this.a == STATE_DIRTY) {
|
|
788
|
-
const currentFlags = this.
|
|
789
|
-
this.
|
|
790
|
-
if (this.
|
|
794
|
+
const currentFlags = this.d;
|
|
795
|
+
this.d = flags;
|
|
796
|
+
if (this.u === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
791
797
|
this.h.S?.(this);
|
|
792
798
|
}
|
|
793
799
|
}
|
|
@@ -797,20 +803,20 @@ var Effect = class extends Computation {
|
|
|
797
803
|
this.R = true;
|
|
798
804
|
return value;
|
|
799
805
|
}
|
|
800
|
-
|
|
806
|
+
r(state, skipQueue) {
|
|
801
807
|
if (this.a >= state || skipQueue)
|
|
802
808
|
return;
|
|
803
809
|
if (this.a === STATE_CLEAN)
|
|
804
|
-
this.h.enqueue(this.
|
|
810
|
+
this.h.enqueue(this.u, this);
|
|
805
811
|
this.a = state;
|
|
806
812
|
}
|
|
807
813
|
H(error) {
|
|
808
814
|
this.C?.();
|
|
809
|
-
if (this.
|
|
815
|
+
if (this.d & LOADING_BIT) {
|
|
810
816
|
this.h.S?.(this);
|
|
811
817
|
}
|
|
812
|
-
this.
|
|
813
|
-
if (this.
|
|
818
|
+
this.d = ERROR_BIT;
|
|
819
|
+
if (this.u === EFFECT_USER) {
|
|
814
820
|
try {
|
|
815
821
|
return this.M ? this.C = this.M(error) : console.error(new EffectError(this.L, error));
|
|
816
822
|
} catch (e) {
|
|
@@ -819,7 +825,7 @@ var Effect = class extends Computation {
|
|
|
819
825
|
}
|
|
820
826
|
this.handleError(error);
|
|
821
827
|
}
|
|
822
|
-
|
|
828
|
+
z() {
|
|
823
829
|
if (this.a === STATE_DISPOSED)
|
|
824
830
|
return;
|
|
825
831
|
this.L = void 0;
|
|
@@ -827,9 +833,9 @@ var Effect = class extends Computation {
|
|
|
827
833
|
this.M = void 0;
|
|
828
834
|
this.C?.();
|
|
829
835
|
this.C = void 0;
|
|
830
|
-
super.
|
|
836
|
+
super.z();
|
|
831
837
|
}
|
|
832
|
-
|
|
838
|
+
T() {
|
|
833
839
|
if (this.R && this.a !== STATE_DISPOSED) {
|
|
834
840
|
this.C?.();
|
|
835
841
|
try {
|
|
@@ -846,75 +852,126 @@ var Effect = class extends Computation {
|
|
|
846
852
|
var EagerComputation = class extends Computation {
|
|
847
853
|
constructor(initialValue, compute2, options) {
|
|
848
854
|
super(initialValue, compute2, options);
|
|
849
|
-
!options?.defer && this.
|
|
855
|
+
!options?.defer && this.y();
|
|
850
856
|
}
|
|
851
|
-
|
|
857
|
+
r(state, skipQueue) {
|
|
852
858
|
if (this.a >= state && !this.K)
|
|
853
859
|
return;
|
|
854
860
|
if (this.a === STATE_CLEAN && !skipQueue)
|
|
855
861
|
this.h.enqueue(EFFECT_PURE, this);
|
|
856
|
-
super.
|
|
862
|
+
super.r(state, skipQueue);
|
|
857
863
|
}
|
|
858
864
|
};
|
|
859
865
|
var ProjectionComputation = class extends Computation {
|
|
860
866
|
constructor(compute2) {
|
|
861
|
-
super(
|
|
867
|
+
super(void 0, compute2);
|
|
862
868
|
}
|
|
863
|
-
|
|
869
|
+
r(state, skipQueue) {
|
|
864
870
|
if (this.a >= state && !this.K)
|
|
865
871
|
return;
|
|
866
872
|
if (this.a === STATE_CLEAN && !skipQueue)
|
|
867
873
|
this.h.enqueue(EFFECT_PURE, this);
|
|
868
|
-
super.
|
|
874
|
+
super.r(state, true);
|
|
869
875
|
}
|
|
870
876
|
};
|
|
871
877
|
|
|
872
|
-
// src/core/
|
|
878
|
+
// src/core/boundaries.ts
|
|
879
|
+
function createBoundary(owner, fn, queue) {
|
|
880
|
+
if (queue) {
|
|
881
|
+
const parentQueue = owner.h;
|
|
882
|
+
parentQueue.addChild(owner.h = queue);
|
|
883
|
+
onCleanup(() => parentQueue.removeChild(owner.h));
|
|
884
|
+
}
|
|
885
|
+
return compute(
|
|
886
|
+
owner,
|
|
887
|
+
() => {
|
|
888
|
+
const c = new Computation(void 0, fn);
|
|
889
|
+
return new EagerComputation(void 0, () => flatten(c.wait()), { defer: true });
|
|
890
|
+
},
|
|
891
|
+
null
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
function createDecision(main, condition, fallback) {
|
|
895
|
+
const decision = new Computation(void 0, () => {
|
|
896
|
+
if (!condition.read()) {
|
|
897
|
+
const resolved = main.read();
|
|
898
|
+
if (!condition.read())
|
|
899
|
+
return resolved;
|
|
900
|
+
}
|
|
901
|
+
return fallback();
|
|
902
|
+
});
|
|
903
|
+
return decision.read.bind(decision);
|
|
904
|
+
}
|
|
873
905
|
var SuspenseQueue = class extends Queue {
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
T = new Computation(false, null);
|
|
906
|
+
b = /* @__PURE__ */ new Set();
|
|
907
|
+
p = new Computation(false, null);
|
|
877
908
|
run(type) {
|
|
878
|
-
if (type && this.
|
|
909
|
+
if (type && this.p.read())
|
|
879
910
|
return;
|
|
880
911
|
return super.run(type);
|
|
881
912
|
}
|
|
882
913
|
S(node) {
|
|
883
|
-
if (node.
|
|
884
|
-
this.
|
|
885
|
-
if (
|
|
886
|
-
this.
|
|
887
|
-
this.T.write(true);
|
|
888
|
-
}
|
|
914
|
+
if (node.d & LOADING_BIT) {
|
|
915
|
+
this.b.add(node);
|
|
916
|
+
if (this.b.size === 1)
|
|
917
|
+
this.p.write(true);
|
|
889
918
|
} else {
|
|
890
|
-
this.
|
|
891
|
-
if (this.
|
|
892
|
-
this.
|
|
893
|
-
this.T.write(false);
|
|
894
|
-
}
|
|
919
|
+
this.b.delete(node);
|
|
920
|
+
if (this.b.size === 0)
|
|
921
|
+
this.p.write(false);
|
|
895
922
|
}
|
|
896
923
|
}
|
|
897
924
|
};
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
925
|
+
function createSuspense(fn, fallback) {
|
|
926
|
+
const owner = new Owner();
|
|
927
|
+
const queue = new SuspenseQueue();
|
|
928
|
+
const tree = createBoundary(owner, fn, queue);
|
|
929
|
+
const ogWrite = tree.write;
|
|
930
|
+
tree.write = function(value, flags = 0) {
|
|
931
|
+
const currentFlags = this.d;
|
|
901
932
|
const dirty = this.a === STATE_DIRTY;
|
|
902
|
-
|
|
933
|
+
ogWrite.call(this, value, flags);
|
|
903
934
|
if (dirty && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
904
935
|
this.h.S?.(this);
|
|
905
936
|
}
|
|
906
937
|
return this.g;
|
|
938
|
+
};
|
|
939
|
+
return createDecision(tree, queue.p, fallback);
|
|
940
|
+
}
|
|
941
|
+
function createErrorBoundary(fn, fallback) {
|
|
942
|
+
const owner = new Owner();
|
|
943
|
+
const error = new Computation(void 0, null);
|
|
944
|
+
const nodes = /* @__PURE__ */ new Set();
|
|
945
|
+
function handler(err, node) {
|
|
946
|
+
if (nodes.has(node))
|
|
947
|
+
return;
|
|
948
|
+
compute(
|
|
949
|
+
node,
|
|
950
|
+
() => onCleanup(() => {
|
|
951
|
+
nodes.delete(node);
|
|
952
|
+
if (!nodes.size)
|
|
953
|
+
error.write(void 0);
|
|
954
|
+
}),
|
|
955
|
+
null
|
|
956
|
+
);
|
|
957
|
+
nodes.add(node);
|
|
958
|
+
if (nodes.size === 1)
|
|
959
|
+
error.write({ G: err });
|
|
907
960
|
}
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
961
|
+
owner.addErrorHandler(handler);
|
|
962
|
+
const tree = createBoundary(owner, fn);
|
|
963
|
+
tree.H = tree.handleError;
|
|
964
|
+
return createDecision(
|
|
965
|
+
tree,
|
|
966
|
+
error,
|
|
967
|
+
() => fallback(error.read().G, () => {
|
|
968
|
+
incrementClock();
|
|
969
|
+
for (let node of nodes) {
|
|
970
|
+
node.a = STATE_DIRTY;
|
|
971
|
+
node.h?.enqueue(node.u, node);
|
|
972
|
+
}
|
|
973
|
+
})
|
|
974
|
+
);
|
|
918
975
|
}
|
|
919
976
|
|
|
920
977
|
// src/signals.ts
|
|
@@ -942,77 +999,64 @@ function createMemo(compute2, value, options) {
|
|
|
942
999
|
let resolvedValue;
|
|
943
1000
|
return () => {
|
|
944
1001
|
if (node) {
|
|
1002
|
+
if (node.a === STATE_DISPOSED) {
|
|
1003
|
+
node = void 0;
|
|
1004
|
+
return resolvedValue;
|
|
1005
|
+
}
|
|
945
1006
|
resolvedValue = node.wait();
|
|
946
|
-
if (!node.
|
|
1007
|
+
if (!node.c?.length && node.l?.x !== node) {
|
|
947
1008
|
node.dispose();
|
|
948
1009
|
node = void 0;
|
|
949
|
-
} else if (!node.t && !node.e?.length) {
|
|
950
|
-
node.dispose();
|
|
951
|
-
node.a = STATE_DIRTY;
|
|
952
1010
|
}
|
|
953
1011
|
}
|
|
954
1012
|
return resolvedValue;
|
|
955
1013
|
};
|
|
956
1014
|
}
|
|
957
1015
|
function createAsync(compute2, value, options) {
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
{
|
|
961
|
-
g: value
|
|
962
|
-
},
|
|
1016
|
+
const node = new EagerComputation(
|
|
1017
|
+
value,
|
|
963
1018
|
(p) => {
|
|
964
|
-
const
|
|
965
|
-
const source = compute2(value2);
|
|
1019
|
+
const source = compute2(p);
|
|
966
1020
|
const isPromise = source instanceof Promise;
|
|
967
1021
|
const iterator = source[Symbol.asyncIterator];
|
|
968
1022
|
if (!isPromise && !iterator) {
|
|
969
|
-
return
|
|
970
|
-
wait() {
|
|
971
|
-
return source;
|
|
972
|
-
},
|
|
973
|
-
g: source
|
|
974
|
-
};
|
|
1023
|
+
return source;
|
|
975
1024
|
}
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
signal.wait = function() {
|
|
979
|
-
if (signal.f & ERROR_BIT && signal.y <= getClock()) {
|
|
980
|
-
lhs.q(STATE_DIRTY);
|
|
981
|
-
throw new NotReadyError();
|
|
982
|
-
}
|
|
983
|
-
return w.call(this);
|
|
984
|
-
};
|
|
985
|
-
signal.write(UNCHANGED, LOADING_BIT | (uninitialized ? UNINITIALIZED_BIT : 0));
|
|
1025
|
+
let abort = false;
|
|
1026
|
+
onCleanup(() => abort = true);
|
|
986
1027
|
if (isPromise) {
|
|
987
1028
|
source.then(
|
|
988
1029
|
(value3) => {
|
|
989
|
-
|
|
990
|
-
|
|
1030
|
+
if (abort)
|
|
1031
|
+
return;
|
|
1032
|
+
node.write(value3, 0, true);
|
|
991
1033
|
},
|
|
992
1034
|
(error) => {
|
|
993
|
-
|
|
994
|
-
|
|
1035
|
+
if (abort)
|
|
1036
|
+
return;
|
|
1037
|
+
node.H(error);
|
|
995
1038
|
}
|
|
996
1039
|
);
|
|
997
1040
|
} else {
|
|
998
|
-
let abort = false;
|
|
999
|
-
onCleanup(() => abort = true);
|
|
1000
1041
|
(async () => {
|
|
1001
1042
|
try {
|
|
1002
1043
|
for await (let value3 of source) {
|
|
1003
1044
|
if (abort)
|
|
1004
1045
|
return;
|
|
1005
|
-
|
|
1046
|
+
node.write(value3, 0, true);
|
|
1006
1047
|
}
|
|
1007
1048
|
} catch (error) {
|
|
1008
|
-
|
|
1049
|
+
if (abort)
|
|
1050
|
+
return;
|
|
1051
|
+
node.write(error, ERROR_BIT);
|
|
1009
1052
|
}
|
|
1010
1053
|
})();
|
|
1011
1054
|
}
|
|
1012
|
-
|
|
1013
|
-
}
|
|
1055
|
+
throw new NotReadyError();
|
|
1056
|
+
},
|
|
1057
|
+
options
|
|
1014
1058
|
);
|
|
1015
|
-
return
|
|
1059
|
+
return node.wait.bind(node);
|
|
1016
1060
|
}
|
|
1017
1061
|
function createEffect(compute2, effect, error, value, options) {
|
|
1018
1062
|
void new Effect(
|
|
@@ -1029,62 +1073,13 @@ function createRenderEffect(compute2, effect, value, options) {
|
|
|
1029
1073
|
...options
|
|
1030
1074
|
});
|
|
1031
1075
|
}
|
|
1032
|
-
function createRoot(init) {
|
|
1033
|
-
const owner = new Owner();
|
|
1076
|
+
function createRoot(init, options) {
|
|
1077
|
+
const owner = new Owner(options?.id);
|
|
1034
1078
|
return compute(owner, !init.length ? init : () => init(() => owner.dispose()), null);
|
|
1035
1079
|
}
|
|
1036
1080
|
function runWithOwner(owner, run) {
|
|
1037
1081
|
return compute(owner, run, null);
|
|
1038
1082
|
}
|
|
1039
|
-
function createErrorBoundary(fn, fallback) {
|
|
1040
|
-
const owner = new Owner();
|
|
1041
|
-
const error = new Computation(void 0, null);
|
|
1042
|
-
const nodes = /* @__PURE__ */ new Set();
|
|
1043
|
-
function handler(err, node) {
|
|
1044
|
-
if (nodes.has(node))
|
|
1045
|
-
return;
|
|
1046
|
-
compute(
|
|
1047
|
-
node,
|
|
1048
|
-
() => onCleanup(() => {
|
|
1049
|
-
nodes.delete(node);
|
|
1050
|
-
if (!nodes.size)
|
|
1051
|
-
error.write(void 0);
|
|
1052
|
-
}),
|
|
1053
|
-
null
|
|
1054
|
-
);
|
|
1055
|
-
nodes.add(node);
|
|
1056
|
-
if (nodes.size === 1)
|
|
1057
|
-
error.write({ G: err });
|
|
1058
|
-
}
|
|
1059
|
-
owner.m = owner.m ? [handler, ...owner.m] : [handler];
|
|
1060
|
-
const guarded = compute(
|
|
1061
|
-
owner,
|
|
1062
|
-
() => {
|
|
1063
|
-
const c = new Computation(void 0, fn);
|
|
1064
|
-
const f = new EagerComputation(void 0, () => flatten(c.read()), { defer: true });
|
|
1065
|
-
f.H = function(error2) {
|
|
1066
|
-
this.handleError(error2);
|
|
1067
|
-
};
|
|
1068
|
-
return f;
|
|
1069
|
-
},
|
|
1070
|
-
null
|
|
1071
|
-
);
|
|
1072
|
-
const decision = new Computation(null, () => {
|
|
1073
|
-
if (!error.read()) {
|
|
1074
|
-
const resolved = guarded.read();
|
|
1075
|
-
if (!error.read())
|
|
1076
|
-
return resolved;
|
|
1077
|
-
}
|
|
1078
|
-
return fallback(error.read().G, () => {
|
|
1079
|
-
incrementClock();
|
|
1080
|
-
for (let node of nodes) {
|
|
1081
|
-
node.a = STATE_DIRTY;
|
|
1082
|
-
node.h?.enqueue(node.w, node);
|
|
1083
|
-
}
|
|
1084
|
-
});
|
|
1085
|
-
});
|
|
1086
|
-
return decision.read.bind(decision);
|
|
1087
|
-
}
|
|
1088
1083
|
function resolve(fn) {
|
|
1089
1084
|
return new Promise((res, rej) => {
|
|
1090
1085
|
createRoot((dispose) => {
|
|
@@ -1644,14 +1639,14 @@ function mapArray(list, map, options) {
|
|
|
1644
1639
|
I: new Owner(),
|
|
1645
1640
|
i: 0,
|
|
1646
1641
|
Y: list,
|
|
1647
|
-
|
|
1642
|
+
w: [],
|
|
1648
1643
|
D: map,
|
|
1649
|
-
|
|
1650
|
-
|
|
1644
|
+
e: [],
|
|
1645
|
+
b: [],
|
|
1651
1646
|
E: keyFn,
|
|
1652
1647
|
j: keyFn || options?.keyed === false ? [] : void 0,
|
|
1653
1648
|
k: map.length > 1 ? [] : void 0,
|
|
1654
|
-
|
|
1649
|
+
p: options?.fallback
|
|
1655
1650
|
});
|
|
1656
1651
|
}
|
|
1657
1652
|
function updateKeyedMap() {
|
|
@@ -1676,38 +1671,38 @@ function updateKeyedMap() {
|
|
|
1676
1671
|
if (newLen === 0) {
|
|
1677
1672
|
if (this.i !== 0) {
|
|
1678
1673
|
this.I.dispose(false);
|
|
1679
|
-
this.
|
|
1680
|
-
this.
|
|
1681
|
-
this.
|
|
1674
|
+
this.b = [];
|
|
1675
|
+
this.w = [];
|
|
1676
|
+
this.e = [];
|
|
1682
1677
|
this.i = 0;
|
|
1683
1678
|
this.j && (this.j = []);
|
|
1684
1679
|
this.k && (this.k = []);
|
|
1685
1680
|
}
|
|
1686
|
-
if (this.
|
|
1687
|
-
this.
|
|
1688
|
-
this.
|
|
1689
|
-
this.
|
|
1681
|
+
if (this.p && !this.e[0]) {
|
|
1682
|
+
this.e[0] = compute(
|
|
1683
|
+
this.b[0] = new Owner(),
|
|
1684
|
+
this.p,
|
|
1690
1685
|
null
|
|
1691
1686
|
);
|
|
1692
1687
|
}
|
|
1693
1688
|
} else if (this.i === 0) {
|
|
1694
|
-
if (this.
|
|
1695
|
-
this.
|
|
1696
|
-
this.
|
|
1689
|
+
if (this.b[0])
|
|
1690
|
+
this.b[0].dispose();
|
|
1691
|
+
this.e = new Array(newLen);
|
|
1697
1692
|
for (j = 0; j < newLen; j++) {
|
|
1698
|
-
this.
|
|
1699
|
-
this.
|
|
1693
|
+
this.w[j] = newItems[j];
|
|
1694
|
+
this.e[j] = compute(this.b[j] = new Owner(), mapper, null);
|
|
1700
1695
|
}
|
|
1701
1696
|
this.i = newLen;
|
|
1702
1697
|
} else {
|
|
1703
1698
|
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;
|
|
1704
|
-
for (start = 0, end = Math.min(this.i, newLen); start < end && (this.
|
|
1699
|
+
for (start = 0, end = Math.min(this.i, newLen); start < end && (this.w[start] === newItems[start] || this.j && compare(this.E, this.w[start], newItems[start])); start++) {
|
|
1705
1700
|
if (this.j)
|
|
1706
1701
|
this.j[start].write(newItems[start]);
|
|
1707
1702
|
}
|
|
1708
|
-
for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.
|
|
1709
|
-
temp[newEnd] = this.
|
|
1710
|
-
tempNodes[newEnd] = this.
|
|
1703
|
+
for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.w[end] === newItems[newEnd] || this.j && compare(this.E, this.w[end], newItems[newEnd])); end--, newEnd--) {
|
|
1704
|
+
temp[newEnd] = this.e[end];
|
|
1705
|
+
tempNodes[newEnd] = this.b[end];
|
|
1711
1706
|
tempRows && (tempRows[newEnd] = this.j[end]);
|
|
1712
1707
|
tempIndexes && (tempIndexes[newEnd] = this.k[end]);
|
|
1713
1708
|
}
|
|
@@ -1721,23 +1716,23 @@ function updateKeyedMap() {
|
|
|
1721
1716
|
newIndices.set(key, j);
|
|
1722
1717
|
}
|
|
1723
1718
|
for (i = start; i <= end; i++) {
|
|
1724
|
-
item = this.
|
|
1719
|
+
item = this.w[i];
|
|
1725
1720
|
key = this.E ? this.E(item) : item;
|
|
1726
1721
|
j = newIndices.get(key);
|
|
1727
1722
|
if (j !== void 0 && j !== -1) {
|
|
1728
|
-
temp[j] = this.
|
|
1729
|
-
tempNodes[j] = this.
|
|
1723
|
+
temp[j] = this.e[i];
|
|
1724
|
+
tempNodes[j] = this.b[i];
|
|
1730
1725
|
tempRows && (tempRows[j] = this.j[i]);
|
|
1731
1726
|
tempIndexes && (tempIndexes[j] = this.k[i]);
|
|
1732
1727
|
j = newIndicesNext[j];
|
|
1733
1728
|
newIndices.set(key, j);
|
|
1734
1729
|
} else
|
|
1735
|
-
this.
|
|
1730
|
+
this.b[i].dispose();
|
|
1736
1731
|
}
|
|
1737
1732
|
for (j = start; j < newLen; j++) {
|
|
1738
1733
|
if (j in temp) {
|
|
1739
|
-
this.
|
|
1740
|
-
this.
|
|
1734
|
+
this.e[j] = temp[j];
|
|
1735
|
+
this.b[j] = tempNodes[j];
|
|
1741
1736
|
if (tempRows) {
|
|
1742
1737
|
this.j[j] = tempRows[j];
|
|
1743
1738
|
this.j[j].write(newItems[j]);
|
|
@@ -1747,26 +1742,26 @@ function updateKeyedMap() {
|
|
|
1747
1742
|
this.k[j].write(j);
|
|
1748
1743
|
}
|
|
1749
1744
|
} else {
|
|
1750
|
-
this.
|
|
1745
|
+
this.e[j] = compute(this.b[j] = new Owner(), mapper, null);
|
|
1751
1746
|
}
|
|
1752
1747
|
}
|
|
1753
|
-
this.
|
|
1754
|
-
this.
|
|
1748
|
+
this.e = this.e.slice(0, this.i = newLen);
|
|
1749
|
+
this.w = newItems.slice(0);
|
|
1755
1750
|
}
|
|
1756
1751
|
});
|
|
1757
|
-
return this.
|
|
1752
|
+
return this.e;
|
|
1758
1753
|
}
|
|
1759
1754
|
function repeat(count, map, options) {
|
|
1760
1755
|
return updateRepeat.bind({
|
|
1761
1756
|
I: new Owner(),
|
|
1762
1757
|
i: 0,
|
|
1763
|
-
|
|
1758
|
+
q: 0,
|
|
1764
1759
|
Z: count,
|
|
1765
1760
|
D: map,
|
|
1766
|
-
|
|
1767
|
-
|
|
1761
|
+
b: [],
|
|
1762
|
+
e: [],
|
|
1768
1763
|
_: options?.from,
|
|
1769
|
-
|
|
1764
|
+
p: options?.fallback
|
|
1770
1765
|
});
|
|
1771
1766
|
}
|
|
1772
1767
|
function updateRepeat() {
|
|
@@ -1776,63 +1771,63 @@ function updateRepeat() {
|
|
|
1776
1771
|
if (newLen === 0) {
|
|
1777
1772
|
if (this.i !== 0) {
|
|
1778
1773
|
this.I.dispose(false);
|
|
1779
|
-
this.
|
|
1780
|
-
this.
|
|
1774
|
+
this.b = [];
|
|
1775
|
+
this.e = [];
|
|
1781
1776
|
this.i = 0;
|
|
1782
1777
|
}
|
|
1783
|
-
if (this.
|
|
1784
|
-
this.
|
|
1785
|
-
this.
|
|
1786
|
-
this.
|
|
1778
|
+
if (this.p && !this.e[0]) {
|
|
1779
|
+
this.e[0] = compute(
|
|
1780
|
+
this.b[0] = new Owner(),
|
|
1781
|
+
this.p,
|
|
1787
1782
|
null
|
|
1788
1783
|
);
|
|
1789
1784
|
}
|
|
1790
1785
|
return;
|
|
1791
1786
|
}
|
|
1792
1787
|
const to = from + newLen;
|
|
1793
|
-
const prevTo = this.
|
|
1794
|
-
if (this.i === 0 && this.
|
|
1795
|
-
this.
|
|
1788
|
+
const prevTo = this.q + this.i;
|
|
1789
|
+
if (this.i === 0 && this.b[0])
|
|
1790
|
+
this.b[0].dispose();
|
|
1796
1791
|
for (let i = to; i < prevTo; i++)
|
|
1797
|
-
this.
|
|
1798
|
-
if (this.
|
|
1799
|
-
let i = this.
|
|
1792
|
+
this.b[i - this.q].dispose();
|
|
1793
|
+
if (this.q < from) {
|
|
1794
|
+
let i = this.q;
|
|
1800
1795
|
while (i < from && i < this.i)
|
|
1801
|
-
this.
|
|
1802
|
-
this.
|
|
1803
|
-
this.
|
|
1804
|
-
} else if (this.
|
|
1805
|
-
let i = prevTo - this.
|
|
1806
|
-
let difference = this.
|
|
1807
|
-
this.
|
|
1796
|
+
this.b[i++].dispose();
|
|
1797
|
+
this.b.splice(0, from - this.q);
|
|
1798
|
+
this.e.splice(0, from - this.q);
|
|
1799
|
+
} else if (this.q > from) {
|
|
1800
|
+
let i = prevTo - this.q - 1;
|
|
1801
|
+
let difference = this.q - from;
|
|
1802
|
+
this.b.length = this.e.length = newLen;
|
|
1808
1803
|
while (i >= difference) {
|
|
1809
|
-
this.
|
|
1810
|
-
this.
|
|
1804
|
+
this.b[i] = this.b[i - difference];
|
|
1805
|
+
this.e[i] = this.e[i - difference];
|
|
1811
1806
|
i--;
|
|
1812
1807
|
}
|
|
1813
1808
|
for (let i2 = 0; i2 < difference; i2++) {
|
|
1814
|
-
this.
|
|
1815
|
-
this.
|
|
1809
|
+
this.e[i2] = compute(
|
|
1810
|
+
this.b[i2] = new Owner(),
|
|
1816
1811
|
() => this.D(i2 + from),
|
|
1817
1812
|
null
|
|
1818
1813
|
);
|
|
1819
1814
|
}
|
|
1820
1815
|
}
|
|
1821
1816
|
for (let i = prevTo; i < to; i++) {
|
|
1822
|
-
this.
|
|
1823
|
-
this.
|
|
1817
|
+
this.e[i - from] = compute(
|
|
1818
|
+
this.b[i - from] = new Owner(),
|
|
1824
1819
|
() => this.D(i),
|
|
1825
1820
|
null
|
|
1826
1821
|
);
|
|
1827
1822
|
}
|
|
1828
|
-
this.
|
|
1829
|
-
this.
|
|
1823
|
+
this.e = this.e.slice(0, newLen);
|
|
1824
|
+
this.q = from;
|
|
1830
1825
|
this.i = newLen;
|
|
1831
1826
|
});
|
|
1832
|
-
return this.
|
|
1827
|
+
return this.e;
|
|
1833
1828
|
}
|
|
1834
1829
|
function compare(key, a, b) {
|
|
1835
1830
|
return key ? key(a) === key(b) : true;
|
|
1836
1831
|
}
|
|
1837
1832
|
|
|
1838
|
-
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY,
|
|
1833
|
+
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, createAsync, createContext, createEffect, createErrorBoundary, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, deep, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, runWithObserver, runWithOwner, setContext, tryCatch, untrack, unwrap };
|