@solidjs/signals 0.0.9 → 0.0.10

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/prod.js CHANGED
@@ -30,6 +30,103 @@ var EFFECT_RENDER = 1;
30
30
  var EFFECT_USER = 2;
31
31
  var SUPPORTS_PROXY = typeof Proxy === "function";
32
32
 
33
+ // src/core/scheduler.ts
34
+ var clock = 0;
35
+ function getClock() {
36
+ return clock;
37
+ }
38
+ function incrementClock() {
39
+ clock++;
40
+ }
41
+ var scheduled = false;
42
+ function schedule() {
43
+ if (scheduled)
44
+ return;
45
+ scheduled = true;
46
+ if (!globalQueue.H)
47
+ queueMicrotask(flushSync);
48
+ }
49
+ var Queue = class {
50
+ H = false;
51
+ r = [[], [], []];
52
+ D = [];
53
+ enqueue(type, node) {
54
+ this.r[0].push(node);
55
+ if (type)
56
+ this.r[type].push(node);
57
+ schedule();
58
+ }
59
+ run(type) {
60
+ if (this.r[type].length) {
61
+ if (type === EFFECT_PURE) {
62
+ runPureQueue(this.r[type]);
63
+ this.r[type] = [];
64
+ } else {
65
+ const effects = this.r[type];
66
+ this.r[type] = [];
67
+ runEffectQueue(effects);
68
+ }
69
+ }
70
+ let rerun = false;
71
+ for (let i = 0; i < this.D.length; i++) {
72
+ rerun = this.D[i].run(type) || rerun;
73
+ }
74
+ if (type === EFFECT_PURE && this.r[type].length)
75
+ return true;
76
+ }
77
+ flush() {
78
+ if (this.H)
79
+ return;
80
+ this.H = true;
81
+ try {
82
+ while (this.run(EFFECT_PURE)) {
83
+ }
84
+ incrementClock();
85
+ scheduled = false;
86
+ this.run(EFFECT_RENDER);
87
+ this.run(EFFECT_USER);
88
+ } finally {
89
+ this.H = false;
90
+ }
91
+ }
92
+ addChild(child) {
93
+ this.D.push(child);
94
+ }
95
+ removeChild(child) {
96
+ const index = this.D.indexOf(child);
97
+ if (index >= 0)
98
+ this.D.splice(index, 1);
99
+ }
100
+ };
101
+ var globalQueue = new Queue();
102
+ function flushSync() {
103
+ while (scheduled) {
104
+ globalQueue.flush();
105
+ }
106
+ }
107
+ function runTop(node) {
108
+ const ancestors = [];
109
+ for (let current = node; current !== null; current = current.s) {
110
+ if (current.a !== STATE_CLEAN) {
111
+ ancestors.push(current);
112
+ }
113
+ }
114
+ for (let i = ancestors.length - 1; i >= 0; i--) {
115
+ if (ancestors[i].a !== STATE_DISPOSED)
116
+ ancestors[i].y();
117
+ }
118
+ }
119
+ function runPureQueue(queue) {
120
+ for (let i = 0; i < queue.length; i++) {
121
+ if (queue[i].a !== STATE_CLEAN)
122
+ runTop(queue[i]);
123
+ }
124
+ }
125
+ function runEffectQueue(queue) {
126
+ for (let i = 0; i < queue.length; i++)
127
+ queue[i].T();
128
+ }
129
+
33
130
  // src/core/utils.ts
34
131
  function isUndefined(value) {
35
132
  return typeof value === "undefined";
@@ -104,23 +201,23 @@ var Owner = class {
104
201
  // We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
105
202
  // However, the children are actually added in reverse creation order
106
203
  // See comment at the top of the file for an example of the _nextSibling traversal
107
- r = null;
108
- n = null;
109
204
  s = null;
205
+ n = null;
206
+ t = null;
110
207
  a = STATE_CLEAN;
111
208
  l = null;
112
209
  p = defaultContext;
113
210
  m = null;
114
- b = null;
211
+ h = globalQueue;
115
212
  constructor(signal = false) {
116
213
  if (currentOwner && !signal)
117
214
  currentOwner.append(this);
118
215
  }
119
216
  append(child) {
120
- child.r = this;
121
217
  child.s = this;
218
+ child.t = this;
122
219
  if (this.n)
123
- this.n.s = child;
220
+ this.n.t = child;
124
221
  child.n = this.n;
125
222
  this.n = child;
126
223
  if (child.p !== this.p) {
@@ -129,32 +226,32 @@ var Owner = class {
129
226
  if (this.m) {
130
227
  child.m = !child.m ? this.m : [...child.m, ...this.m];
131
228
  }
132
- if (this.b)
133
- child.b = this.b;
229
+ if (this.h)
230
+ child.h = this.h;
134
231
  }
135
232
  dispose(self = true) {
136
233
  if (this.a === STATE_DISPOSED)
137
234
  return;
138
- let head = self ? this.s || this.r : this, current = this.n, next = null;
139
- while (current && current.r === this) {
235
+ let head = self ? this.t || this.s : this, current = this.n, next = null;
236
+ while (current && current.s === this) {
140
237
  current.dispose(true);
141
- current.z();
238
+ current.A();
142
239
  next = current.n;
143
240
  current.n = null;
144
241
  current = next;
145
242
  }
146
243
  if (self)
147
- this.z();
244
+ this.A();
148
245
  if (current)
149
- current.s = !self ? this : this.s;
246
+ current.t = !self ? this : this.t;
150
247
  if (head)
151
248
  head.n = current;
152
249
  }
153
- z() {
154
- if (this.s)
155
- this.s.n = null;
156
- this.r = null;
250
+ A() {
251
+ if (this.t)
252
+ this.t.n = null;
157
253
  this.s = null;
254
+ this.t = null;
158
255
  this.p = defaultContext;
159
256
  this.m = null;
160
257
  this.a = STATE_DISPOSED;
@@ -179,7 +276,7 @@ var Owner = class {
179
276
  let i = 0, len = this.m.length;
180
277
  for (i = 0; i < len; i++) {
181
278
  try {
182
- this.m[i](error);
279
+ this.m[i](error, this);
183
280
  break;
184
281
  } catch (e) {
185
282
  error = e;
@@ -243,58 +340,55 @@ var currentMask = DEFAULT_FLAGS;
243
340
  var newSources = null;
244
341
  var newSourcesIndex = 0;
245
342
  var newFlags = 0;
246
- var clock = 0;
247
343
  var notStale = false;
248
344
  var updateCheck = null;
249
345
  var staleCheck = null;
250
346
  function getObserver() {
251
347
  return currentObserver;
252
348
  }
253
- function getClock() {
254
- return clock;
255
- }
256
- function incrementClock() {
257
- clock++;
258
- }
259
349
  var UNCHANGED = Symbol(0);
260
350
  var Computation = class extends Owner {
261
- g = null;
262
- e = null;
351
+ f = null;
352
+ d = null;
263
353
  c;
264
- D;
265
- t;
354
+ E;
355
+ u;
266
356
  // Used in __DEV__ mode, hopefully removed in production
267
357
  Z;
268
358
  // Using false is an optimization as an alternative to _equals: () => false
269
359
  // which could enable more efficient DIRTY notification
270
360
  N = isEqual;
271
- T;
361
+ U;
272
362
  /** Whether the computation is an error or has ancestors that are unresolved */
273
- d = 0;
363
+ b = 0;
274
364
  /** Which flags raised by sources are handled, vs. being passed through. */
275
365
  O = DEFAULT_FLAGS;
276
366
  P = null;
277
- A = -1;
278
- H = false;
367
+ z = -1;
368
+ I = false;
279
369
  constructor(initialValue, compute2, options) {
280
370
  super(compute2 === null);
281
- this.t = compute2;
371
+ this.u = compute2;
282
372
  this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
283
- this.d = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
373
+ this.b = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
284
374
  this.c = initialValue;
285
375
  if (options?.equals !== void 0)
286
376
  this.N = options.equals;
287
377
  if (options?.unobserved)
288
- this.T = options?.unobserved;
378
+ this.U = options?.unobserved;
289
379
  }
290
- U() {
291
- if (this.t)
292
- this.x();
293
- if (!this.t || this.g?.length)
380
+ V() {
381
+ if (this.u) {
382
+ if (this.b & ERROR_BIT && this.z <= getClock())
383
+ update(this);
384
+ else
385
+ this.y();
386
+ }
387
+ if (!this.u || this.f?.length)
294
388
  track(this);
295
- newFlags |= this.d & ~currentMask;
296
- if (this.d & ERROR_BIT) {
297
- throw this.D;
389
+ newFlags |= this.b & ~currentMask;
390
+ if (this.b & ERROR_BIT) {
391
+ throw this.E;
298
392
  } else {
299
393
  return this.c;
300
394
  }
@@ -304,7 +398,7 @@ var Computation = class extends Owner {
304
398
  * Automatically re-executes the surrounding computation when the value changes
305
399
  */
306
400
  read() {
307
- return this.U();
401
+ return this.V();
308
402
  }
309
403
  /**
310
404
  * Return the current value of this computation
@@ -314,15 +408,15 @@ var Computation = class extends Owner {
314
408
  * before continuing
315
409
  */
316
410
  wait() {
317
- if (this.t && this.d & ERROR_BIT && this.A <= clock) {
411
+ if (this.u && this.b & ERROR_BIT && this.z <= getClock()) {
318
412
  update(this);
319
413
  }
320
- if ((notStale || this.d & UNINITIALIZED_BIT) && this.loading()) {
414
+ if ((notStale || this.b & UNINITIALIZED_BIT) && this.loading()) {
321
415
  throw new NotReadyError();
322
416
  }
323
- if (staleCheck && this.d & LOADING_BIT)
417
+ if (staleCheck && this.b & LOADING_BIT)
324
418
  staleCheck.c = true;
325
- return this.U();
419
+ return this.V();
326
420
  }
327
421
  /**
328
422
  * Return true if the computation is the value is dependent on an unresolved promise
@@ -340,20 +434,20 @@ var Computation = class extends Owner {
340
434
  /** Update the computation with a new value. */
341
435
  write(value, flags = 0, raw = false) {
342
436
  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));
437
+ const valueChanged = newValue !== UNCHANGED && (!!(this.b & UNINITIALIZED_BIT) || this.N === false || !this.N(this.c, newValue));
344
438
  if (valueChanged) {
345
439
  this.c = newValue;
346
- this.D = void 0;
440
+ this.E = void 0;
347
441
  }
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++) {
442
+ const changedFlagsMask = this.b ^ flags, changedFlags = changedFlagsMask & flags;
443
+ this.b = flags;
444
+ this.z = getClock() + 1;
445
+ if (this.d) {
446
+ for (let i = 0; i < this.d.length; i++) {
353
447
  if (valueChanged) {
354
- this.e[i].q(STATE_DIRTY);
448
+ this.d[i].q(STATE_DIRTY);
355
449
  } else if (changedFlagsMask) {
356
- this.e[i].V(changedFlagsMask, changedFlags);
450
+ this.d[i].W(changedFlagsMask, changedFlags);
357
451
  }
358
452
  }
359
453
  }
@@ -363,13 +457,13 @@ var Computation = class extends Owner {
363
457
  * Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
364
458
  */
365
459
  q(state, skipQueue) {
366
- if (this.a >= state && !this.H)
460
+ if (this.a >= state && !this.I)
367
461
  return;
368
- this.H = !!skipQueue;
462
+ this.I = !!skipQueue;
369
463
  this.a = state;
370
- if (this.e) {
371
- for (let i = 0; i < this.e.length; i++) {
372
- this.e[i].q(STATE_CHECK, skipQueue);
464
+ if (this.d) {
465
+ for (let i = 0; i < this.d.length; i++) {
466
+ this.d[i].q(STATE_CHECK, skipQueue);
373
467
  }
374
468
  }
375
469
  }
@@ -379,7 +473,7 @@ var Computation = class extends Owner {
379
473
  * @param mask A bitmask for which flag(s) were changed.
380
474
  * @param newFlags The source's new flags, masked to just the changed ones.
381
475
  */
382
- V(mask, newFlags2) {
476
+ W(mask, newFlags2) {
383
477
  if (this.a >= STATE_DIRTY)
384
478
  return;
385
479
  if (mask & this.O) {
@@ -388,22 +482,22 @@ var Computation = class extends Owner {
388
482
  }
389
483
  if (this.a >= STATE_CHECK)
390
484
  return;
391
- const prevFlags = this.d & mask;
485
+ const prevFlags = this.b & mask;
392
486
  const deltaFlags = prevFlags ^ newFlags2;
393
487
  if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
394
488
  this.q(STATE_CHECK);
395
489
  } else {
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);
490
+ this.b ^= deltaFlags;
491
+ if (this.d) {
492
+ for (let i = 0; i < this.d.length; i++) {
493
+ this.d[i].W(mask, newFlags2);
400
494
  }
401
495
  }
402
496
  }
403
497
  }
404
- I(error) {
405
- this.D = error;
406
- this.write(UNCHANGED, this.d & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
498
+ J(error) {
499
+ this.E = error;
500
+ this.write(UNCHANGED, this.b & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
407
501
  }
408
502
  /**
409
503
  * This is the core part of the reactivity system, which makes sure that the values are updated
@@ -412,7 +506,7 @@ var Computation = class extends Owner {
412
506
  *
413
507
  * This function will ensure that the value and states we read from the computation are up to date
414
508
  */
415
- x() {
509
+ y() {
416
510
  if (this.a === STATE_DISPOSED) {
417
511
  throw new Error("Tried to read a disposed computation");
418
512
  }
@@ -421,9 +515,9 @@ var Computation = class extends Owner {
421
515
  }
422
516
  let observerFlags = 0;
423
517
  if (this.a === STATE_CHECK) {
424
- for (let i = 0; i < this.g.length; i++) {
425
- this.g[i].x();
426
- observerFlags |= this.g[i].d;
518
+ for (let i = 0; i < this.f.length; i++) {
519
+ this.f[i].y();
520
+ observerFlags |= this.f[i].b;
427
521
  if (this.a === STATE_DIRTY) {
428
522
  break;
429
523
  }
@@ -439,23 +533,23 @@ var Computation = class extends Owner {
439
533
  /**
440
534
  * Remove ourselves from the owner graph and the computation graph
441
535
  */
442
- z() {
536
+ A() {
443
537
  if (this.a === STATE_DISPOSED)
444
538
  return;
445
- if (this.g)
539
+ if (this.f)
446
540
  removeSourceObservers(this, 0);
447
- super.z();
541
+ super.A();
448
542
  }
449
543
  };
450
544
  function loadingState(node) {
451
- const prevOwner = setOwner(node.r);
545
+ const prevOwner = setOwner(node.s);
452
546
  const options = void 0;
453
547
  const computation = new Computation(
454
548
  void 0,
455
549
  () => {
456
550
  track(node);
457
- node.x();
458
- return !!(node.d & LOADING_BIT);
551
+ node.y();
552
+ return !!(node.b & LOADING_BIT);
459
553
  },
460
554
  options
461
555
  );
@@ -465,7 +559,7 @@ function loadingState(node) {
465
559
  }
466
560
  function track(computation) {
467
561
  if (currentObserver) {
468
- if (!newSources && currentObserver.g && currentObserver.g[newSourcesIndex] === computation) {
562
+ if (!newSources && currentObserver.f && currentObserver.f[newSourcesIndex] === computation) {
469
563
  newSourcesIndex++;
470
564
  } else if (!newSources)
471
565
  newSources = [computation];
@@ -473,7 +567,7 @@ function track(computation) {
473
567
  newSources.push(computation);
474
568
  }
475
569
  if (updateCheck) {
476
- updateCheck.c = computation.A > currentObserver.A;
570
+ updateCheck.c = computation.z > currentObserver.z;
477
571
  }
478
572
  }
479
573
  }
@@ -485,56 +579,56 @@ function update(node) {
485
579
  try {
486
580
  node.dispose(false);
487
581
  node.emptyDisposal();
488
- const result = compute(node, node.t, node);
582
+ const result = compute(node, node.u, node);
489
583
  node.write(result, newFlags, true);
490
584
  } catch (error) {
491
585
  if (error instanceof NotReadyError) {
492
- node.write(UNCHANGED, newFlags | LOADING_BIT | node.d & UNINITIALIZED_BIT);
586
+ node.write(UNCHANGED, newFlags | LOADING_BIT | node.b & UNINITIALIZED_BIT);
493
587
  } else {
494
- node.I(error);
588
+ node.J(error);
495
589
  }
496
590
  } finally {
497
591
  if (newSources) {
498
- if (node.g)
592
+ if (node.f)
499
593
  removeSourceObservers(node, newSourcesIndex);
500
- if (node.g && newSourcesIndex > 0) {
501
- node.g.length = newSourcesIndex + newSources.length;
594
+ if (node.f && newSourcesIndex > 0) {
595
+ node.f.length = newSourcesIndex + newSources.length;
502
596
  for (let i = 0; i < newSources.length; i++) {
503
- node.g[newSourcesIndex + i] = newSources[i];
597
+ node.f[newSourcesIndex + i] = newSources[i];
504
598
  }
505
599
  } else {
506
- node.g = newSources;
600
+ node.f = newSources;
507
601
  }
508
602
  let source;
509
- for (let i = newSourcesIndex; i < node.g.length; i++) {
510
- source = node.g[i];
511
- if (!source.e)
512
- source.e = [node];
603
+ for (let i = newSourcesIndex; i < node.f.length; i++) {
604
+ source = node.f[i];
605
+ if (!source.d)
606
+ source.d = [node];
513
607
  else
514
- source.e.push(node);
608
+ source.d.push(node);
515
609
  }
516
- } else if (node.g && newSourcesIndex < node.g.length) {
610
+ } else if (node.f && newSourcesIndex < node.f.length) {
517
611
  removeSourceObservers(node, newSourcesIndex);
518
- node.g.length = newSourcesIndex;
612
+ node.f.length = newSourcesIndex;
519
613
  }
520
614
  newSources = prevSources;
521
615
  newSourcesIndex = prevSourcesIndex;
522
616
  newFlags = prevFlags;
523
- node.A = clock + 1;
617
+ node.z = getClock() + 1;
524
618
  node.a = STATE_CLEAN;
525
619
  }
526
620
  }
527
621
  function removeSourceObservers(node, index) {
528
622
  let source;
529
623
  let swap;
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?.();
624
+ for (let i = index; i < node.f.length; i++) {
625
+ source = node.f[i];
626
+ if (source.d) {
627
+ swap = source.d.indexOf(node);
628
+ source.d[swap] = source.d[source.d.length - 1];
629
+ source.d.pop();
630
+ if (!source.d.length)
631
+ source.U?.();
538
632
  }
539
633
  }
540
634
  }
@@ -602,103 +696,13 @@ function compute(owner, fn, observer) {
602
696
  notStale = prevNotStale;
603
697
  }
604
698
  }
605
-
606
- // src/core/scheduler.ts
607
- var scheduled = false;
608
- function schedule() {
609
- if (scheduled)
610
- return;
611
- scheduled = true;
612
- if (!globalQueue.J)
613
- queueMicrotask(flushSync);
614
- }
615
- var Queue = class {
616
- J = false;
617
- u = [[], [], []];
618
- E = [];
619
- enqueue(type, node) {
620
- this.u[0].push(node);
621
- if (type)
622
- this.u[type].push(node);
623
- schedule();
624
- }
625
- run(type) {
626
- if (this.u[type].length) {
627
- if (type === EFFECT_PURE) {
628
- runPureQueue(this.u[type]);
629
- this.u[type] = [];
630
- } else {
631
- const effects = this.u[type];
632
- this.u[type] = [];
633
- runEffectQueue(effects);
634
- }
635
- }
636
- let rerun = false;
637
- for (let i = 0; i < this.E.length; i++) {
638
- rerun = this.E[i].run(type) || rerun;
639
- }
640
- if (type === EFFECT_PURE && this.u[type].length)
641
- return true;
642
- }
643
- flush() {
644
- if (this.J)
645
- return;
646
- this.J = true;
647
- try {
648
- while (this.run(EFFECT_PURE)) {
649
- }
650
- incrementClock();
651
- scheduled = false;
652
- this.run(EFFECT_RENDER);
653
- this.run(EFFECT_USER);
654
- } finally {
655
- this.J = false;
656
- }
657
- }
658
- addChild(child) {
659
- this.E.push(child);
660
- }
661
- removeChild(child) {
662
- const index = this.E.indexOf(child);
663
- if (index >= 0)
664
- this.E.splice(index, 1);
665
- }
666
- };
667
- var globalQueue = new Queue();
668
- function flushSync() {
669
- while (scheduled) {
670
- globalQueue.flush();
671
- }
672
- }
673
699
  function createBoundary(fn, queue) {
674
700
  const owner = new Owner();
675
- const parentQueue = owner.b || globalQueue;
676
- parentQueue.addChild(owner.b = queue);
677
- onCleanup(() => parentQueue.removeChild(owner.b));
701
+ const parentQueue = owner.h;
702
+ parentQueue.addChild(owner.h = queue);
703
+ onCleanup(() => parentQueue.removeChild(owner.h));
678
704
  return compute(owner, fn, null);
679
705
  }
680
- function runTop(node) {
681
- const ancestors = [];
682
- for (let current = node; current !== null; current = current.r) {
683
- if (current.a !== STATE_CLEAN) {
684
- ancestors.push(current);
685
- }
686
- }
687
- for (let i = ancestors.length - 1; i >= 0; i--) {
688
- if (ancestors[i].a !== STATE_DISPOSED)
689
- ancestors[i].x();
690
- }
691
- }
692
- function runPureQueue(queue) {
693
- for (let i = 0; i < queue.length; i++) {
694
- if (queue[i].a !== STATE_CLEAN)
695
- runTop(queue[i]);
696
- }
697
- }
698
- function runEffectQueue(queue) {
699
- for (let i = 0; i < queue.length; i++)
700
- queue[i].W();
701
- }
702
706
 
703
707
  // src/core/effect.ts
704
708
  var Effect = class extends Computation {
@@ -707,29 +711,27 @@ var Effect = class extends Computation {
707
711
  B;
708
712
  Q = false;
709
713
  M;
710
- y;
711
- b;
714
+ w;
712
715
  constructor(initialValue, compute2, effect, error, options) {
713
716
  super(initialValue, compute2, options);
714
717
  this.K = effect;
715
718
  this.L = error;
716
719
  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
+ this.w = options?.render ? EFFECT_RENDER : EFFECT_USER;
721
+ if (this.w === EFFECT_RENDER) {
722
+ this.u = (p) => latest(() => compute2(p));
720
723
  }
721
- this.b = getOwner()?.b || globalQueue;
722
724
  if (!options?.defer) {
723
- this.x();
724
- this.y === EFFECT_USER ? this.b.enqueue(this.y, this) : this.W();
725
+ this.y();
726
+ this.w === EFFECT_USER ? this.h.enqueue(this.w, this) : this.T();
725
727
  }
726
728
  }
727
729
  write(value, flags = 0) {
728
730
  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);
731
+ const currentFlags = this.b;
732
+ this.b = flags;
733
+ if (this.w === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
734
+ this.h.R?.(this);
733
735
  }
734
736
  }
735
737
  if (value === UNCHANGED)
@@ -742,16 +744,16 @@ var Effect = class extends Computation {
742
744
  if (this.a >= state || skipQueue)
743
745
  return;
744
746
  if (this.a === STATE_CLEAN)
745
- this.b.enqueue(this.y, this);
747
+ this.h.enqueue(this.w, this);
746
748
  this.a = state;
747
749
  }
748
- I(error) {
750
+ J(error) {
749
751
  this.B?.();
750
- if (this.d & LOADING_BIT) {
751
- this.d = 0;
752
- this.b.R?.(this);
752
+ if (this.b & LOADING_BIT) {
753
+ this.b = 0;
754
+ this.h.R?.(this);
753
755
  }
754
- if (this.y === EFFECT_USER) {
756
+ if (this.w === EFFECT_USER) {
755
757
  try {
756
758
  return this.L ? this.B = this.L(error) : console.error(new EffectError(this.K, error));
757
759
  } catch (e) {
@@ -760,7 +762,7 @@ var Effect = class extends Computation {
760
762
  }
761
763
  this.handleError(error);
762
764
  }
763
- z() {
765
+ A() {
764
766
  if (this.a === STATE_DISPOSED)
765
767
  return;
766
768
  this.K = void 0;
@@ -768,9 +770,9 @@ var Effect = class extends Computation {
768
770
  this.L = void 0;
769
771
  this.B?.();
770
772
  this.B = void 0;
771
- super.z();
773
+ super.A();
772
774
  }
773
- W() {
775
+ T() {
774
776
  if (this.Q && this.a !== STATE_DISPOSED) {
775
777
  this.B?.();
776
778
  try {
@@ -785,38 +787,34 @@ var Effect = class extends Computation {
785
787
  }
786
788
  };
787
789
  var EagerComputation = class extends Computation {
788
- b;
789
790
  constructor(initialValue, compute2, options) {
790
791
  super(initialValue, compute2, options);
791
- this.b = getOwner()?.b || globalQueue;
792
- this.x();
792
+ !options?.defer && this.y();
793
793
  }
794
794
  q(state, skipQueue) {
795
- if (this.a >= state && !this.H)
795
+ if (this.a >= state && !this.I)
796
796
  return;
797
797
  if (this.a === STATE_CLEAN && !skipQueue)
798
- this.b.enqueue(EFFECT_PURE, this);
798
+ this.h.enqueue(EFFECT_PURE, this);
799
799
  super.q(state, skipQueue);
800
800
  }
801
801
  };
802
802
  var ProjectionComputation = class extends Computation {
803
- b;
804
803
  constructor(compute2) {
805
804
  super(null, compute2);
806
- this.b = getOwner()?.b || globalQueue;
807
805
  }
808
806
  q(state, skipQueue) {
809
- if (this.a >= state && !this.H)
807
+ if (this.a >= state && !this.I)
810
808
  return;
811
809
  if (this.a === STATE_CLEAN && !skipQueue)
812
- this.b.enqueue(EFFECT_PURE, this);
810
+ this.h.enqueue(EFFECT_PURE, this);
813
811
  super.q(state, true);
814
812
  }
815
813
  };
816
814
 
817
815
  // src/core/suspense.ts
818
816
  var SuspenseQueue = class extends Queue {
819
- f = /* @__PURE__ */ new Set();
817
+ e = /* @__PURE__ */ new Set();
820
818
  o = false;
821
819
  S = new Computation(false, null);
822
820
  run(type) {
@@ -825,15 +823,15 @@ var SuspenseQueue = class extends Queue {
825
823
  return super.run(type);
826
824
  }
827
825
  R(node) {
828
- if (node.d & LOADING_BIT) {
829
- this.f.add(node);
826
+ if (node.b & LOADING_BIT) {
827
+ this.e.add(node);
830
828
  if (!this.o) {
831
829
  this.o = true;
832
830
  this.S.write(true);
833
831
  }
834
832
  } else {
835
- this.f.delete(node);
836
- if (this.f.size === 0) {
833
+ this.e.delete(node);
834
+ if (this.e.size === 0) {
837
835
  this.o = false;
838
836
  this.S.write(false);
839
837
  }
@@ -842,10 +840,11 @@ var SuspenseQueue = class extends Queue {
842
840
  };
843
841
  var LiveComputation = class extends EagerComputation {
844
842
  write(value, flags = 0) {
845
- const currentFlags = this.d;
843
+ const currentFlags = this.b;
844
+ const dirty = this.a === STATE_DIRTY;
846
845
  super.write(value, flags);
847
- if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
848
- this.b.R?.(this);
846
+ if (dirty && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
847
+ this.h.R?.(this);
849
848
  }
850
849
  return this.c;
851
850
  }
@@ -887,10 +886,10 @@ function createMemo(compute2, value, options) {
887
886
  return () => {
888
887
  if (node) {
889
888
  resolvedValue = node.wait();
890
- if (!node.g?.length && node.n?.r !== node) {
889
+ if (!node.f?.length && node.n?.s !== node) {
891
890
  node.dispose();
892
891
  node = void 0;
893
- } else if (!node.r && !node.e?.length) {
892
+ } else if (!node.s && !node.d?.length) {
894
893
  node.dispose();
895
894
  node.a = STATE_DIRTY;
896
895
  }
@@ -920,7 +919,7 @@ function createAsync(compute2, value, options) {
920
919
  const signal = new Computation(value2, null, options);
921
920
  const w = signal.wait;
922
921
  signal.wait = function() {
923
- if (signal.d & ERROR_BIT && signal.A <= getClock()) {
922
+ if (signal.b & ERROR_BIT && signal.z <= getClock()) {
924
923
  lhs.q(STATE_DIRTY);
925
924
  throw new NotReadyError();
926
925
  }
@@ -935,7 +934,7 @@ function createAsync(compute2, value, options) {
935
934
  },
936
935
  (error) => {
937
936
  uninitialized = true;
938
- signal.I(error);
937
+ signal.J(error);
939
938
  }
940
939
  );
941
940
  } else {
@@ -987,16 +986,31 @@ function runWithOwner(owner, run) {
987
986
  }
988
987
  function createErrorBoundary(fn, fallback) {
989
988
  const owner = new Owner();
990
- const error = new Computation(null, null);
991
- const reset = new Computation(null, null, { equals: false });
992
- const handler = (err) => error.write({ D: err });
989
+ const error = new Computation(void 0, null);
990
+ const nodes = /* @__PURE__ */ new Set();
991
+ function handler(err, node) {
992
+ if (nodes.has(node))
993
+ return;
994
+ compute(
995
+ node,
996
+ () => onCleanup(() => {
997
+ nodes.delete(node);
998
+ if (!nodes.size)
999
+ error.write(void 0);
1000
+ }),
1001
+ null
1002
+ );
1003
+ nodes.add(node);
1004
+ if (nodes.size === 1)
1005
+ error.write({ E: err });
1006
+ }
993
1007
  owner.m = owner.m ? [handler, ...owner.m] : [handler];
994
1008
  const guarded = compute(
995
1009
  owner,
996
1010
  () => {
997
- const c = new Computation(null, () => (reset.read(), fn()));
998
- const f = new Computation(null, () => flatten(c.read()));
999
- f.I = function(error2) {
1011
+ const c = new Computation(void 0, fn);
1012
+ const f = new EagerComputation(void 0, () => flatten(c.read()), { defer: true });
1013
+ f.J = function(error2) {
1000
1014
  this.handleError(error2);
1001
1015
  };
1002
1016
  return f;
@@ -1009,24 +1023,29 @@ function createErrorBoundary(fn, fallback) {
1009
1023
  if (!error.read())
1010
1024
  return resolved;
1011
1025
  }
1012
- return fallback(error.read().D, () => {
1013
- error.write(null);
1014
- reset.write(null);
1026
+ return fallback(error.read().E, () => {
1027
+ incrementClock();
1028
+ for (let node of nodes) {
1029
+ node.a = STATE_DIRTY;
1030
+ node.h?.enqueue(node.w, node);
1031
+ }
1015
1032
  });
1016
1033
  });
1017
1034
  return decision.read.bind(decision);
1018
1035
  }
1019
1036
  function resolve(fn) {
1020
1037
  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);
1038
+ createRoot((dispose) => {
1039
+ new EagerComputation(void 0, () => {
1040
+ try {
1041
+ res(fn());
1042
+ } catch (err) {
1043
+ if (err instanceof NotReadyError)
1044
+ throw err;
1045
+ rej(err);
1046
+ }
1047
+ dispose();
1048
+ });
1030
1049
  });
1031
1050
  });
1032
1051
  }
@@ -1037,10 +1056,10 @@ function createReaction(effect, error, options) {
1037
1056
  ...void 0
1038
1057
  });
1039
1058
  return (tracking) => {
1040
- node.t = tracking;
1059
+ node.u = tracking;
1041
1060
  node.a = STATE_DIRTY;
1042
- node.x();
1043
- node.t = null;
1061
+ node.y();
1062
+ node.u = null;
1044
1063
  };
1045
1064
  }
1046
1065
 
@@ -1531,10 +1550,10 @@ function mapArray(list, map, options) {
1531
1550
  F: new Owner(),
1532
1551
  i: 0,
1533
1552
  X: list,
1534
- w: [],
1553
+ x: [],
1535
1554
  G: map,
1536
- h: [],
1537
- f: [],
1555
+ g: [],
1556
+ e: [],
1538
1557
  C: keyFn,
1539
1558
  j: keyFn || options?.keyed === false ? [] : void 0,
1540
1559
  k: map.length > 1 ? [] : void 0,
@@ -1563,38 +1582,38 @@ function updateKeyedMap() {
1563
1582
  if (newLen === 0) {
1564
1583
  if (this.i !== 0) {
1565
1584
  this.F.dispose(false);
1566
- this.f = [];
1567
- this.w = [];
1568
- this.h = [];
1585
+ this.e = [];
1586
+ this.x = [];
1587
+ this.g = [];
1569
1588
  this.i = 0;
1570
1589
  this.j && (this.j = []);
1571
1590
  this.k && (this.k = []);
1572
1591
  }
1573
- if (this.o && !this.h[0]) {
1574
- this.h[0] = compute(
1575
- this.f[0] = new Owner(),
1592
+ if (this.o && !this.g[0]) {
1593
+ this.g[0] = compute(
1594
+ this.e[0] = new Owner(),
1576
1595
  this.o,
1577
1596
  null
1578
1597
  );
1579
1598
  }
1580
1599
  } else if (this.i === 0) {
1581
- if (this.f[0])
1582
- this.f[0].dispose();
1583
- this.h = new Array(newLen);
1600
+ if (this.e[0])
1601
+ this.e[0].dispose();
1602
+ this.g = new Array(newLen);
1584
1603
  for (j = 0; j < newLen; j++) {
1585
- this.w[j] = newItems[j];
1586
- this.h[j] = compute(this.f[j] = new Owner(), mapper, null);
1604
+ this.x[j] = newItems[j];
1605
+ this.g[j] = compute(this.e[j] = new Owner(), mapper, null);
1587
1606
  }
1588
1607
  this.i = newLen;
1589
1608
  } else {
1590
1609
  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++) {
1610
+ for (start = 0, end = Math.min(this.i, newLen); start < end && (this.x[start] === newItems[start] || this.j && compare(this.C, this.x[start], newItems[start])); start++) {
1592
1611
  if (this.j)
1593
1612
  this.j[start].write(newItems[start]);
1594
1613
  }
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];
1614
+ for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.x[end] === newItems[newEnd] || this.j && compare(this.C, this.x[end], newItems[newEnd])); end--, newEnd--) {
1615
+ temp[newEnd] = this.g[end];
1616
+ tempNodes[newEnd] = this.e[end];
1598
1617
  tempRows && (tempRows[newEnd] = this.j[end]);
1599
1618
  tempIndexes && (tempIndexes[newEnd] = this.k[end]);
1600
1619
  }
@@ -1608,23 +1627,23 @@ function updateKeyedMap() {
1608
1627
  newIndices.set(key, j);
1609
1628
  }
1610
1629
  for (i = start; i <= end; i++) {
1611
- item = this.w[i];
1630
+ item = this.x[i];
1612
1631
  key = this.C ? this.C(item) : item;
1613
1632
  j = newIndices.get(key);
1614
1633
  if (j !== void 0 && j !== -1) {
1615
- temp[j] = this.h[i];
1616
- tempNodes[j] = this.f[i];
1634
+ temp[j] = this.g[i];
1635
+ tempNodes[j] = this.e[i];
1617
1636
  tempRows && (tempRows[j] = this.j[i]);
1618
1637
  tempIndexes && (tempIndexes[j] = this.k[i]);
1619
1638
  j = newIndicesNext[j];
1620
1639
  newIndices.set(key, j);
1621
1640
  } else
1622
- this.f[i].dispose();
1641
+ this.e[i].dispose();
1623
1642
  }
1624
1643
  for (j = start; j < newLen; j++) {
1625
1644
  if (j in temp) {
1626
- this.h[j] = temp[j];
1627
- this.f[j] = tempNodes[j];
1645
+ this.g[j] = temp[j];
1646
+ this.e[j] = tempNodes[j];
1628
1647
  if (tempRows) {
1629
1648
  this.j[j] = tempRows[j];
1630
1649
  this.j[j].write(newItems[j]);
@@ -1634,14 +1653,14 @@ function updateKeyedMap() {
1634
1653
  this.k[j].write(j);
1635
1654
  }
1636
1655
  } else {
1637
- this.h[j] = compute(this.f[j] = new Owner(), mapper, null);
1656
+ this.g[j] = compute(this.e[j] = new Owner(), mapper, null);
1638
1657
  }
1639
1658
  }
1640
- this.h = this.h.slice(0, this.i = newLen);
1641
- this.w = newItems.slice(0);
1659
+ this.g = this.g.slice(0, this.i = newLen);
1660
+ this.x = newItems.slice(0);
1642
1661
  }
1643
1662
  });
1644
- return this.h;
1663
+ return this.g;
1645
1664
  }
1646
1665
  function repeat(count, map, options) {
1647
1666
  return updateRepeat.bind({
@@ -1649,8 +1668,8 @@ function repeat(count, map, options) {
1649
1668
  i: 0,
1650
1669
  Y: count,
1651
1670
  G: map,
1652
- f: [],
1653
- h: [],
1671
+ e: [],
1672
+ g: [],
1654
1673
  o: options?.fallback
1655
1674
  });
1656
1675
  }
@@ -1660,34 +1679,34 @@ function updateRepeat() {
1660
1679
  if (newLen === 0) {
1661
1680
  if (this.i !== 0) {
1662
1681
  this.F.dispose(false);
1663
- this.f = [];
1664
- this.h = [];
1682
+ this.e = [];
1683
+ this.g = [];
1665
1684
  this.i = 0;
1666
1685
  }
1667
- if (this.o && !this.h[0]) {
1668
- this.h[0] = compute(
1669
- this.f[0] = new Owner(),
1686
+ if (this.o && !this.g[0]) {
1687
+ this.g[0] = compute(
1688
+ this.e[0] = new Owner(),
1670
1689
  this.o,
1671
1690
  null
1672
1691
  );
1673
1692
  }
1674
1693
  } else {
1675
- if (this.i === 0 && this.f[0])
1676
- this.f[0].dispose();
1694
+ if (this.i === 0 && this.e[0])
1695
+ this.e[0].dispose();
1677
1696
  for (let i = this.i; i < newLen; i++) {
1678
- this.h[i] = compute(
1679
- this.f[i] = new Owner(),
1697
+ this.g[i] = compute(
1698
+ this.e[i] = new Owner(),
1680
1699
  () => this.G(i),
1681
1700
  null
1682
1701
  );
1683
1702
  }
1684
1703
  for (let i = newLen; i < this.i; i++)
1685
- this.f[i].dispose();
1686
- this.h = this.h.slice(0, newLen);
1704
+ this.e[i].dispose();
1705
+ this.g = this.g.slice(0, newLen);
1687
1706
  this.i = newLen;
1688
1707
  }
1689
1708
  });
1690
- return this.h;
1709
+ return this.g;
1691
1710
  }
1692
1711
  function compare(key, a, b) {
1693
1712
  return key ? key(a) === key(b) : true;