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