@solidjs/signals 0.0.4 → 0.0.6

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
@@ -5,9 +5,7 @@ var NotReadyError = class extends Error {
5
5
  };
6
6
  var NoOwnerError = class extends Error {
7
7
  constructor() {
8
- super(
9
- ""
10
- );
8
+ super("");
11
9
  }
12
10
  };
13
11
  var ContextNotFoundError = class extends Error {
@@ -18,11 +16,6 @@ var ContextNotFoundError = class extends Error {
18
16
  }
19
17
  };
20
18
 
21
- // src/utils.ts
22
- function isUndefined(value) {
23
- return typeof value === "undefined";
24
- }
25
-
26
19
  // src/core/constants.ts
27
20
  var STATE_CLEAN = 0;
28
21
  var STATE_CHECK = 1;
@@ -34,6 +27,65 @@ var EFFECT_RENDER = 1;
34
27
  var EFFECT_USER = 2;
35
28
  var SUPPORTS_PROXY = typeof Proxy === "function";
36
29
 
30
+ // src/core/utils.ts
31
+ function isUndefined(value) {
32
+ return typeof value === "undefined";
33
+ }
34
+ function flatten(children, options) {
35
+ if (typeof children === "function" && !children.length) {
36
+ if (options == null ? void 0 : options.doNotUnwrap)
37
+ return children;
38
+ do {
39
+ children = children();
40
+ } while (typeof children === "function" && !children.length);
41
+ }
42
+ if ((options == null ? void 0 : options.skipNonRendered) && (children == null || children === true || children === false || children === ""))
43
+ return;
44
+ if (Array.isArray(children)) {
45
+ let results = [];
46
+ if (flattenArray(children, results, options)) {
47
+ return () => {
48
+ let nested = [];
49
+ flattenArray(results, nested, { ...options, doNotUnwrap: false });
50
+ return nested;
51
+ };
52
+ }
53
+ return results;
54
+ }
55
+ return children;
56
+ }
57
+ function flattenArray(children, results = [], options) {
58
+ let notReady = null;
59
+ let needsUnwrap = false;
60
+ for (let i = 0; i < children.length; i++) {
61
+ try {
62
+ let child = children[i];
63
+ if (typeof child === "function" && !child.length) {
64
+ if (options == null ? void 0 : options.doNotUnwrap) {
65
+ results.push(child);
66
+ needsUnwrap = true;
67
+ continue;
68
+ }
69
+ do {
70
+ child = child();
71
+ } while (typeof child === "function" && !child.length);
72
+ }
73
+ if (Array.isArray(child)) {
74
+ needsUnwrap = flattenArray(child, results, options);
75
+ } else if ((options == null ? void 0 : options.skipNonRendered) && (child == null || child === true || child === false || child === "")) {
76
+ } else
77
+ results.push(child);
78
+ } catch (e) {
79
+ if (!(e instanceof NotReadyError))
80
+ throw e;
81
+ notReady = e;
82
+ }
83
+ }
84
+ if (notReady)
85
+ throw notReady;
86
+ return needsUnwrap;
87
+ }
88
+
37
89
  // src/core/owner.ts
38
90
  var currentOwner = null;
39
91
  var defaultContext = {};
@@ -53,9 +105,9 @@ var Owner = class {
53
105
  m = null;
54
106
  p = null;
55
107
  a = STATE_CLEAN;
56
- h = null;
108
+ j = null;
57
109
  n = defaultContext;
58
- i = null;
110
+ k = null;
59
111
  e = null;
60
112
  constructor(signal = false) {
61
113
  if (currentOwner && !signal)
@@ -71,8 +123,8 @@ var Owner = class {
71
123
  if (child.n !== this.n) {
72
124
  child.n = { ...this.n, ...child.n };
73
125
  }
74
- if (this.i) {
75
- child.i = !child.i ? this.i : [...child.i, ...this.i];
126
+ if (this.k) {
127
+ child.k = !child.k ? this.k : [...child.k, ...this.k];
76
128
  }
77
129
  if (this.e)
78
130
  child.e = this.e;
@@ -101,30 +153,30 @@ var Owner = class {
101
153
  this.o = null;
102
154
  this.p = null;
103
155
  this.n = defaultContext;
104
- this.i = null;
156
+ this.k = null;
105
157
  this.a = STATE_DISPOSED;
106
158
  this.emptyDisposal();
107
159
  }
108
160
  emptyDisposal() {
109
- if (!this.h)
161
+ if (!this.j)
110
162
  return;
111
- if (Array.isArray(this.h)) {
112
- for (let i = 0; i < this.h.length; i++) {
113
- const callable = this.h[i];
163
+ if (Array.isArray(this.j)) {
164
+ for (let i = 0; i < this.j.length; i++) {
165
+ const callable = this.j[i];
114
166
  callable.call(callable);
115
167
  }
116
168
  } else {
117
- this.h.call(this.h);
169
+ this.j.call(this.j);
118
170
  }
119
- this.h = null;
171
+ this.j = null;
120
172
  }
121
173
  handleError(error) {
122
- if (!this.i)
174
+ if (!this.k)
123
175
  throw error;
124
- let i = 0, len = this.i.length;
176
+ let i = 0, len = this.k.length;
125
177
  for (i = 0; i < len; i++) {
126
178
  try {
127
- this.i[i](error);
179
+ this.k[i](error);
128
180
  break;
129
181
  } catch (e) {
130
182
  error = e;
@@ -163,12 +215,12 @@ function onCleanup(fn) {
163
215
  if (!currentOwner)
164
216
  return fn;
165
217
  const node = currentOwner;
166
- if (!node.h) {
167
- node.h = fn;
168
- } else if (Array.isArray(node.h)) {
169
- node.h.push(fn);
218
+ if (!node.j) {
219
+ node.j = fn;
220
+ } else if (Array.isArray(node.j)) {
221
+ node.j.push(fn);
170
222
  } else {
171
- node.h = [node.h, fn];
223
+ node.j = [node.j, fn];
172
224
  }
173
225
  return fn;
174
226
  }
@@ -197,40 +249,41 @@ function incrementClock() {
197
249
  }
198
250
  var UNCHANGED = Symbol(0);
199
251
  var Computation = class extends Owner {
200
- b = null;
201
252
  c = null;
253
+ b = null;
202
254
  d;
203
- E;
255
+ C;
204
256
  // Used in __DEV__ mode, hopefully removed in production
205
257
  V;
206
258
  // Using false is an optimization as an alternative to _equals: () => false
207
259
  // which could enable more efficient DIRTY notification
208
- F = isEqual;
209
- N;
260
+ G = isEqual;
261
+ O;
210
262
  /** Whether the computation is an error or has ancestors that are unresolved */
211
- j = 0;
263
+ f = 0;
212
264
  /** Which flags raised by sources are handled, vs. being passed through. */
213
- A = DEFAULT_FLAGS;
214
- G = null;
265
+ D = DEFAULT_FLAGS;
266
+ z = null;
215
267
  H = null;
216
268
  I = -1;
217
269
  constructor(initialValue, compute2, options) {
218
270
  super(compute2 === null);
219
- this.E = compute2;
271
+ this.C = compute2;
220
272
  this.a = compute2 ? STATE_UNINITIALIZED : STATE_CLEAN;
221
273
  this.d = initialValue;
222
274
  if ((options == null ? void 0 : options.equals) !== void 0)
223
- this.F = options.equals;
275
+ this.G = options.equals;
224
276
  if (options == null ? void 0 : options.unobserved)
225
- this.N = options == null ? void 0 : options.unobserved;
277
+ this.O = options == null ? void 0 : options.unobserved;
226
278
  }
227
- O() {
228
- if (this.E)
279
+ P() {
280
+ var _a;
281
+ if (this.C)
229
282
  this.s();
230
- if (!this.b || this.b.length)
283
+ if (!this.C || ((_a = this.c) == null ? void 0 : _a.length))
231
284
  track(this);
232
- newFlags |= this.j & ~currentMask;
233
- if (this.j & ERROR_BIT) {
285
+ newFlags |= this.f & ~currentMask;
286
+ if (this.f & ERROR_BIT) {
234
287
  throw this.d;
235
288
  } else {
236
289
  return this.d;
@@ -241,7 +294,7 @@ var Computation = class extends Owner {
241
294
  * Automatically re-executes the surrounding computation when the value changes
242
295
  */
243
296
  read() {
244
- return this.O();
297
+ return this.P();
245
298
  }
246
299
  /**
247
300
  * Return the current value of this computation
@@ -254,7 +307,7 @@ var Computation = class extends Owner {
254
307
  if (!syncResolve && this.loading()) {
255
308
  throw new NotReadyError();
256
309
  }
257
- return this.O();
310
+ return this.P();
258
311
  }
259
312
  /**
260
313
  * Return true if the computation is the value is dependent on an unresolved promise
@@ -274,26 +327,26 @@ var Computation = class extends Owner {
274
327
  * Triggers re-execution of the computation when the error state changes
275
328
  */
276
329
  error() {
277
- if (this.G === null) {
278
- this.G = errorState(this);
330
+ if (this.z === null) {
331
+ this.z = errorState(this);
279
332
  }
280
- return this.G.read();
333
+ return this.z.read();
281
334
  }
282
335
  /** Update the computation with a new value. */
283
336
  write(value, flags = 0, raw = false) {
284
337
  const newValue = !raw && typeof value === "function" ? value(this.d) : value;
285
- const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.a === STATE_UNINITIALIZED || this.F === false || !this.F(this.d, newValue));
338
+ const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.a === STATE_UNINITIALIZED || this.G === false || !this.G(this.d, newValue));
286
339
  if (valueChanged)
287
340
  this.d = newValue;
288
- const changedFlagsMask = this.j ^ flags, changedFlags = changedFlagsMask & flags;
289
- this.j = flags;
341
+ const changedFlagsMask = this.f ^ flags, changedFlags = changedFlagsMask & flags;
342
+ this.f = flags;
290
343
  this.I = clock + 1;
291
- if (this.c) {
292
- for (let i = 0; i < this.c.length; i++) {
344
+ if (this.b) {
345
+ for (let i = 0; i < this.b.length; i++) {
293
346
  if (valueChanged) {
294
- this.c[i].t(STATE_DIRTY);
347
+ this.b[i].t(STATE_DIRTY);
295
348
  } else if (changedFlagsMask) {
296
- this.c[i].P(changedFlagsMask, changedFlags);
349
+ this.b[i].Q(changedFlagsMask, changedFlags);
297
350
  }
298
351
  }
299
352
  }
@@ -306,9 +359,9 @@ var Computation = class extends Owner {
306
359
  if (this.a >= state)
307
360
  return;
308
361
  this.a = state;
309
- if (this.c) {
310
- for (let i = 0; i < this.c.length; i++) {
311
- this.c[i].t(STATE_CHECK);
362
+ if (this.b) {
363
+ for (let i = 0; i < this.b.length; i++) {
364
+ this.b[i].t(STATE_CHECK);
312
365
  }
313
366
  }
314
367
  }
@@ -318,30 +371,30 @@ var Computation = class extends Owner {
318
371
  * @param mask A bitmask for which flag(s) were changed.
319
372
  * @param newFlags The source's new flags, masked to just the changed ones.
320
373
  */
321
- P(mask, newFlags2) {
374
+ Q(mask, newFlags2) {
322
375
  if (this.a >= STATE_DIRTY)
323
376
  return;
324
- if (mask & this.A) {
377
+ if (mask & this.D) {
325
378
  this.t(STATE_DIRTY);
326
379
  return;
327
380
  }
328
381
  if (this.a >= STATE_CHECK)
329
382
  return;
330
- const prevFlags = this.j & mask;
383
+ const prevFlags = this.f & mask;
331
384
  const deltaFlags = prevFlags ^ newFlags2;
332
385
  if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
333
386
  this.t(STATE_CHECK);
334
387
  } else {
335
- this.j ^= deltaFlags;
336
- if (this.c) {
337
- for (let i = 0; i < this.c.length; i++) {
338
- this.c[i].P(mask, newFlags2);
388
+ this.f ^= deltaFlags;
389
+ if (this.b) {
390
+ for (let i = 0; i < this.b.length; i++) {
391
+ this.b[i].Q(mask, newFlags2);
339
392
  }
340
393
  }
341
394
  }
342
395
  }
343
- Q(error) {
344
- this.write(error, this.j | ERROR_BIT);
396
+ J(error) {
397
+ this.write(error, this.f | ERROR_BIT);
345
398
  }
346
399
  /**
347
400
  * This is the core part of the reactivity system, which makes sure that the values are updated
@@ -359,9 +412,9 @@ var Computation = class extends Owner {
359
412
  }
360
413
  let observerFlags = 0;
361
414
  if (this.a === STATE_CHECK) {
362
- for (let i = 0; i < this.b.length; i++) {
363
- this.b[i].s();
364
- observerFlags |= this.b[i].j;
415
+ for (let i = 0; i < this.c.length; i++) {
416
+ this.c[i].s();
417
+ observerFlags |= this.c[i].f;
365
418
  if (this.a === STATE_DIRTY) {
366
419
  break;
367
420
  }
@@ -380,7 +433,7 @@ var Computation = class extends Owner {
380
433
  x() {
381
434
  if (this.a === STATE_DISPOSED)
382
435
  return;
383
- if (this.b)
436
+ if (this.c)
384
437
  removeSourceObservers(this, 0);
385
438
  super.x();
386
439
  }
@@ -393,11 +446,11 @@ function loadingState(node) {
393
446
  () => {
394
447
  track(node);
395
448
  node.s();
396
- return !!(node.j & LOADING_BIT);
449
+ return !!(node.f & LOADING_BIT);
397
450
  },
398
451
  options
399
452
  );
400
- computation.A = ERROR_BIT | LOADING_BIT;
453
+ computation.D = ERROR_BIT | LOADING_BIT;
401
454
  setOwner(prevOwner);
402
455
  return computation;
403
456
  }
@@ -409,17 +462,17 @@ function errorState(node) {
409
462
  () => {
410
463
  track(node);
411
464
  node.s();
412
- return !!(node.j & ERROR_BIT);
465
+ return !!(node.f & ERROR_BIT);
413
466
  },
414
467
  options
415
468
  );
416
- computation.A = ERROR_BIT;
469
+ computation.D = ERROR_BIT;
417
470
  setOwner(prevOwner);
418
471
  return computation;
419
472
  }
420
473
  function track(computation) {
421
474
  if (currentObserver) {
422
- if (!newSources && currentObserver.b && currentObserver.b[newSourcesIndex] === computation) {
475
+ if (!newSources && currentObserver.c && currentObserver.c[newSourcesIndex] === computation) {
423
476
  newSourcesIndex++;
424
477
  } else if (!newSources)
425
478
  newSources = [computation];
@@ -439,37 +492,37 @@ function update(node) {
439
492
  try {
440
493
  node.dispose(false);
441
494
  node.emptyDisposal();
442
- const result = compute(node, node.E, node);
495
+ const result = compute(node, node.C, node);
443
496
  node.write(result, newFlags, true);
444
497
  } catch (error) {
445
498
  if (error instanceof NotReadyError) {
446
499
  node.write(UNCHANGED, newFlags | LOADING_BIT);
447
500
  } else {
448
- node.Q(error);
501
+ node.J(error);
449
502
  }
450
503
  } finally {
451
504
  if (newSources) {
452
- if (node.b)
505
+ if (node.c)
453
506
  removeSourceObservers(node, newSourcesIndex);
454
- if (node.b && newSourcesIndex > 0) {
455
- node.b.length = newSourcesIndex + newSources.length;
507
+ if (node.c && newSourcesIndex > 0) {
508
+ node.c.length = newSourcesIndex + newSources.length;
456
509
  for (let i = 0; i < newSources.length; i++) {
457
- node.b[newSourcesIndex + i] = newSources[i];
510
+ node.c[newSourcesIndex + i] = newSources[i];
458
511
  }
459
512
  } else {
460
- node.b = newSources;
513
+ node.c = newSources;
461
514
  }
462
515
  let source;
463
- for (let i = newSourcesIndex; i < node.b.length; i++) {
464
- source = node.b[i];
465
- if (!source.c)
466
- source.c = [node];
516
+ for (let i = newSourcesIndex; i < node.c.length; i++) {
517
+ source = node.c[i];
518
+ if (!source.b)
519
+ source.b = [node];
467
520
  else
468
- source.c.push(node);
521
+ source.b.push(node);
469
522
  }
470
- } else if (node.b && newSourcesIndex < node.b.length) {
523
+ } else if (node.c && newSourcesIndex < node.c.length) {
471
524
  removeSourceObservers(node, newSourcesIndex);
472
- node.b.length = newSourcesIndex;
525
+ node.c.length = newSourcesIndex;
473
526
  }
474
527
  newSources = prevSources;
475
528
  newSourcesIndex = prevSourcesIndex;
@@ -481,14 +534,14 @@ function removeSourceObservers(node, index) {
481
534
  var _a;
482
535
  let source;
483
536
  let swap;
484
- for (let i = index; i < node.b.length; i++) {
485
- source = node.b[i];
486
- if (source.c) {
487
- swap = source.c.indexOf(node);
488
- source.c[swap] = source.c[source.c.length - 1];
489
- source.c.pop();
490
- if (!source.c.length)
491
- (_a = source.N) == null ? void 0 : _a.call(source);
537
+ for (let i = index; i < node.c.length; i++) {
538
+ source = node.c[i];
539
+ if (source.b) {
540
+ swap = source.b.indexOf(node);
541
+ source.b[swap] = source.b[source.b.length - 1];
542
+ source.b.pop();
543
+ if (!source.b.length)
544
+ (_a = source.O) == null ? void 0 : _a.call(source);
492
545
  }
493
546
  }
494
547
  }
@@ -532,7 +585,7 @@ function latest(fn) {
532
585
  function compute(owner, compute2, observer) {
533
586
  const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask;
534
587
  currentObserver = observer;
535
- currentMask = (observer == null ? void 0 : observer.A) ?? DEFAULT_FLAGS;
588
+ currentMask = (observer == null ? void 0 : observer.D) ?? DEFAULT_FLAGS;
536
589
  try {
537
590
  return compute2(observer ? observer.d : void 0);
538
591
  } finally {
@@ -548,13 +601,13 @@ function schedule() {
548
601
  if (scheduled)
549
602
  return;
550
603
  scheduled = true;
551
- if (!globalQueue.B)
604
+ if (!globalQueue.E)
552
605
  queueMicrotask(flushSync);
553
606
  }
554
607
  var Queue = class {
555
- B = false;
608
+ E = false;
556
609
  u = [[], [], []];
557
- z = [];
610
+ A = [];
558
611
  enqueue(type, node) {
559
612
  this.u[0].push(node);
560
613
  if (type)
@@ -572,14 +625,14 @@ var Queue = class {
572
625
  runEffectQueue(effects);
573
626
  }
574
627
  }
575
- for (let i = 0; i < this.z.length; i++) {
576
- this.z[i].run(type);
628
+ for (let i = 0; i < this.A.length; i++) {
629
+ this.A[i].run(type);
577
630
  }
578
631
  }
579
632
  flush() {
580
- if (this.B)
633
+ if (this.E)
581
634
  return;
582
- this.B = true;
635
+ this.E = true;
583
636
  try {
584
637
  this.run(EFFECT_PURE);
585
638
  incrementClock();
@@ -587,24 +640,32 @@ var Queue = class {
587
640
  this.run(EFFECT_RENDER);
588
641
  this.run(EFFECT_USER);
589
642
  } finally {
590
- this.B = false;
643
+ this.E = false;
591
644
  }
592
645
  }
593
646
  addChild(child) {
594
- this.z.push(child);
647
+ this.A.push(child);
595
648
  }
596
649
  removeChild(child) {
597
- const index = this.z.indexOf(child);
650
+ const index = this.A.indexOf(child);
598
651
  if (index >= 0)
599
- this.z.splice(index, 1);
652
+ this.A.splice(index, 1);
600
653
  }
601
654
  };
602
655
  var globalQueue = new Queue();
656
+ var globalTasks = [];
603
657
  function flushSync() {
604
658
  while (scheduled) {
605
659
  globalQueue.flush();
660
+ for (let i = 0; i < globalTasks.length; i++)
661
+ globalTasks[i]();
662
+ globalTasks.length = 0;
606
663
  }
607
664
  }
665
+ function queueTask(fn) {
666
+ globalTasks.push(fn);
667
+ schedule();
668
+ }
608
669
  function createBoundary(fn, queue) {
609
670
  const owner = new Owner();
610
671
  const parentQueue = owner.e || globalQueue;
@@ -637,54 +698,54 @@ function runEffectQueue(queue) {
637
698
 
638
699
  // src/core/effect.ts
639
700
  var Effect = class extends Computation {
640
- J;
641
- K = false;
642
- C;
643
- D;
701
+ K;
702
+ L = false;
703
+ F;
704
+ B;
644
705
  e;
645
706
  constructor(initialValue, compute2, effect, options) {
646
707
  var _a;
647
708
  super(initialValue, compute2, options);
648
- this.J = effect;
649
- this.C = initialValue;
650
- this.D = (options == null ? void 0 : options.render) ? EFFECT_RENDER : EFFECT_USER;
709
+ this.K = effect;
710
+ this.F = initialValue;
711
+ this.B = (options == null ? void 0 : options.render) ? EFFECT_RENDER : EFFECT_USER;
651
712
  this.e = ((_a = getOwner()) == null ? void 0 : _a.e) || globalQueue;
652
713
  this.s();
653
- this.D === EFFECT_USER ? this.e.enqueue(this.D, this) : this.R();
714
+ this.B === EFFECT_USER ? this.e.enqueue(this.B, this) : this.R();
654
715
  }
655
716
  write(value, flags = 0) {
656
717
  var _a, _b;
657
- const currentFlags = this.j;
658
- this.j = flags;
659
- if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
660
- (_b = (_a = this.e).T) == null ? void 0 : _b.call(_a, this);
718
+ const currentFlags = this.f;
719
+ this.f = flags;
720
+ if (this.B === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
721
+ (_b = (_a = this.e).S) == null ? void 0 : _b.call(_a, this);
661
722
  }
662
723
  if (value === UNCHANGED)
663
724
  return this.d;
664
725
  this.d = value;
665
- this.K = true;
726
+ this.L = true;
666
727
  return value;
667
728
  }
668
729
  t(state) {
669
730
  if (this.a >= state)
670
731
  return;
671
732
  if (this.a === STATE_CLEAN)
672
- this.e.enqueue(this.D, this);
733
+ this.e.enqueue(this.B, this);
673
734
  this.a = state;
674
735
  }
675
- Q(error) {
736
+ J(error) {
676
737
  this.handleError(error);
677
738
  }
678
739
  x() {
679
- this.J = void 0;
680
- this.C = void 0;
740
+ this.K = void 0;
741
+ this.F = void 0;
681
742
  super.x();
682
743
  }
683
744
  R() {
684
- if (this.K && this.a !== STATE_DISPOSED) {
685
- this.J(this.d, this.C);
686
- this.C = this.d;
687
- this.K = false;
745
+ if (this.L && this.a !== STATE_DISPOSED) {
746
+ this.K(this.d, this.F);
747
+ this.F = this.d;
748
+ this.L = false;
688
749
  }
689
750
  }
690
751
  };
@@ -707,35 +768,49 @@ var EagerComputation = class extends Computation {
707
768
 
708
769
  // src/core/suspense.ts
709
770
  var SuspenseQueue = class extends Queue {
710
- f = /* @__PURE__ */ new Set();
771
+ g = /* @__PURE__ */ new Set();
711
772
  q = false;
712
- L = new Computation(false, null);
773
+ M = new Computation(false, null);
713
774
  run(type) {
714
775
  if (type && this.q)
715
776
  return;
716
777
  super.run(type);
717
778
  }
718
- T(node) {
719
- if (node.j & LOADING_BIT) {
720
- this.f.add(node);
779
+ S(node) {
780
+ if (node.f & LOADING_BIT) {
781
+ this.g.add(node);
721
782
  if (!this.q) {
722
783
  this.q = true;
723
- queueMicrotask(() => this.L.write(true));
784
+ queueTask(() => this.M.write(true));
724
785
  }
725
786
  } else {
726
- this.f.delete(node);
727
- if (this.f.size === 0) {
787
+ this.g.delete(node);
788
+ if (this.g.size === 0) {
728
789
  this.q = false;
729
- queueMicrotask(() => this.L.write(false));
790
+ queueTask(() => this.M.write(false));
730
791
  }
731
792
  }
732
793
  }
733
794
  };
734
- function createSuspense(fn, fallbackFn) {
795
+ var LiveComputation = class extends EagerComputation {
796
+ write(value, flags = 0) {
797
+ var _a, _b;
798
+ const currentFlags = this.f;
799
+ super.write(value, flags);
800
+ if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
801
+ (_b = (_a = this.e).S) == null ? void 0 : _b.call(_a, this);
802
+ }
803
+ return this.d;
804
+ }
805
+ };
806
+ function createSuspense(fn, fallback) {
735
807
  const queue = new SuspenseQueue();
736
- const tree = createBoundary(fn, queue);
737
- const equality = new Computation(null, () => queue.L.read() || queue.q);
738
- const comp = new Computation(null, () => equality.read() ? untrack(fallbackFn) : tree);
808
+ const tree = createBoundary(() => {
809
+ const child = new Computation(null, fn);
810
+ return new LiveComputation(null, () => flatten(child.wait()));
811
+ }, queue);
812
+ const equality = new Computation(null, () => queue.M.read() || queue.q);
813
+ const comp = new Computation(null, () => equality.read() ? fallback() : tree.read());
739
814
  return comp.read.bind(comp);
740
815
  }
741
816
 
@@ -763,13 +838,13 @@ function createMemo(compute2, value, options) {
763
838
  );
764
839
  let resolvedValue;
765
840
  return () => {
766
- var _a, _b;
841
+ var _a, _b, _c;
767
842
  if (node) {
768
843
  resolvedValue = node.wait();
769
- if (!((_a = node.b) == null ? void 0 : _a.length)) {
844
+ if (!((_a = node.c) == null ? void 0 : _a.length) && ((_b = node.m) == null ? void 0 : _b.o) !== node) {
770
845
  node.dispose();
771
846
  node = void 0;
772
- } else if (!node.o && !((_b = node.c) == null ? void 0 : _b.length)) {
847
+ } else if (!node.o && !((_c = node.b) == null ? void 0 : _c.length)) {
773
848
  node.dispose();
774
849
  node.a = STATE_UNINITIALIZED;
775
850
  }
@@ -800,7 +875,7 @@ function createAsync(compute2, value, options) {
800
875
  if (isPromise) {
801
876
  source.then(
802
877
  (value3) => {
803
- signal.write(value3, 0);
878
+ signal.write(value3, 0, true);
804
879
  },
805
880
  (error) => {
806
881
  signal.write(error, ERROR_BIT);
@@ -814,7 +889,7 @@ function createAsync(compute2, value, options) {
814
889
  for await (let value3 of source) {
815
890
  if (abort)
816
891
  return;
817
- signal.write(value3, 0);
892
+ signal.write(value3, 0, true);
818
893
  }
819
894
  } catch (error) {
820
895
  signal.write(error, ERROR_BIT);
@@ -852,14 +927,36 @@ function runWithOwner(owner, run) {
852
927
  return void 0;
853
928
  }
854
929
  }
855
- function catchError(fn, handler) {
930
+ function createErrorBoundary(fn, fallback) {
856
931
  const owner = new Owner();
857
- owner.i = owner.i ? [handler, ...owner.i] : [handler];
858
- try {
859
- compute(owner, fn, null);
860
- } catch (error) {
861
- owner.handleError(error);
862
- }
932
+ const error = new Computation(null, null);
933
+ const reset = new Computation(null, null, { equals: false });
934
+ const handler = (err) => error.write({ z: err });
935
+ owner.k = owner.k ? [handler, ...owner.k] : [handler];
936
+ const guarded = compute(
937
+ owner,
938
+ () => {
939
+ const c = new Computation(null, () => (reset.read(), fn()));
940
+ const f = new Computation(null, () => flatten(c.read()));
941
+ f.J = function(error2) {
942
+ this.handleError(error2);
943
+ };
944
+ return f;
945
+ },
946
+ null
947
+ );
948
+ const decision = new Computation(null, () => {
949
+ if (!error.read()) {
950
+ const resolved = guarded.read();
951
+ if (!error.read())
952
+ return resolved;
953
+ }
954
+ return fallback(error.read().z, () => {
955
+ error.write(null);
956
+ reset.write(null);
957
+ });
958
+ });
959
+ return decision.read.bind(decision);
863
960
  }
864
961
 
865
962
  // src/store/store.ts
@@ -1323,75 +1420,75 @@ function omit(props, ...keys) {
1323
1420
  function mapArray(list, map, options) {
1324
1421
  const keyFn = typeof (options == null ? void 0 : options.keyed) === "function" ? options.keyed : void 0;
1325
1422
  return updateKeyedMap.bind({
1326
- S: new Owner(),
1423
+ T: new Owner(),
1327
1424
  w: 0,
1328
1425
  U: list,
1329
1426
  r: [],
1330
- M: map,
1331
- k: [],
1332
- f: [],
1427
+ N: map,
1428
+ l: [],
1429
+ g: [],
1333
1430
  y: keyFn,
1334
- g: keyFn || (options == null ? void 0 : options.keyed) === false ? [] : void 0,
1335
- l: map.length > 1 ? [] : void 0,
1431
+ h: keyFn || (options == null ? void 0 : options.keyed) === false ? [] : void 0,
1432
+ i: map.length > 1 ? [] : void 0,
1336
1433
  q: options == null ? void 0 : options.fallback
1337
1434
  });
1338
1435
  }
1339
1436
  function updateKeyedMap() {
1340
1437
  const newItems = this.U() || [], newLen = newItems.length;
1341
1438
  newItems[$TRACK];
1342
- runWithOwner(this.S, () => {
1343
- let i, j, mapper = this.g ? () => {
1344
- this.g[j] = new Computation(newItems[j], null);
1345
- this.l[j] = new Computation(j, null);
1346
- return this.M(
1347
- Computation.prototype.read.bind(this.g[j]),
1348
- Computation.prototype.read.bind(this.l[j])
1439
+ runWithOwner(this.T, () => {
1440
+ let i, j, mapper = this.h ? () => {
1441
+ this.h[j] = new Computation(newItems[j], null);
1442
+ this.i && (this.i[j] = new Computation(j, null));
1443
+ return this.N(
1444
+ Computation.prototype.read.bind(this.h[j]),
1445
+ this.i ? Computation.prototype.read.bind(this.i[j]) : void 0
1349
1446
  );
1350
- } : this.l ? () => {
1447
+ } : this.i ? () => {
1351
1448
  const item = newItems[j];
1352
- this.l[j] = new Computation(j, null);
1353
- return this.M(() => item, Computation.prototype.read.bind(this.l[j]));
1449
+ this.i[j] = new Computation(j, null);
1450
+ return this.N(() => item, Computation.prototype.read.bind(this.i[j]));
1354
1451
  } : () => {
1355
1452
  const item = newItems[j];
1356
- return this.M(() => item);
1453
+ return this.N(() => item);
1357
1454
  };
1358
1455
  if (newLen === 0) {
1359
1456
  if (this.w !== 0) {
1360
- this.S.dispose(false);
1361
- this.f = [];
1457
+ this.T.dispose(false);
1458
+ this.g = [];
1362
1459
  this.r = [];
1363
- this.k = [];
1460
+ this.l = [];
1364
1461
  this.w = 0;
1365
- this.g && (this.g = []);
1366
- this.l && (this.l = []);
1462
+ this.h && (this.h = []);
1463
+ this.i && (this.i = []);
1367
1464
  }
1368
- if (this.q && !this.k[0]) {
1369
- this.k[0] = compute(
1370
- this.f[0] = new Owner(),
1465
+ if (this.q && !this.l[0]) {
1466
+ this.l[0] = compute(
1467
+ this.g[0] = new Owner(),
1371
1468
  this.q,
1372
1469
  null
1373
1470
  );
1374
1471
  }
1375
1472
  } else if (this.w === 0) {
1376
- if (this.f[0])
1377
- this.f[0].dispose();
1378
- this.k = new Array(newLen);
1473
+ if (this.g[0])
1474
+ this.g[0].dispose();
1475
+ this.l = new Array(newLen);
1379
1476
  for (j = 0; j < newLen; j++) {
1380
1477
  this.r[j] = newItems[j];
1381
- this.k[j] = compute(this.f[j] = new Owner(), mapper, null);
1478
+ this.l[j] = compute(this.g[j] = new Owner(), mapper, null);
1382
1479
  }
1383
1480
  this.w = newLen;
1384
1481
  } else {
1385
- let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.g ? new Array(newLen) : void 0, tempIndexes = this.l ? new Array(newLen) : void 0;
1386
- for (start = 0, end = Math.min(this.w, newLen); start < end && (this.r[start] === newItems[start] || this.g && compare(this.y, this.r[start], newItems[start])); start++) {
1387
- if (this.g)
1388
- this.g[start].write(newItems[start]);
1482
+ 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;
1483
+ for (start = 0, end = Math.min(this.w, newLen); start < end && (this.r[start] === newItems[start] || this.h && compare(this.y, this.r[start], newItems[start])); start++) {
1484
+ if (this.h)
1485
+ this.h[start].write(newItems[start]);
1389
1486
  }
1390
- for (end = this.w - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.r[end] === newItems[newEnd] || this.g && compare(this.y, this.r[end], newItems[newEnd])); end--, newEnd--) {
1391
- temp[newEnd] = this.k[end];
1392
- tempNodes[newEnd] = this.f[end];
1393
- tempRows && (tempRows[newEnd] = this.g[end]);
1394
- tempIndexes && (tempIndexes[newEnd] = this.l[end]);
1487
+ for (end = this.w - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.r[end] === newItems[newEnd] || this.h && compare(this.y, this.r[end], newItems[newEnd])); end--, newEnd--) {
1488
+ temp[newEnd] = this.l[end];
1489
+ tempNodes[newEnd] = this.g[end];
1490
+ tempRows && (tempRows[newEnd] = this.h[end]);
1491
+ tempIndexes && (tempIndexes[newEnd] = this.i[end]);
1395
1492
  }
1396
1493
  newIndices = /* @__PURE__ */ new Map();
1397
1494
  newIndicesNext = new Array(newEnd + 1);
@@ -1407,36 +1504,36 @@ function updateKeyedMap() {
1407
1504
  key = this.y ? this.y(item) : item;
1408
1505
  j = newIndices.get(key);
1409
1506
  if (j !== void 0 && j !== -1) {
1410
- temp[j] = this.k[i];
1411
- tempNodes[j] = this.f[i];
1412
- tempRows && (tempRows[j] = this.g[i]);
1413
- tempIndexes && (tempIndexes[j] = this.l[i]);
1507
+ temp[j] = this.l[i];
1508
+ tempNodes[j] = this.g[i];
1509
+ tempRows && (tempRows[j] = this.h[i]);
1510
+ tempIndexes && (tempIndexes[j] = this.i[i]);
1414
1511
  j = newIndicesNext[j];
1415
1512
  newIndices.set(key, j);
1416
1513
  } else
1417
- this.f[i].dispose();
1514
+ this.g[i].dispose();
1418
1515
  }
1419
1516
  for (j = start; j < newLen; j++) {
1420
1517
  if (j in temp) {
1421
- this.k[j] = temp[j];
1422
- this.f[j] = tempNodes[j];
1518
+ this.l[j] = temp[j];
1519
+ this.g[j] = tempNodes[j];
1423
1520
  if (tempRows) {
1424
- this.g[j] = tempRows[j];
1425
- this.g[j].write(newItems[j]);
1521
+ this.h[j] = tempRows[j];
1522
+ this.h[j].write(newItems[j]);
1426
1523
  }
1427
1524
  if (tempIndexes) {
1428
- this.l[j] = tempIndexes[j];
1429
- this.l[j].write(j);
1525
+ this.i[j] = tempIndexes[j];
1526
+ this.i[j].write(j);
1430
1527
  }
1431
1528
  } else {
1432
- this.k[j] = compute(this.f[j] = new Owner(), mapper, null);
1529
+ this.l[j] = compute(this.g[j] = new Owner(), mapper, null);
1433
1530
  }
1434
1531
  }
1435
- this.k = this.k.slice(0, this.w = newLen);
1532
+ this.l = this.l.slice(0, this.w = newLen);
1436
1533
  this.r = newItems.slice(0);
1437
1534
  }
1438
1535
  });
1439
- return this.k;
1536
+ return this.l;
1440
1537
  }
1441
1538
  function compare(key, a, b) {
1442
1539
  return key ? key(a) === key(b) : true;
@@ -1453,11 +1550,11 @@ exports.NotReadyError = NotReadyError;
1453
1550
  exports.Owner = Owner;
1454
1551
  exports.Queue = Queue;
1455
1552
  exports.SUPPORTS_PROXY = SUPPORTS_PROXY;
1456
- exports.catchError = catchError;
1457
1553
  exports.createAsync = createAsync;
1458
1554
  exports.createBoundary = createBoundary;
1459
1555
  exports.createContext = createContext;
1460
1556
  exports.createEffect = createEffect;
1557
+ exports.createErrorBoundary = createErrorBoundary;
1461
1558
  exports.createMemo = createMemo;
1462
1559
  exports.createProjection = createProjection;
1463
1560
  exports.createRenderEffect = createRenderEffect;
@@ -1465,6 +1562,7 @@ exports.createRoot = createRoot;
1465
1562
  exports.createSignal = createSignal;
1466
1563
  exports.createStore = createStore;
1467
1564
  exports.createSuspense = createSuspense;
1565
+ exports.flatten = flatten;
1468
1566
  exports.flushSync = flushSync;
1469
1567
  exports.getContext = getContext;
1470
1568
  exports.getObserver = getObserver;