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