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