@solidjs/signals 0.0.7 → 0.0.8

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