@solidjs/signals 0.7.3 → 0.7.5

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
@@ -2,6 +2,10 @@
2
2
 
3
3
  // src/core/error.ts
4
4
  var NotReadyError = class extends Error {
5
+ constructor(node) {
6
+ super();
7
+ this.cause = node;
8
+ }
5
9
  };
6
10
  var NoOwnerError = class extends Error {
7
11
  constructor() {
@@ -55,21 +59,21 @@ function notifyUnobserved() {
55
59
  for (let i = 0; i < Unobserved.length; i++) {
56
60
  const source = Unobserved[i];
57
61
  if (!source.c || !source.c.length)
58
- (_b = (_a = Unobserved[i]).ea) == null ? void 0 : _b.call(_a);
62
+ (_b = (_a = Unobserved[i]).fa) == null ? void 0 : _b.call(_a);
59
63
  }
60
64
  Unobserved = [];
61
65
  }
62
66
  var pureQueue = [];
63
67
  var Queue = class {
64
- k = null;
68
+ l = null;
65
69
  C = false;
66
- g = [[], []];
67
- h = [];
70
+ h = [[], []];
71
+ i = [];
68
72
  created = clock;
69
73
  enqueue(type, fn) {
70
74
  pureQueue.push(fn);
71
75
  if (type)
72
- this.g[type - 1].push(fn);
76
+ this.h[type - 1].push(fn);
73
77
  schedule();
74
78
  }
75
79
  run(type) {
@@ -77,13 +81,13 @@ var Queue = class {
77
81
  pureQueue.length && runQueue(pureQueue, type);
78
82
  pureQueue = [];
79
83
  return;
80
- } else if (this.g[type - 1].length) {
81
- const effects = this.g[type - 1];
82
- this.g[type - 1] = [];
84
+ } else if (this.h[type - 1].length) {
85
+ const effects = this.h[type - 1];
86
+ this.h[type - 1] = [];
83
87
  runQueue(effects, type);
84
88
  }
85
- for (let i = 0; i < this.h.length; i++) {
86
- this.h[i].run(type);
89
+ for (let i = 0; i < this.i.length; i++) {
90
+ this.i[i].run(type);
87
91
  }
88
92
  }
89
93
  flush() {
@@ -104,32 +108,32 @@ var Queue = class {
104
108
  addChild(child) {
105
109
  if (ActiveTransition && ActiveTransition.J.has(this))
106
110
  return ActiveTransition.J.get(this).addChild(child);
107
- this.h.push(child);
108
- child.k = this;
111
+ this.i.push(child);
112
+ child.l = this;
109
113
  }
110
114
  removeChild(child) {
111
115
  if (ActiveTransition && ActiveTransition.J.has(this))
112
116
  return ActiveTransition.J.get(this).removeChild(child);
113
- const index = this.h.indexOf(child);
117
+ const index = this.i.indexOf(child);
114
118
  if (index >= 0) {
115
- this.h.splice(index, 1);
116
- child.k = null;
119
+ this.i.splice(index, 1);
120
+ child.l = null;
117
121
  }
118
122
  }
119
123
  notify(...args) {
120
- if (this.k)
121
- return this.k.notify(...args);
124
+ if (this.l)
125
+ return this.l.notify(...args);
122
126
  return false;
123
127
  }
124
128
  merge(queue) {
125
- this.g[0].push.apply(this.g[0], queue.g[0]);
126
- this.g[1].push.apply(this.g[1], queue.g[1]);
127
- for (let i = 0; i < queue.h.length; i++) {
128
- const og = this.h.find((c) => c.d === queue.h[i].d);
129
+ this.h[0].push.apply(this.h[0], queue.h[0]);
130
+ this.h[1].push.apply(this.h[1], queue.h[1]);
131
+ for (let i = 0; i < queue.i.length; i++) {
132
+ const og = this.i.find((c) => c.d === queue.i[i].d);
129
133
  if (og)
130
- og.merge(queue.h[i]);
134
+ og.merge(queue.i[i]);
131
135
  else
132
- this.addChild(queue.h[i]);
136
+ this.addChild(queue.i[i]);
133
137
  }
134
138
  }
135
139
  };
@@ -142,8 +146,8 @@ function flush() {
142
146
  function removeSourceObservers(node, index) {
143
147
  let source;
144
148
  let swap;
145
- for (let i = index; i < node.a.length; i++) {
146
- source = getTransitionSource(node.a[i]);
149
+ for (let i = index; i < node.b.length; i++) {
150
+ source = getTransitionSource(node.b[i]);
147
151
  if (source.c) {
148
152
  if ((swap = source.c.indexOf(node)) !== -1) {
149
153
  source.c[swap] = source.c[source.c.length - 1];
@@ -159,30 +163,32 @@ function runQueue(queue, type) {
159
163
  queue[i](type);
160
164
  }
161
165
  var Transition = class _Transition {
162
- a = /* @__PURE__ */ new Map();
166
+ b = /* @__PURE__ */ new Map();
163
167
  t = /* @__PURE__ */ new Set();
164
168
  K = /* @__PURE__ */ new Set();
165
- m = /* @__PURE__ */ new Set();
169
+ j = /* @__PURE__ */ new Set();
166
170
  D = false;
167
- g = [[], []];
171
+ h = [[], []];
168
172
  J = /* @__PURE__ */ new Map();
169
173
  G = [];
170
- h = [];
171
- k = null;
174
+ i = [];
175
+ l = null;
172
176
  C = false;
173
177
  Y = false;
174
178
  d = globalQueue;
179
+ aa;
175
180
  created = clock;
176
- constructor() {
181
+ constructor(signal) {
182
+ this.aa = signal;
177
183
  this.J.set(globalQueue, this);
178
- for (const child of globalQueue.h) {
184
+ for (const child of globalQueue.i) {
179
185
  cloneQueue(child, this, this);
180
186
  }
181
187
  }
182
188
  enqueue(type, fn) {
183
189
  this.G.push(fn);
184
190
  if (type)
185
- this.g[type - 1].push(fn);
191
+ this.h[type - 1].push(fn);
186
192
  this.schedule();
187
193
  }
188
194
  run(type) {
@@ -190,18 +196,19 @@ var Transition = class _Transition {
190
196
  this.G.length && runQueue(this.G, type);
191
197
  this.G = [];
192
198
  return;
193
- } else if (this.g[type - 1].length) {
194
- const effects = this.g[type - 1];
195
- this.g[type - 1] = [];
199
+ } else if (this.h[type - 1].length) {
200
+ const effects = this.h[type - 1];
201
+ this.h[type - 1] = [];
196
202
  runQueue(effects, type);
197
203
  }
198
- for (let i = 0; i < this.h.length; i++) {
199
- this.h[i].run(type);
204
+ for (let i = 0; i < this.i.length; i++) {
205
+ this.i[i].run(type);
200
206
  }
201
207
  }
202
208
  flush() {
203
209
  if (this.C || this.D)
204
210
  return;
211
+ globalQueue.flush();
205
212
  this.C = true;
206
213
  let currentTransition = ActiveTransition;
207
214
  ActiveTransition = this;
@@ -217,13 +224,13 @@ var Transition = class _Transition {
217
224
  }
218
225
  }
219
226
  addChild(child) {
220
- this.h.push(child);
221
- child.k = this;
227
+ this.i.push(child);
228
+ child.l = this;
222
229
  }
223
230
  removeChild(child) {
224
- const index = this.h.indexOf(child);
231
+ const index = this.i.indexOf(child);
225
232
  if (index >= 0)
226
- this.h.splice(index, 1);
233
+ this.i.splice(index, 1);
227
234
  }
228
235
  notify(node, type, flags) {
229
236
  if (!(type & LOADING_BIT))
@@ -236,18 +243,18 @@ var Transition = class _Transition {
236
243
  return true;
237
244
  }
238
245
  merge(queue) {
239
- this.g[0].push.apply(this.g[0], queue.g[0]);
240
- this.g[1].push.apply(this.g[1], queue.g[1]);
246
+ this.h[0].push.apply(this.h[0], queue.h[0]);
247
+ this.h[1].push.apply(this.h[1], queue.h[1]);
241
248
  this.G.push.apply(this.G, queue.G);
242
- queue.g[0].length = 0;
243
- queue.g[1].length = 0;
249
+ queue.h[0].length = 0;
250
+ queue.h[1].length = 0;
244
251
  queue.G.length = 0;
245
- for (let i = 0; i < queue.h.length; i++) {
246
- const og = this.h.find((c) => c.d === queue.h[i].d);
252
+ for (let i = 0; i < queue.i.length; i++) {
253
+ const og = this.i.find((c) => c.d === queue.i[i].d);
247
254
  if (og)
248
- og.merge(queue.h[i]);
255
+ og.merge(queue.i[i]);
249
256
  else
250
- this.addChild(queue.h[i]);
257
+ this.addChild(queue.i[i]);
251
258
  }
252
259
  }
253
260
  schedule() {
@@ -307,45 +314,45 @@ var Transition = class _Transition {
307
314
  }
308
315
  }
309
316
  addOptimistic(fn) {
310
- if (fn.j && fn.j !== this) {
311
- mergeTransitions(fn.j, this);
312
- ActiveTransition = fn.j;
317
+ if (fn.f && fn.f !== this) {
318
+ mergeTransitions(fn.f, this);
319
+ ActiveTransition = fn.f;
313
320
  return;
314
321
  }
315
- fn.j = this;
316
- this.m.add(fn);
322
+ fn.f = this;
323
+ this.j.add(fn);
317
324
  }
318
325
  };
319
- function transition(fn) {
320
- let t = new Transition();
321
- queueMicrotask(() => t.runTransition(() => fn((fn2) => t.runTransition(fn2))));
322
- }
323
326
  function cloneGraph(node) {
324
- if (node.m) {
325
- ActiveTransition.addOptimistic(node.m);
327
+ var _a, _b;
328
+ if (node.j) {
329
+ if (node.a !== STATE_DISPOSED) {
330
+ !node.f && ((_b = (_a = node.j).ia) == null ? void 0 : _b.call(_a));
331
+ ActiveTransition.addOptimistic(node.j);
332
+ }
326
333
  return node;
327
334
  }
328
- if (node.j) {
329
- if (node.j !== ActiveTransition) {
330
- mergeTransitions(node.j, ActiveTransition);
331
- ActiveTransition = node.j;
335
+ if (node.f) {
336
+ if (node.f !== ActiveTransition) {
337
+ mergeTransitions(node.f, ActiveTransition);
338
+ ActiveTransition = node.f;
332
339
  }
333
- return node.j.a.get(node);
340
+ return node.f.b.get(node);
334
341
  }
335
342
  const clone = Object.create(Object.getPrototypeOf(node));
336
343
  Object.assign(clone, node, {
337
344
  o: null,
338
345
  n: null,
339
346
  c: null,
340
- a: node.a ? [...node.a] : null,
347
+ b: node.b ? [...node.b] : null,
341
348
  d: node
342
349
  });
343
350
  delete clone.T;
344
- ActiveTransition.a.set(node, clone);
345
- node.j = ActiveTransition;
346
- if (node.a) {
347
- for (let i = 0; i < node.a.length; i++)
348
- node.a[i].c.push(clone);
351
+ ActiveTransition.b.set(node, clone);
352
+ node.f = ActiveTransition;
353
+ if (node.b) {
354
+ for (let i = 0; i < node.b.length; i++)
355
+ node.b[i].c.push(clone);
349
356
  }
350
357
  if (node.c) {
351
358
  clone.c = [];
@@ -364,9 +371,9 @@ function replaceSourceObservers(node, transition2) {
364
371
  let source;
365
372
  let transitionSource;
366
373
  let swap;
367
- for (let i = 0; i < node.a.length; i++) {
368
- transitionSource = transition2.a.get(node.a[i]);
369
- source = transitionSource || node.a[i];
374
+ for (let i = 0; i < node.b.length; i++) {
375
+ transitionSource = transition2.b.get(node.b[i]);
376
+ source = transitionSource || node.b[i];
370
377
  if (source.c && (swap = source.c.indexOf(node)) !== -1) {
371
378
  source.c[swap] = transitionSource ? node.d : source.c[source.c.length - 1];
372
379
  !transitionSource && source.c.pop();
@@ -377,8 +384,8 @@ function cloneQueue(queue, parent, transition2) {
377
384
  const clone = Object.create(Object.getPrototypeOf(queue));
378
385
  Object.assign(clone, queue, {
379
386
  d: queue,
380
- k: parent,
381
- h: [],
387
+ l: parent,
388
+ i: [],
382
389
  enqueue(type, fn) {
383
390
  transition2 = latestTransition(transition2);
384
391
  transition2.enqueue(type, fn);
@@ -395,9 +402,9 @@ function cloneQueue(queue, parent, transition2) {
395
402
  return queue.notify.call(this, node, type, flags);
396
403
  }
397
404
  });
398
- parent.h.push(clone);
405
+ parent.i.push(clone);
399
406
  transition2.J.set(queue, clone);
400
- for (const child of queue.h) {
407
+ for (const child of queue.i) {
401
408
  cloneQueue(child, clone, transition2);
402
409
  }
403
410
  }
@@ -405,27 +412,27 @@ function resolveQueues(children) {
405
412
  for (const child of children) {
406
413
  const og = child.d;
407
414
  if (og) {
408
- const clonedChildren = child.h;
415
+ const clonedChildren = child.i;
409
416
  delete child.enqueue;
410
417
  delete child.notify;
411
- delete child.k;
412
- delete child.h;
418
+ delete child.l;
419
+ delete child.i;
413
420
  Object.assign(og, child);
414
421
  delete og.d;
415
422
  resolveQueues(clonedChildren);
416
- } else if (child.k.d) {
417
- child.k.d.addChild(child);
423
+ } else if (child.l.d) {
424
+ child.l.d.addChild(child);
418
425
  }
419
426
  }
420
427
  }
421
428
  function mergeTransitions(t1, t2) {
422
- t2.a.forEach((value, key) => {
423
- key.j = t1;
424
- t1.a.set(key, value);
429
+ t2.b.forEach((value, key) => {
430
+ key.f = t1;
431
+ t1.b.set(key, value);
425
432
  });
426
- t2.m.forEach((c) => {
427
- c.j = t1;
428
- t1.m.add(c);
433
+ t2.j.forEach((c) => {
434
+ c.f = t1;
435
+ t1.j.add(c);
429
436
  });
430
437
  t2.K.forEach((p) => t1.K.add(p));
431
438
  t2.t.forEach((n) => t1.t.add(n));
@@ -433,18 +440,18 @@ function mergeTransitions(t1, t2) {
433
440
  t2.D = t1;
434
441
  }
435
442
  function getTransitionSource(input) {
436
- return ActiveTransition && ActiveTransition.a.get(input) || input;
443
+ return ActiveTransition && ActiveTransition.b.get(input) || input;
437
444
  }
438
445
  function getQueue(node) {
439
446
  var _a;
440
- const transition2 = ActiveTransition || ((_a = node.d) == null ? void 0 : _a.j);
447
+ const transition2 = ActiveTransition || ((_a = node.d) == null ? void 0 : _a.f);
441
448
  return transition2 && transition2.J.get(node.E) || node.E;
442
449
  }
443
450
  function initialDispose(node) {
444
451
  let current = node.n;
445
- while (current !== null && current.k === node) {
452
+ while (current !== null && current.l === node) {
446
453
  initialDispose(current);
447
- const clone = ActiveTransition.a.get(current);
454
+ const clone = ActiveTransition.b.get(current);
448
455
  if (clone && !clone.Z)
449
456
  clone.dispose(true);
450
457
  current = current.n;
@@ -453,18 +460,18 @@ function initialDispose(node) {
453
460
  function finishTransition(transition2) {
454
461
  if (transition2.D || transition2.Y || transition2.K.size || transition2.t.size)
455
462
  return;
456
- globalQueue.g[0].push.apply(globalQueue.g[0], transition2.g[0]);
457
- globalQueue.g[1].push.apply(globalQueue.g[1], transition2.g[1]);
458
- resolveQueues(transition2.h);
459
- for (const [source, clone] of transition2.a) {
460
- if (source === clone || source.j !== transition2) {
461
- delete source.j;
463
+ globalQueue.h[0].push.apply(globalQueue.h[0], transition2.h[0]);
464
+ globalQueue.h[1].push.apply(globalQueue.h[1], transition2.h[1]);
465
+ resolveQueues(transition2.i);
466
+ for (const [source, clone] of transition2.b) {
467
+ if (source === clone || source.f !== transition2) {
468
+ delete source.f;
462
469
  continue;
463
470
  }
464
- if (clone.a)
471
+ if (clone.b)
465
472
  replaceSourceObservers(clone, transition2);
466
- if (clone.Z || clone.b === STATE_DISPOSED) {
467
- source.dispose(clone.b === STATE_DISPOSED);
473
+ if (clone.Z || clone.a === STATE_DISPOSED) {
474
+ source.dispose(clone.a === STATE_DISPOSED);
468
475
  source.emptyDisposal();
469
476
  delete clone.Z;
470
477
  } else {
@@ -476,17 +483,18 @@ function finishTransition(transition2) {
476
483
  let current = clone.n;
477
484
  if ((current == null ? void 0 : current.z) === clone)
478
485
  current.z = source;
479
- while ((current == null ? void 0 : current.k) === clone) {
480
- current.k = source;
486
+ while ((current == null ? void 0 : current.l) === clone) {
487
+ current.l = source;
481
488
  current = current.n;
482
489
  }
483
- delete source.j;
490
+ delete source.f;
484
491
  }
485
492
  transition2.D = true;
486
- for (const reset of transition2.m) {
487
- delete reset.j;
493
+ for (const reset of transition2.j) {
494
+ delete reset.f;
488
495
  reset();
489
496
  }
497
+ transition2.aa.write(true);
490
498
  globalQueue.flush();
491
499
  }
492
500
 
@@ -505,14 +513,14 @@ var Owner = class {
505
513
  // We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
506
514
  // However, the children are actually added in reverse creation order
507
515
  // See comment at the top of the file for an example of the _nextSibling traversal
508
- k = null;
516
+ l = null;
509
517
  n = null;
510
518
  z = null;
511
- b = STATE_CLEAN;
519
+ a = STATE_CLEAN;
512
520
  o = null;
513
521
  A = defaultContext;
514
522
  E = globalQueue;
515
- fa = 0;
523
+ ga = 0;
516
524
  id = null;
517
525
  constructor(id = null, skipAppend = false) {
518
526
  this.id = id;
@@ -521,7 +529,7 @@ var Owner = class {
521
529
  }
522
530
  }
523
531
  append(child) {
524
- child.k = this;
532
+ child.l = this;
525
533
  child.z = this;
526
534
  if (this.n)
527
535
  this.n.z = child;
@@ -536,16 +544,16 @@ var Owner = class {
536
544
  child.E = this.E;
537
545
  }
538
546
  dispose(self = true) {
539
- if (this.b === STATE_DISPOSED)
547
+ if (this.a === STATE_DISPOSED)
540
548
  return;
541
- let head = self ? this.z || this.k : this, current = this.n, next = null;
542
- while (current && current.k === this) {
549
+ let head = self ? this.z || this.l : this, current = this.n, next = null;
550
+ while (current && current.l === this) {
543
551
  current.dispose(true);
544
552
  next = current.n;
545
553
  current.n = null;
546
554
  current = next;
547
555
  }
548
- this.fa = 0;
556
+ this.ga = 0;
549
557
  if (self)
550
558
  this.M();
551
559
  if (current)
@@ -556,10 +564,10 @@ var Owner = class {
556
564
  M() {
557
565
  if (this.z)
558
566
  this.z.n = null;
559
- this.k = null;
567
+ this.l = null;
560
568
  this.z = null;
561
569
  this.A = defaultContext;
562
- this.b = STATE_DISPOSED;
570
+ this.a = STATE_DISPOSED;
563
571
  this.emptyDisposal();
564
572
  }
565
573
  emptyDisposal() {
@@ -577,7 +585,7 @@ var Owner = class {
577
585
  }
578
586
  getNextChildId() {
579
587
  if (this.id != null)
580
- return formatId(this.id, this.fa++);
588
+ return formatId(this.id, this.ga++);
581
589
  throw new Error("Cannot get child id from owner without an id");
582
590
  }
583
591
  };
@@ -641,49 +649,54 @@ function getObserver() {
641
649
  }
642
650
  var UNCHANGED = Symbol(0);
643
651
  var Computation = class extends Owner {
644
- a = null;
652
+ b = null;
645
653
  c = null;
646
- l;
654
+ m;
647
655
  O;
648
656
  P;
649
657
  // Used in __DEV__ mode, hopefully removed in production
650
- la;
658
+ na;
651
659
  // Using false is an optimization as an alternative to _equals: () => false
652
660
  // which could enable more efficient DIRTY notification
653
- aa = isEqual;
654
- ea;
655
- ha = false;
661
+ ba = isEqual;
662
+ fa;
663
+ ja = false;
656
664
  /** Whether the computation is an error or has ancestors that are unresolved */
657
- f = 0;
665
+ g = 0;
658
666
  /** Which flags raised by sources are handled, vs. being passed through. */
659
- ba = DEFAULT_FLAGS;
667
+ ca = DEFAULT_FLAGS;
660
668
  Q = -1;
661
669
  H = false;
662
- j;
670
+ f;
663
671
  d;
664
- m;
672
+ j;
665
673
  constructor(initialValue, compute2, options) {
666
674
  super(options == null ? void 0 : options.id, compute2 === null);
667
675
  this.P = compute2;
668
- this.b = compute2 ? STATE_DIRTY : STATE_CLEAN;
669
- this.f = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
670
- this.l = initialValue;
676
+ this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
677
+ this.g = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
678
+ this.m = initialValue;
671
679
  if ((options == null ? void 0 : options.equals) !== void 0)
672
- this.aa = options.equals;
673
- this.ha = !!(options == null ? void 0 : options.pureWrite);
674
- this.ea = options == null ? void 0 : options.unobserved;
680
+ this.ba = options.equals;
681
+ this.ja = !!(options == null ? void 0 : options.pureWrite);
682
+ this.fa = options == null ? void 0 : options.unobserved;
675
683
  if (ActiveTransition) {
676
- this.j = ActiveTransition;
677
- ActiveTransition.a.set(this, this);
684
+ this.f = ActiveTransition;
685
+ ActiveTransition.b.set(this, this);
678
686
  }
679
687
  }
680
- ga() {
688
+ ha() {
689
+ var _a;
690
+ if (staleCheck && (this.g & LOADING_BIT || this.f)) {
691
+ staleCheck.m = true;
692
+ (_a = this.f) == null ? void 0 : _a.aa.read();
693
+ }
681
694
  track(this);
682
- newFlags |= this.f & ~currentMask;
683
- if (this.f & ERROR_BIT) {
695
+ newFlags |= this.g & ~currentMask;
696
+ if (this.g & ERROR_BIT) {
684
697
  throw this.O;
685
698
  } else {
686
- return this.l;
699
+ return this.m;
687
700
  }
688
701
  }
689
702
  /**
@@ -691,18 +704,18 @@ var Computation = class extends Owner {
691
704
  * Automatically re-executes the surrounding computation when the value changes
692
705
  */
693
706
  read() {
694
- if (ActiveTransition && (ActiveTransition.a.has(this) || !this.d && this.f & (UNINITIALIZED_BIT | ERROR_BIT))) {
695
- const clone = ActiveTransition.a.get(this) || cloneGraph(this);
707
+ if (ActiveTransition && (ActiveTransition.b.has(this) || !this.d && this.g & (UNINITIALIZED_BIT | ERROR_BIT))) {
708
+ const clone = ActiveTransition.b.get(this) || cloneGraph(this);
696
709
  if (clone !== this)
697
710
  return clone.read();
698
711
  }
699
712
  if (this.P) {
700
- if (this.f & ERROR_BIT && this.Q <= clock)
713
+ if (this.g & ERROR_BIT && this.Q <= clock)
701
714
  update(this);
702
715
  else
703
716
  this.F();
704
717
  }
705
- return this.ga();
718
+ return this.ha();
706
719
  }
707
720
  /**
708
721
  * Return the current value of this computation
@@ -712,25 +725,21 @@ var Computation = class extends Owner {
712
725
  * before continuing
713
726
  */
714
727
  wait() {
715
- if (ActiveTransition && (ActiveTransition.a.has(this) || !this.d && this.f & (UNINITIALIZED_BIT | ERROR_BIT))) {
716
- const clone = ActiveTransition.a.get(this) || cloneGraph(this);
728
+ if (ActiveTransition && (ActiveTransition.b.has(this) || !this.d && this.g & (UNINITIALIZED_BIT | ERROR_BIT))) {
729
+ const clone = ActiveTransition.b.get(this) || cloneGraph(this);
717
730
  if (clone !== this)
718
731
  return clone.wait();
719
732
  }
720
733
  if (this.P) {
721
- if (this.f & ERROR_BIT && this.Q <= clock)
734
+ if (this.g & ERROR_BIT && this.Q <= clock)
722
735
  update(this);
723
736
  else
724
737
  this.F();
725
738
  }
726
- if ((notStale || this.f & UNINITIALIZED_BIT) && this.f & LOADING_BIT) {
727
- track(this);
728
- throw new NotReadyError();
739
+ if ((notStale || this.g & UNINITIALIZED_BIT) && this.g & LOADING_BIT) {
740
+ throw new NotReadyError(this);
729
741
  }
730
- if (staleCheck && this.f & LOADING_BIT) {
731
- staleCheck.l = true;
732
- }
733
- return this.ga();
742
+ return this.ha();
734
743
  }
735
744
  /** Update the computation with a new value. */
736
745
  write(value, flags = 0, raw = false) {
@@ -739,17 +748,17 @@ var Computation = class extends Owner {
739
748
  if (clone !== this)
740
749
  return clone.write(value, flags, raw);
741
750
  }
742
- const newValue = !raw && typeof value === "function" ? value(this.l) : value;
743
- const valueChanged = newValue !== UNCHANGED && (!!(this.f & UNINITIALIZED_BIT) || // this._stateFlags & LOADING_BIT & ~flags ||
744
- this.aa === false || !this.aa(this.l, newValue));
751
+ const newValue = !raw && typeof value === "function" ? value(this.m) : value;
752
+ const valueChanged = newValue !== UNCHANGED && (!!(this.g & UNINITIALIZED_BIT) || // this._stateFlags & LOADING_BIT & ~flags ||
753
+ this.ba === false || !this.ba(this.m, newValue));
745
754
  if (valueChanged) {
746
- this.l = newValue;
755
+ this.m = newValue;
747
756
  this.O = void 0;
748
757
  }
749
- const changedFlagsMask = this.f ^ flags, changedFlags = changedFlagsMask & flags;
750
- this.f = flags;
758
+ const changedFlagsMask = this.g ^ flags, changedFlags = changedFlagsMask & flags;
759
+ this.g = flags;
751
760
  this.Q = clock + 1;
752
- if (this.c && !(this.m && ActiveTransition)) {
761
+ if (this.c && !(this.j && ActiveTransition)) {
753
762
  for (let i = 0; i < this.c.length; i++) {
754
763
  if (valueChanged) {
755
764
  this.c[i].u(STATE_DIRTY);
@@ -758,17 +767,17 @@ var Computation = class extends Owner {
758
767
  }
759
768
  }
760
769
  }
761
- return this.l;
770
+ return this.m;
762
771
  }
763
772
  /**
764
773
  * Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
765
774
  */
766
775
  u(state, skipQueue) {
767
- if (this.b >= state && !this.H)
776
+ if (this.a >= state && !this.H)
768
777
  return;
769
778
  this.H = !!skipQueue;
770
- this.b = state;
771
- if (this.c && !(this.m && ActiveTransition)) {
779
+ this.a = state;
780
+ if (this.c && !(this.j && ActiveTransition)) {
772
781
  for (let i = 0; i < this.c.length; i++) {
773
782
  this.c[i].u(STATE_CHECK, skipQueue);
774
783
  }
@@ -781,20 +790,20 @@ var Computation = class extends Owner {
781
790
  * @param newFlags The source's new flags, masked to just the changed ones.
782
791
  */
783
792
  _(mask, newFlags2) {
784
- if (this.b >= STATE_DIRTY)
793
+ if (this.a >= STATE_DIRTY)
785
794
  return;
786
- if (mask & this.ba || this.m && ActiveTransition) {
795
+ if (mask & this.ca || this.j && ActiveTransition) {
787
796
  this.u(STATE_DIRTY);
788
797
  return;
789
798
  }
790
- if (this.b >= STATE_CHECK && !this.H)
799
+ if (this.a >= STATE_CHECK && !this.H)
791
800
  return;
792
- const prevFlags = this.f & mask;
801
+ const prevFlags = this.g & mask;
793
802
  const deltaFlags = prevFlags ^ newFlags2;
794
803
  if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
795
804
  this.u(STATE_CHECK);
796
805
  } else {
797
- this.f ^= deltaFlags;
806
+ this.g ^= deltaFlags;
798
807
  if (this.c) {
799
808
  for (let i = 0; i < this.c.length; i++) {
800
809
  this.c[i]._(mask, newFlags2);
@@ -809,7 +818,7 @@ var Computation = class extends Owner {
809
818
  return clone.N(error);
810
819
  }
811
820
  this.O = error;
812
- this.write(UNCHANGED, this.f & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
821
+ this.write(UNCHANGED, this.g & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
813
822
  }
814
823
  /**
815
824
  * This is the core part of the reactivity system, which makes sure that the values are updated
@@ -822,37 +831,37 @@ var Computation = class extends Owner {
822
831
  if (!this.P) {
823
832
  return;
824
833
  }
825
- if (this.b === STATE_DISPOSED) {
834
+ if (this.a === STATE_DISPOSED) {
826
835
  return;
827
836
  }
828
- if (this.b === STATE_CLEAN) {
837
+ if (this.a === STATE_CLEAN) {
829
838
  return;
830
839
  }
831
840
  let observerFlags = 0;
832
- if (this.b === STATE_CHECK) {
833
- for (let i = 0; i < this.a.length; i++) {
834
- const source = getTransitionSource(this.a[i]);
841
+ if (this.a === STATE_CHECK) {
842
+ for (let i = 0; i < this.b.length; i++) {
843
+ const source = getTransitionSource(this.b[i]);
835
844
  source.F();
836
- observerFlags |= source.f & ~UNINITIALIZED_BIT;
837
- if (this.b === STATE_DIRTY) {
845
+ observerFlags |= source.g & ~UNINITIALIZED_BIT;
846
+ if (this.a === STATE_DIRTY) {
838
847
  break;
839
848
  }
840
849
  }
841
850
  }
842
- if (this.b === STATE_DIRTY) {
851
+ if (this.a === STATE_DIRTY) {
843
852
  update(this);
844
853
  } else {
845
854
  this.write(UNCHANGED, observerFlags);
846
- this.b = STATE_CLEAN;
855
+ this.a = STATE_CLEAN;
847
856
  }
848
857
  }
849
858
  /**
850
859
  * Remove ourselves from the owner graph and the computation graph
851
860
  */
852
861
  M() {
853
- if (this.b === STATE_DISPOSED)
862
+ if (this.a === STATE_DISPOSED)
854
863
  return;
855
- if (this.a)
864
+ if (this.b)
856
865
  removeSourceObservers(this, 0);
857
866
  super.M();
858
867
  }
@@ -861,7 +870,7 @@ function track(computation) {
861
870
  if (ActiveTransition && computation.d)
862
871
  computation = computation.d;
863
872
  if (currentObserver) {
864
- if (!newSources && currentObserver.a && currentObserver.a[newSourcesIndex] === computation) {
873
+ if (!newSources && currentObserver.b && currentObserver.b[newSourcesIndex] === computation) {
865
874
  newSourcesIndex++;
866
875
  } else if (!newSources)
867
876
  newSources = [computation];
@@ -869,7 +878,7 @@ function track(computation) {
869
878
  newSources.push(computation);
870
879
  }
871
880
  if (updateCheck) {
872
- updateCheck.l = computation.Q > currentObserver.Q;
881
+ updateCheck.m = computation.Q > currentObserver.Q;
873
882
  }
874
883
  }
875
884
  }
@@ -889,39 +898,45 @@ function update(node) {
889
898
  node.write(result, newFlags, true);
890
899
  } catch (error) {
891
900
  if (error instanceof NotReadyError) {
892
- node.write(UNCHANGED, newFlags | LOADING_BIT | node.f & UNINITIALIZED_BIT);
901
+ if (error.cause !== node)
902
+ compute(
903
+ node,
904
+ () => track(error.cause),
905
+ node
906
+ );
907
+ node.write(UNCHANGED, newFlags | LOADING_BIT | node.g & UNINITIALIZED_BIT);
893
908
  } else {
894
909
  node.N(error);
895
910
  }
896
911
  } finally {
897
912
  if (newSources) {
898
- if (node.a)
913
+ if (node.b)
899
914
  removeSourceObservers(node, newSourcesIndex);
900
- if (node.a && newSourcesIndex > 0) {
901
- node.a.length = newSourcesIndex + newSources.length;
915
+ if (node.b && newSourcesIndex > 0) {
916
+ node.b.length = newSourcesIndex + newSources.length;
902
917
  for (let i = 0; i < newSources.length; i++) {
903
- node.a[newSourcesIndex + i] = newSources[i];
918
+ node.b[newSourcesIndex + i] = newSources[i];
904
919
  }
905
920
  } else {
906
- node.a = newSources;
921
+ node.b = newSources;
907
922
  }
908
923
  let source;
909
- for (let i = newSourcesIndex; i < node.a.length; i++) {
910
- source = getTransitionSource(node.a[i]);
924
+ for (let i = newSourcesIndex; i < node.b.length; i++) {
925
+ source = getTransitionSource(node.b[i]);
911
926
  if (!source.c)
912
927
  source.c = [node];
913
928
  else
914
929
  source.c.push(node);
915
930
  }
916
- } else if (node.a && newSourcesIndex < node.a.length) {
931
+ } else if (node.b && newSourcesIndex < node.b.length) {
917
932
  removeSourceObservers(node, newSourcesIndex);
918
- node.a.length = newSourcesIndex;
933
+ node.b.length = newSourcesIndex;
919
934
  }
920
935
  newSources = prevSources;
921
936
  newSourcesIndex = prevSourcesIndex;
922
937
  newFlags = prevFlags;
923
938
  node.Q = clock + 1;
924
- node.b = STATE_CLEAN;
939
+ node.a = STATE_CLEAN;
925
940
  }
926
941
  }
927
942
  function isEqual(a, b) {
@@ -934,20 +949,20 @@ function untrack(fn) {
934
949
  }
935
950
  function hasUpdated(fn) {
936
951
  const current = updateCheck;
937
- updateCheck = { l: false };
952
+ updateCheck = { m: false };
938
953
  try {
939
954
  fn();
940
- return updateCheck.l;
955
+ return updateCheck.m;
941
956
  } finally {
942
957
  updateCheck = current;
943
958
  }
944
959
  }
945
960
  function pendingCheck(fn, loadingValue) {
946
961
  const current = staleCheck;
947
- staleCheck = { l: false };
962
+ staleCheck = { m: false };
948
963
  try {
949
964
  latest(fn);
950
- return staleCheck.l;
965
+ return staleCheck.m;
951
966
  } catch (err) {
952
967
  if (!(err instanceof NotReadyError))
953
968
  return false;
@@ -962,8 +977,17 @@ function isPending(fn, loadingValue) {
962
977
  if (!currentObserver)
963
978
  return pendingCheck(fn, loadingValue);
964
979
  const c = new Computation(void 0, () => pendingCheck(fn, loadingValue));
965
- c.ba |= LOADING_BIT;
966
- return c.wait();
980
+ c.j = () => c.write(false);
981
+ c.j.ia = () => globalQueue.enqueue(0, () => c.j.f && c.write(true));
982
+ c.ca |= LOADING_BIT;
983
+ const res = c.wait();
984
+ c.o = () => {
985
+ if (c.j.f) {
986
+ c.j.f.j.delete(c.j);
987
+ delete c.j.f;
988
+ }
989
+ };
990
+ return res;
967
991
  }
968
992
  function latest(fn, fallback) {
969
993
  const argLength = arguments.length;
@@ -984,10 +1008,10 @@ function latest(fn, fallback) {
984
1008
  function compute(owner, fn, observer) {
985
1009
  const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask, prevNotStale = notStale;
986
1010
  currentObserver = observer;
987
- currentMask = (observer == null ? void 0 : observer.ba) ?? DEFAULT_FLAGS;
1011
+ currentMask = (observer == null ? void 0 : observer.ca) ?? DEFAULT_FLAGS;
988
1012
  notStale = true;
989
1013
  try {
990
- return fn.call(observer, observer ? observer.l : void 0);
1014
+ return fn.call(observer, observer ? observer.m : void 0);
991
1015
  } finally {
992
1016
  setOwner(prevOwner);
993
1017
  currentObserver = prevObserver;
@@ -998,50 +1022,50 @@ function compute(owner, fn, observer) {
998
1022
 
999
1023
  // src/core/effect.ts
1000
1024
  var Effect = class extends Computation {
1001
- ca;
1025
+ da;
1002
1026
  $;
1003
1027
  w;
1004
- da = false;
1028
+ ea = false;
1005
1029
  T;
1006
1030
  s;
1007
1031
  constructor(initialValue, compute2, effect, error, options) {
1008
1032
  super(initialValue, compute2, options);
1009
- this.ca = effect;
1033
+ this.da = effect;
1010
1034
  this.$ = error;
1011
1035
  this.T = initialValue;
1012
1036
  this.s = (options == null ? void 0 : options.render) ? EFFECT_RENDER : EFFECT_USER;
1013
1037
  if (this.s === EFFECT_RENDER) {
1014
1038
  this.P = function(p) {
1015
- return !this.d && clock > this.E.created && !(this.f & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
1039
+ return !this.d && clock > this.E.created && !(this.g & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
1016
1040
  };
1017
1041
  }
1018
1042
  this.F();
1019
1043
  !(options == null ? void 0 : options.defer) && (this.s === EFFECT_USER ? getQueue(this).enqueue(this.s, this.x.bind(this)) : this.x(this.s));
1020
1044
  }
1021
1045
  write(value, flags = 0) {
1022
- if (this.b == STATE_DIRTY) {
1023
- this.f = flags;
1046
+ if (this.a == STATE_DIRTY) {
1047
+ this.g = flags;
1024
1048
  if (this.s === EFFECT_RENDER) {
1025
- getQueue(this).notify(this, LOADING_BIT | ERROR_BIT, this.f);
1049
+ getQueue(this).notify(this, LOADING_BIT | ERROR_BIT, this.g);
1026
1050
  }
1027
1051
  }
1028
1052
  if (value === UNCHANGED)
1029
- return this.l;
1030
- this.l = value;
1031
- this.da = true;
1053
+ return this.m;
1054
+ this.m = value;
1055
+ this.ea = true;
1032
1056
  this.O = void 0;
1033
1057
  return value;
1034
1058
  }
1035
1059
  u(state, skipQueue) {
1036
- if (this.b >= state || skipQueue)
1060
+ if (this.a >= state || skipQueue)
1037
1061
  return;
1038
- if (this.b === STATE_CLEAN || this.d && !ActiveTransition)
1062
+ if (this.a === STATE_CLEAN || this.d && !ActiveTransition)
1039
1063
  getQueue(this).enqueue(this.s, this.x.bind(this));
1040
- this.b = state;
1064
+ this.a = state;
1041
1065
  }
1042
1066
  _(mask, newFlags2) {
1043
1067
  if (this.d) {
1044
- if (this.b >= STATE_DIRTY)
1068
+ if (this.a >= STATE_DIRTY)
1045
1069
  return;
1046
1070
  if (mask & 3) {
1047
1071
  this.u(STATE_DIRTY);
@@ -1053,7 +1077,7 @@ var Effect = class extends Computation {
1053
1077
  N(error) {
1054
1078
  this.O = error;
1055
1079
  getQueue(this).notify(this, LOADING_BIT, 0);
1056
- this.f = ERROR_BIT;
1080
+ this.g = ERROR_BIT;
1057
1081
  if (this.s === EFFECT_USER) {
1058
1082
  try {
1059
1083
  return this.$ ? this.$(error, () => {
@@ -1070,9 +1094,9 @@ var Effect = class extends Computation {
1070
1094
  }
1071
1095
  M() {
1072
1096
  var _a;
1073
- if (this.b === STATE_DISPOSED)
1097
+ if (this.a === STATE_DISPOSED)
1074
1098
  return;
1075
- this.ca = void 0;
1099
+ this.da = void 0;
1076
1100
  this.T = void 0;
1077
1101
  this.$ = void 0;
1078
1102
  (_a = this.w) == null ? void 0 : _a.call(this);
@@ -1084,44 +1108,48 @@ var Effect = class extends Computation {
1084
1108
  var _a;
1085
1109
  if (type) {
1086
1110
  const effect = this.d || this;
1087
- if (effect.da && effect.b !== STATE_DISPOSED) {
1111
+ if (effect.ea && effect.a !== STATE_DISPOSED) {
1088
1112
  (_a = effect.w) == null ? void 0 : _a.call(effect);
1089
1113
  try {
1090
- effect.w = effect.ca(effect.l, effect.T);
1114
+ effect.w = effect.da(effect.m, effect.T);
1091
1115
  } catch (e) {
1092
1116
  if (!getQueue(effect).notify(effect, ERROR_BIT, ERROR_BIT))
1093
1117
  throw e;
1094
1118
  } finally {
1095
- effect.T = effect.l;
1096
- effect.da = false;
1119
+ effect.T = effect.m;
1120
+ effect.ea = false;
1097
1121
  }
1098
1122
  }
1099
1123
  } else
1100
- this.b !== STATE_CLEAN && runTop(this);
1124
+ this.a !== STATE_CLEAN && runTop(this);
1101
1125
  }
1102
1126
  };
1103
1127
  var TrackedEffect = class extends Computation {
1104
1128
  s = EFFECT_USER;
1105
1129
  w;
1106
1130
  constructor(compute2, options) {
1107
- super(void 0, () => {
1108
- var _a;
1109
- (_a = this.w) == null ? void 0 : _a.call(this);
1110
- this.w = latest(compute2);
1111
- return void 0;
1112
- }, options);
1131
+ super(
1132
+ void 0,
1133
+ () => {
1134
+ var _a;
1135
+ (_a = this.w) == null ? void 0 : _a.call(this);
1136
+ this.w = latest(compute2);
1137
+ return void 0;
1138
+ },
1139
+ options
1140
+ );
1113
1141
  getQueue(this).enqueue(this.s, this.x.bind(this));
1114
1142
  }
1115
1143
  u(state, skipQueue) {
1116
- if (this.b >= state || skipQueue)
1144
+ if (this.a >= state || skipQueue)
1117
1145
  return;
1118
- if (this.b === STATE_CLEAN || this.d && !ActiveTransition)
1146
+ if (this.a === STATE_CLEAN || this.d && !ActiveTransition)
1119
1147
  getQueue(this).enqueue(this.s, this.x.bind(this));
1120
- this.b = state;
1148
+ this.a = state;
1121
1149
  }
1122
1150
  M() {
1123
1151
  var _a;
1124
- if (this.b === STATE_DISPOSED)
1152
+ if (this.a === STATE_DISPOSED)
1125
1153
  return;
1126
1154
  (_a = this.w) == null ? void 0 : _a.call(this);
1127
1155
  this.w = void 0;
@@ -1130,7 +1158,7 @@ var TrackedEffect = class extends Computation {
1130
1158
  }
1131
1159
  x(type) {
1132
1160
  if (type)
1133
- this.b !== STATE_CLEAN && runTop(this);
1161
+ this.a !== STATE_CLEAN && runTop(this);
1134
1162
  }
1135
1163
  };
1136
1164
  var EagerComputation = class extends Computation {
@@ -1139,14 +1167,14 @@ var EagerComputation = class extends Computation {
1139
1167
  !(options == null ? void 0 : options.defer) && this.F();
1140
1168
  }
1141
1169
  u(state, skipQueue) {
1142
- if (this.b >= state && !this.H)
1170
+ if (this.a >= state && !this.H)
1143
1171
  return;
1144
- if (!skipQueue && (this.b === STATE_CLEAN || this.b === STATE_CHECK && this.H))
1172
+ if (!skipQueue && (this.a === STATE_CLEAN || this.a === STATE_CHECK && this.H))
1145
1173
  getQueue(this).enqueue(EFFECT_PURE, this.x.bind(this));
1146
1174
  super.u(state, skipQueue);
1147
1175
  }
1148
1176
  x() {
1149
- this.b !== STATE_CLEAN && runTop(this);
1177
+ this.a !== STATE_CLEAN && runTop(this);
1150
1178
  }
1151
1179
  };
1152
1180
  var FirewallComputation = class extends Computation {
@@ -1155,34 +1183,34 @@ var FirewallComputation = class extends Computation {
1155
1183
  super(void 0, compute2);
1156
1184
  }
1157
1185
  u(state, skipQueue) {
1158
- if (this.b >= state && !this.H)
1186
+ if (this.a >= state && !this.H)
1159
1187
  return;
1160
- if (!skipQueue && (this.b === STATE_CLEAN || this.b === STATE_CHECK && this.H))
1188
+ if (!skipQueue && (this.a === STATE_CLEAN || this.a === STATE_CHECK && this.H))
1161
1189
  getQueue(this).enqueue(EFFECT_PURE, this.x.bind(this));
1162
1190
  super.u(state, true);
1163
1191
  this.H = !!skipQueue;
1164
1192
  }
1165
1193
  x() {
1166
- const prevFlags = this.f;
1167
- this.b !== STATE_CLEAN && runTop(this);
1168
- if (ActiveTransition && this.m && (this.f !== prevFlags || this.f !== this.m.flags)) {
1169
- getQueue(this).notify(this, LOADING_BIT | ERROR_BIT, this.f);
1170
- this.m.flags = this.f;
1171
- this.f = prevFlags;
1194
+ const prevFlags = this.g;
1195
+ this.a !== STATE_CLEAN && runTop(this);
1196
+ if (ActiveTransition && this.j && (this.g !== prevFlags || this.g !== this.j.flags)) {
1197
+ getQueue(this).notify(this, LOADING_BIT | ERROR_BIT, this.g);
1198
+ this.j.flags = this.g;
1199
+ this.g = prevFlags;
1172
1200
  }
1173
1201
  }
1174
1202
  };
1175
1203
  function runTop(node) {
1176
1204
  const ancestors = [];
1177
- for (let current = node; current !== null; current = current.k) {
1178
- if (ActiveTransition && current.j)
1179
- current = ActiveTransition.a.get(current);
1180
- if (current.b !== STATE_CLEAN) {
1205
+ for (let current = node; current !== null; current = current.l) {
1206
+ if (ActiveTransition && current.f)
1207
+ current = ActiveTransition.b.get(current);
1208
+ if (current.a !== STATE_CLEAN) {
1181
1209
  ancestors.push(current);
1182
1210
  }
1183
1211
  }
1184
1212
  for (let i = ancestors.length - 1; i >= 0; i--) {
1185
- if (ancestors[i].b !== STATE_DISPOSED)
1213
+ if (ancestors[i].a !== STATE_DISPOSED)
1186
1214
  ancestors[i].F();
1187
1215
  }
1188
1216
  }
@@ -1191,10 +1219,13 @@ function runTop(node) {
1191
1219
  function createSignal(first, second, third) {
1192
1220
  if (typeof first === "function") {
1193
1221
  const node2 = new Computation(second, first, third);
1194
- return [node2.read.bind(node2), (v) => {
1195
- node2.F();
1196
- return node2.write(v);
1197
- }];
1222
+ return [
1223
+ node2.wait.bind(node2),
1224
+ (v) => {
1225
+ node2.F();
1226
+ return node2.write(v);
1227
+ }
1228
+ ];
1198
1229
  }
1199
1230
  const o = getOwner();
1200
1231
  const needsId = (o == null ? void 0 : o.id) != null;
@@ -1215,12 +1246,12 @@ function createMemo(compute2, value, options) {
1215
1246
  return () => {
1216
1247
  var _a, _b;
1217
1248
  if (node) {
1218
- if (node.b === STATE_DISPOSED) {
1249
+ if (node.a === STATE_DISPOSED) {
1219
1250
  node = void 0;
1220
1251
  return resolvedValue;
1221
1252
  }
1222
1253
  resolvedValue = node.wait();
1223
- if (!((_a = node.a) == null ? void 0 : _a.length) && ((_b = node.n) == null ? void 0 : _b.k) !== node && !(node.f & UNINITIALIZED_BIT)) {
1254
+ if (!((_a = node.b) == null ? void 0 : _a.length) && ((_b = node.n) == null ? void 0 : _b.l) !== node && !(node.g & UNINITIALIZED_BIT)) {
1224
1255
  node.dispose();
1225
1256
  node = void 0;
1226
1257
  }
@@ -1287,7 +1318,7 @@ function createAsync(compute2, value, options) {
1287
1318
  }
1288
1319
  })();
1289
1320
  }
1290
- throw new NotReadyError();
1321
+ throw new NotReadyError(getOwner());
1291
1322
  },
1292
1323
  options
1293
1324
  );
@@ -1297,7 +1328,7 @@ function createAsync(compute2, value, options) {
1297
1328
  if (ActiveTransition && !node.d) {
1298
1329
  n = cloneGraph(node);
1299
1330
  }
1300
- n.b = STATE_DIRTY;
1331
+ n.a = STATE_DIRTY;
1301
1332
  refreshing = true;
1302
1333
  n.F();
1303
1334
  };
@@ -1366,25 +1397,34 @@ function resolve(fn) {
1366
1397
  });
1367
1398
  }
1368
1399
  function createOptimistic(first, second, third) {
1369
- const node = typeof first === "function" ? new Computation(second, (prev) => {
1370
- const res = first(prev);
1371
- if (node.m.j)
1372
- return prev;
1373
- return res;
1374
- }, third) : new Computation(first, null, second);
1375
- node.m = () => node.write(first);
1400
+ const node = typeof first === "function" ? new Computation(
1401
+ second,
1402
+ (prev) => {
1403
+ if (node.j.f) {
1404
+ latest(() => first(prev));
1405
+ return prev;
1406
+ }
1407
+ return first(prev);
1408
+ },
1409
+ third
1410
+ ) : new Computation(first, null, second);
1411
+ node.j = () => node.write(first);
1376
1412
  function write(v) {
1377
1413
  if (!ActiveTransition)
1378
1414
  throw new Error("createOptimistic can only be updated inside a transition");
1379
- ActiveTransition.addOptimistic(node.m);
1415
+ ActiveTransition.addOptimistic(node.j);
1380
1416
  queueMicrotask(() => {
1381
- if (node.m.j) {
1417
+ if (node.j.f) {
1382
1418
  node.F();
1383
1419
  node.write(v);
1384
1420
  }
1385
1421
  });
1386
1422
  }
1387
- return [node.read.bind(node), write];
1423
+ return [node.wait.bind(node), write];
1424
+ }
1425
+ function transition(fn) {
1426
+ let t = new Transition(new Computation(void 0, null));
1427
+ queueMicrotask(() => t.runTransition(() => fn((fn2) => t.runTransition(fn2))));
1388
1428
  }
1389
1429
  function useTransition() {
1390
1430
  const [pending, setPending] = createOptimistic(false);
@@ -1667,7 +1707,7 @@ var storeTraps = {
1667
1707
  return desc.get.call(receiver);
1668
1708
  }
1669
1709
  if (Writing == null ? void 0 : Writing.has(receiver)) {
1670
- let value2 = tracked && (overridden || !proxySource) ? tracked.l : storeValue[property];
1710
+ let value2 = tracked && (overridden || !proxySource) ? tracked.m : storeValue[property];
1671
1711
  value2 === $DELETED && (value2 = void 0);
1672
1712
  if (!isWrappable(value2))
1673
1713
  return value2;
@@ -1862,28 +1902,29 @@ function deep(store) {
1862
1902
  // src/store/optimistic.ts
1863
1903
  function createOptimisticStore(first, second, options) {
1864
1904
  const derived = typeof first === "function";
1865
- const { store, node } = derived ? createProjectionInternal((draft) => {
1866
- const res = first(draft);
1867
- if (reset.j)
1868
- return draft;
1869
- return res;
1870
- }, second, options) : createProjectionInternal(() => {
1905
+ const { store, node } = derived ? createProjectionInternal(
1906
+ (draft) => {
1907
+ if (reset.f) {
1908
+ latest(() => first(draft));
1909
+ return draft;
1910
+ }
1911
+ return first(draft);
1912
+ },
1913
+ second,
1914
+ options
1915
+ ) : createProjectionInternal(() => {
1871
1916
  }, first);
1872
1917
  const reset = () => storeSetter(
1873
1918
  store,
1874
- reconcile(
1875
- derived ? first(store) || store : first,
1876
- (options == null ? void 0 : options.key) || "id",
1877
- options == null ? void 0 : options.all
1878
- )
1919
+ reconcile(derived ? first(store) || store : first, (options == null ? void 0 : options.key) || "id", options == null ? void 0 : options.all)
1879
1920
  );
1880
1921
  const write = (v) => {
1881
1922
  if (!ActiveTransition)
1882
1923
  throw new Error("createOptimisticStore can only be updated inside a transition");
1883
1924
  ActiveTransition.addOptimistic(reset);
1884
- queueMicrotask(() => reset.j && storeSetter(store, v));
1925
+ queueMicrotask(() => reset.f && storeSetter(store, v));
1885
1926
  };
1886
- node.m = reset;
1927
+ node.j = reset;
1887
1928
  return [store, write];
1888
1929
  }
1889
1930
 
@@ -2094,10 +2135,10 @@ function mapArray(list, map, options) {
2094
2135
  return updateKeyedMap.bind({
2095
2136
  U: new Owner(),
2096
2137
  p: 0,
2097
- ia: list,
2138
+ ka: list,
2098
2139
  I: [],
2099
2140
  R: map,
2100
- i: [],
2141
+ k: [],
2101
2142
  e: [],
2102
2143
  S: keyFn,
2103
2144
  q: keyFn || (options == null ? void 0 : options.keyed) === false ? [] : void 0,
@@ -2107,7 +2148,7 @@ function mapArray(list, map, options) {
2107
2148
  }
2108
2149
  var pureOptions = { pureWrite: true };
2109
2150
  function updateKeyedMap() {
2110
- const newItems = this.ia() || [], newLen = newItems.length;
2151
+ const newItems = this.ka() || [], newLen = newItems.length;
2111
2152
  newItems[$TRACK];
2112
2153
  runWithOwner(this.U, () => {
2113
2154
  let i, j, mapper = this.q ? () => {
@@ -2130,13 +2171,13 @@ function updateKeyedMap() {
2130
2171
  this.U.dispose(false);
2131
2172
  this.e = [];
2132
2173
  this.I = [];
2133
- this.i = [];
2174
+ this.k = [];
2134
2175
  this.p = 0;
2135
2176
  this.q && (this.q = []);
2136
2177
  this.r && (this.r = []);
2137
2178
  }
2138
- if (this.V && !this.i[0]) {
2139
- this.i[0] = compute(
2179
+ if (this.V && !this.k[0]) {
2180
+ this.k[0] = compute(
2140
2181
  this.e[0] = new Owner(),
2141
2182
  this.V,
2142
2183
  null
@@ -2145,10 +2186,10 @@ function updateKeyedMap() {
2145
2186
  } else if (this.p === 0) {
2146
2187
  if (this.e[0])
2147
2188
  this.e[0].dispose();
2148
- this.i = new Array(newLen);
2189
+ this.k = new Array(newLen);
2149
2190
  for (j = 0; j < newLen; j++) {
2150
2191
  this.I[j] = newItems[j];
2151
- this.i[j] = compute(this.e[j] = new Owner(), mapper, null);
2192
+ this.k[j] = compute(this.e[j] = new Owner(), mapper, null);
2152
2193
  }
2153
2194
  this.p = newLen;
2154
2195
  } else {
@@ -2158,7 +2199,7 @@ function updateKeyedMap() {
2158
2199
  this.q[start].write(newItems[start]);
2159
2200
  }
2160
2201
  for (end = this.p - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.I[end] === newItems[newEnd] || this.q && compare(this.S, this.I[end], newItems[newEnd])); end--, newEnd--) {
2161
- temp[newEnd] = this.i[end];
2202
+ temp[newEnd] = this.k[end];
2162
2203
  tempNodes[newEnd] = this.e[end];
2163
2204
  tempRows && (tempRows[newEnd] = this.q[end]);
2164
2205
  tempIndexes && (tempIndexes[newEnd] = this.r[end]);
@@ -2177,7 +2218,7 @@ function updateKeyedMap() {
2177
2218
  key = this.S ? this.S(item) : item;
2178
2219
  j = newIndices.get(key);
2179
2220
  if (j !== void 0 && j !== -1) {
2180
- temp[j] = this.i[i];
2221
+ temp[j] = this.k[i];
2181
2222
  tempNodes[j] = this.e[i];
2182
2223
  tempRows && (tempRows[j] = this.q[i]);
2183
2224
  tempIndexes && (tempIndexes[j] = this.r[i]);
@@ -2188,7 +2229,7 @@ function updateKeyedMap() {
2188
2229
  }
2189
2230
  for (j = start; j < newLen; j++) {
2190
2231
  if (j in temp) {
2191
- this.i[j] = temp[j];
2232
+ this.k[j] = temp[j];
2192
2233
  this.e[j] = tempNodes[j];
2193
2234
  if (tempRows) {
2194
2235
  this.q[j] = tempRows[j];
@@ -2199,42 +2240,42 @@ function updateKeyedMap() {
2199
2240
  this.r[j].write(j);
2200
2241
  }
2201
2242
  } else {
2202
- this.i[j] = compute(this.e[j] = new Owner(), mapper, null);
2243
+ this.k[j] = compute(this.e[j] = new Owner(), mapper, null);
2203
2244
  }
2204
2245
  }
2205
- this.i = this.i.slice(0, this.p = newLen);
2246
+ this.k = this.k.slice(0, this.p = newLen);
2206
2247
  this.I = newItems.slice(0);
2207
2248
  }
2208
2249
  });
2209
- return this.i;
2250
+ return this.k;
2210
2251
  }
2211
2252
  function repeat(count, map, options) {
2212
2253
  return updateRepeat.bind({
2213
2254
  U: new Owner(),
2214
2255
  p: 0,
2215
2256
  B: 0,
2216
- ja: count,
2257
+ la: count,
2217
2258
  R: map,
2218
2259
  e: [],
2219
- i: [],
2220
- ka: options == null ? void 0 : options.from,
2260
+ k: [],
2261
+ ma: options == null ? void 0 : options.from,
2221
2262
  V: options == null ? void 0 : options.fallback
2222
2263
  });
2223
2264
  }
2224
2265
  function updateRepeat() {
2225
2266
  var _a;
2226
- const newLen = this.ja();
2227
- const from = ((_a = this.ka) == null ? void 0 : _a.call(this)) || 0;
2267
+ const newLen = this.la();
2268
+ const from = ((_a = this.ma) == null ? void 0 : _a.call(this)) || 0;
2228
2269
  runWithOwner(this.U, () => {
2229
2270
  if (newLen === 0) {
2230
2271
  if (this.p !== 0) {
2231
2272
  this.U.dispose(false);
2232
2273
  this.e = [];
2233
- this.i = [];
2274
+ this.k = [];
2234
2275
  this.p = 0;
2235
2276
  }
2236
- if (this.V && !this.i[0]) {
2237
- this.i[0] = compute(
2277
+ if (this.V && !this.k[0]) {
2278
+ this.k[0] = compute(
2238
2279
  this.e[0] = new Owner(),
2239
2280
  this.V,
2240
2281
  null
@@ -2253,18 +2294,18 @@ function updateRepeat() {
2253
2294
  while (i < from && i < this.p)
2254
2295
  this.e[i++].dispose();
2255
2296
  this.e.splice(0, from - this.B);
2256
- this.i.splice(0, from - this.B);
2297
+ this.k.splice(0, from - this.B);
2257
2298
  } else if (this.B > from) {
2258
2299
  let i = prevTo - this.B - 1;
2259
2300
  let difference = this.B - from;
2260
- this.e.length = this.i.length = newLen;
2301
+ this.e.length = this.k.length = newLen;
2261
2302
  while (i >= difference) {
2262
2303
  this.e[i] = this.e[i - difference];
2263
- this.i[i] = this.i[i - difference];
2304
+ this.k[i] = this.k[i - difference];
2264
2305
  i--;
2265
2306
  }
2266
2307
  for (let i2 = 0; i2 < difference; i2++) {
2267
- this.i[i2] = compute(
2308
+ this.k[i2] = compute(
2268
2309
  this.e[i2] = new Owner(),
2269
2310
  () => this.R(i2 + from),
2270
2311
  null
@@ -2272,17 +2313,17 @@ function updateRepeat() {
2272
2313
  }
2273
2314
  }
2274
2315
  for (let i = prevTo; i < to; i++) {
2275
- this.i[i - from] = compute(
2316
+ this.k[i - from] = compute(
2276
2317
  this.e[i - from] = new Owner(),
2277
2318
  () => this.R(i),
2278
2319
  null
2279
2320
  );
2280
2321
  }
2281
- this.i = this.i.slice(0, newLen);
2322
+ this.k = this.k.slice(0, newLen);
2282
2323
  this.B = from;
2283
2324
  this.p = newLen;
2284
2325
  });
2285
- return this.i;
2326
+ return this.k;
2286
2327
  }
2287
2328
  function compare(key, a, b) {
2288
2329
  return key ? key(a) === key(b) : true;
@@ -2297,11 +2338,11 @@ var BoundaryComputation = class extends EagerComputation {
2297
2338
  }
2298
2339
  write(value, flags) {
2299
2340
  super.write(value, flags & ~this.W);
2300
- if (this.W & LOADING_BIT && !(this.f & UNINITIALIZED_BIT || ActiveTransition)) {
2341
+ if (this.W & LOADING_BIT && !(this.g & UNINITIALIZED_BIT || ActiveTransition)) {
2301
2342
  flags &= ~LOADING_BIT;
2302
2343
  }
2303
2344
  getQueue(this).notify(this, this.W, flags);
2304
- return this.l;
2345
+ return this.m;
2305
2346
  }
2306
2347
  };
2307
2348
  function createBoundChildren(owner, fn, queue, mask) {
@@ -2312,7 +2353,7 @@ function createBoundChildren(owner, fn, queue, mask) {
2312
2353
  owner,
2313
2354
  () => {
2314
2355
  const c = new Computation(void 0, fn);
2315
- return new BoundaryComputation(() => flatten(c.wait()), mask);
2356
+ return new BoundaryComputation(() => latest(() => flatten(c.wait())), mask);
2316
2357
  },
2317
2358
  null
2318
2359
  );
@@ -2431,7 +2472,7 @@ function createErrorBoundary(fn, fallback) {
2431
2472
  for (let node2 of queue.e) {
2432
2473
  if (ActiveTransition && !node2.d)
2433
2474
  node2 = cloneGraph(node2);
2434
- node2.b = STATE_DIRTY;
2475
+ node2.a = STATE_DIRTY;
2435
2476
  getQueue(node2).enqueue(node2.s, node2.x.bind(node2));
2436
2477
  }
2437
2478
  });