@solidjs/signals 0.7.2 → 0.7.4

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
@@ -1,5 +1,9 @@
1
1
  // src/core/error.ts
2
2
  var NotReadyError = class extends Error {
3
+ constructor(node) {
4
+ super();
5
+ this.cause = node;
6
+ }
3
7
  };
4
8
  var NoOwnerError = class extends Error {
5
9
  constructor() {
@@ -52,21 +56,21 @@ function notifyUnobserved() {
52
56
  for (let i = 0; i < Unobserved.length; i++) {
53
57
  const source = Unobserved[i];
54
58
  if (!source.c || !source.c.length)
55
- Unobserved[i].ea?.();
59
+ Unobserved[i].fa?.();
56
60
  }
57
61
  Unobserved = [];
58
62
  }
59
63
  var pureQueue = [];
60
64
  var Queue = class {
61
- k = null;
65
+ l = null;
62
66
  C = false;
63
- f = [[], []];
64
- g = [];
67
+ h = [[], []];
68
+ i = [];
65
69
  created = clock;
66
70
  enqueue(type, fn) {
67
71
  pureQueue.push(fn);
68
72
  if (type)
69
- this.f[type - 1].push(fn);
73
+ this.h[type - 1].push(fn);
70
74
  schedule();
71
75
  }
72
76
  run(type) {
@@ -74,13 +78,13 @@ var Queue = class {
74
78
  pureQueue.length && runQueue(pureQueue, type);
75
79
  pureQueue = [];
76
80
  return;
77
- } else if (this.f[type - 1].length) {
78
- const effects = this.f[type - 1];
79
- this.f[type - 1] = [];
81
+ } else if (this.h[type - 1].length) {
82
+ const effects = this.h[type - 1];
83
+ this.h[type - 1] = [];
80
84
  runQueue(effects, type);
81
85
  }
82
- for (let i = 0; i < this.g.length; i++) {
83
- this.g[i].run(type);
86
+ for (let i = 0; i < this.i.length; i++) {
87
+ this.i[i].run(type);
84
88
  }
85
89
  }
86
90
  flush() {
@@ -101,32 +105,32 @@ var Queue = class {
101
105
  addChild(child) {
102
106
  if (ActiveTransition && ActiveTransition.J.has(this))
103
107
  return ActiveTransition.J.get(this).addChild(child);
104
- this.g.push(child);
105
- child.k = this;
108
+ this.i.push(child);
109
+ child.l = this;
106
110
  }
107
111
  removeChild(child) {
108
112
  if (ActiveTransition && ActiveTransition.J.has(this))
109
113
  return ActiveTransition.J.get(this).removeChild(child);
110
- const index = this.g.indexOf(child);
114
+ const index = this.i.indexOf(child);
111
115
  if (index >= 0) {
112
- this.g.splice(index, 1);
113
- child.k = null;
116
+ this.i.splice(index, 1);
117
+ child.l = null;
114
118
  }
115
119
  }
116
120
  notify(...args) {
117
- if (this.k)
118
- return this.k.notify(...args);
121
+ if (this.l)
122
+ return this.l.notify(...args);
119
123
  return false;
120
124
  }
121
125
  merge(queue) {
122
- this.f[0].push.apply(this.f[0], queue.f[0]);
123
- this.f[1].push.apply(this.f[1], queue.f[1]);
124
- for (let i = 0; i < queue.g.length; i++) {
125
- const og = this.g.find((c) => c.d === queue.g[i].d);
126
+ this.h[0].push.apply(this.h[0], queue.h[0]);
127
+ this.h[1].push.apply(this.h[1], queue.h[1]);
128
+ for (let i = 0; i < queue.i.length; i++) {
129
+ const og = this.i.find((c) => c.d === queue.i[i].d);
126
130
  if (og)
127
- og.merge(queue.g[i]);
131
+ og.merge(queue.i[i]);
128
132
  else
129
- this.addChild(queue.g[i]);
133
+ this.addChild(queue.i[i]);
130
134
  }
131
135
  }
132
136
  };
@@ -139,8 +143,8 @@ function flush() {
139
143
  function removeSourceObservers(node, index) {
140
144
  let source;
141
145
  let swap;
142
- for (let i = index; i < node.a.length; i++) {
143
- source = getTransitionSource(node.a[i]);
146
+ for (let i = index; i < node.b.length; i++) {
147
+ source = getTransitionSource(node.b[i]);
144
148
  if (source.c) {
145
149
  if ((swap = source.c.indexOf(node)) !== -1) {
146
150
  source.c[swap] = source.c[source.c.length - 1];
@@ -156,30 +160,32 @@ function runQueue(queue, type) {
156
160
  queue[i](type);
157
161
  }
158
162
  var Transition = class _Transition {
159
- a = /* @__PURE__ */ new Map();
163
+ b = /* @__PURE__ */ new Map();
160
164
  t = /* @__PURE__ */ new Set();
161
165
  K = /* @__PURE__ */ new Set();
162
- r = /* @__PURE__ */ new Set();
166
+ j = /* @__PURE__ */ new Set();
163
167
  D = false;
164
- f = [[], []];
168
+ h = [[], []];
165
169
  J = /* @__PURE__ */ new Map();
166
170
  G = [];
167
- g = [];
168
- k = null;
171
+ i = [];
172
+ l = null;
169
173
  C = false;
170
174
  Y = false;
171
175
  d = globalQueue;
176
+ aa;
172
177
  created = clock;
173
- constructor() {
178
+ constructor(signal) {
179
+ this.aa = signal;
174
180
  this.J.set(globalQueue, this);
175
- for (const child of globalQueue.g) {
181
+ for (const child of globalQueue.i) {
176
182
  cloneQueue(child, this, this);
177
183
  }
178
184
  }
179
185
  enqueue(type, fn) {
180
186
  this.G.push(fn);
181
187
  if (type)
182
- this.f[type - 1].push(fn);
188
+ this.h[type - 1].push(fn);
183
189
  this.schedule();
184
190
  }
185
191
  run(type) {
@@ -187,18 +193,19 @@ var Transition = class _Transition {
187
193
  this.G.length && runQueue(this.G, type);
188
194
  this.G = [];
189
195
  return;
190
- } else if (this.f[type - 1].length) {
191
- const effects = this.f[type - 1];
192
- this.f[type - 1] = [];
196
+ } else if (this.h[type - 1].length) {
197
+ const effects = this.h[type - 1];
198
+ this.h[type - 1] = [];
193
199
  runQueue(effects, type);
194
200
  }
195
- for (let i = 0; i < this.g.length; i++) {
196
- this.g[i].run(type);
201
+ for (let i = 0; i < this.i.length; i++) {
202
+ this.i[i].run(type);
197
203
  }
198
204
  }
199
205
  flush() {
200
206
  if (this.C || this.D)
201
207
  return;
208
+ globalQueue.flush();
202
209
  this.C = true;
203
210
  let currentTransition = ActiveTransition;
204
211
  ActiveTransition = this;
@@ -214,13 +221,13 @@ var Transition = class _Transition {
214
221
  }
215
222
  }
216
223
  addChild(child) {
217
- this.g.push(child);
218
- child.k = this;
224
+ this.i.push(child);
225
+ child.l = this;
219
226
  }
220
227
  removeChild(child) {
221
- const index = this.g.indexOf(child);
228
+ const index = this.i.indexOf(child);
222
229
  if (index >= 0)
223
- this.g.splice(index, 1);
230
+ this.i.splice(index, 1);
224
231
  }
225
232
  notify(node, type, flags) {
226
233
  if (!(type & LOADING_BIT))
@@ -233,18 +240,18 @@ var Transition = class _Transition {
233
240
  return true;
234
241
  }
235
242
  merge(queue) {
236
- this.f[0].push.apply(this.f[0], queue.f[0]);
237
- this.f[1].push.apply(this.f[1], queue.f[1]);
243
+ this.h[0].push.apply(this.h[0], queue.h[0]);
244
+ this.h[1].push.apply(this.h[1], queue.h[1]);
238
245
  this.G.push.apply(this.G, queue.G);
239
- queue.f[0].length = 0;
240
- queue.f[1].length = 0;
246
+ queue.h[0].length = 0;
247
+ queue.h[1].length = 0;
241
248
  queue.G.length = 0;
242
- for (let i = 0; i < queue.g.length; i++) {
243
- const og = this.g.find((c) => c.d === queue.g[i].d);
249
+ for (let i = 0; i < queue.i.length; i++) {
250
+ const og = this.i.find((c) => c.d === queue.i[i].d);
244
251
  if (og)
245
- og.merge(queue.g[i]);
252
+ og.merge(queue.i[i]);
246
253
  else
247
- this.addChild(queue.g[i]);
254
+ this.addChild(queue.i[i]);
248
255
  }
249
256
  }
250
257
  schedule() {
@@ -304,43 +311,44 @@ var Transition = class _Transition {
304
311
  }
305
312
  }
306
313
  addOptimistic(fn) {
307
- if (fn.j && fn.j !== this) {
308
- mergeTransitions(fn.j, this);
309
- ActiveTransition = fn.j;
314
+ if (fn.f && fn.f !== this) {
315
+ mergeTransitions(fn.f, this);
316
+ ActiveTransition = fn.f;
310
317
  return;
311
318
  }
312
- fn.j = this;
313
- this.r.add(fn);
319
+ fn.f = this;
320
+ this.j.add(fn);
314
321
  }
315
322
  };
316
- function transition(fn) {
317
- let t = new Transition();
318
- queueMicrotask(() => t.runTransition(() => fn((fn2) => t.runTransition(fn2))));
319
- }
320
323
  function cloneGraph(node) {
321
- if (node.r)
322
- return node;
323
324
  if (node.j) {
324
- if (node.j !== ActiveTransition) {
325
- mergeTransitions(node.j, ActiveTransition);
326
- ActiveTransition = node.j;
325
+ if (node.a !== STATE_DISPOSED) {
326
+ node.j.ia?.();
327
+ ActiveTransition.addOptimistic(node.j);
328
+ }
329
+ return node;
330
+ }
331
+ if (node.f) {
332
+ if (node.f !== ActiveTransition) {
333
+ mergeTransitions(node.f, ActiveTransition);
334
+ ActiveTransition = node.f;
327
335
  }
328
- return node.j.a.get(node);
336
+ return node.f.b.get(node);
329
337
  }
330
338
  const clone = Object.create(Object.getPrototypeOf(node));
331
339
  Object.assign(clone, node, {
340
+ o: null,
332
341
  n: null,
333
- m: null,
334
342
  c: null,
335
- a: node.a ? [...node.a] : null,
343
+ b: node.b ? [...node.b] : null,
336
344
  d: node
337
345
  });
338
346
  delete clone.T;
339
- ActiveTransition.a.set(node, clone);
340
- node.j = ActiveTransition;
341
- if (node.a) {
342
- for (let i = 0; i < node.a.length; i++)
343
- node.a[i].c.push(clone);
347
+ ActiveTransition.b.set(node, clone);
348
+ node.f = ActiveTransition;
349
+ if (node.b) {
350
+ for (let i = 0; i < node.b.length; i++)
351
+ node.b[i].c.push(clone);
344
352
  }
345
353
  if (node.c) {
346
354
  clone.c = [];
@@ -359,9 +367,9 @@ function replaceSourceObservers(node, transition2) {
359
367
  let source;
360
368
  let transitionSource;
361
369
  let swap;
362
- for (let i = 0; i < node.a.length; i++) {
363
- transitionSource = transition2.a.get(node.a[i]);
364
- source = transitionSource || node.a[i];
370
+ for (let i = 0; i < node.b.length; i++) {
371
+ transitionSource = transition2.b.get(node.b[i]);
372
+ source = transitionSource || node.b[i];
365
373
  if (source.c && (swap = source.c.indexOf(node)) !== -1) {
366
374
  source.c[swap] = transitionSource ? node.d : source.c[source.c.length - 1];
367
375
  !transitionSource && source.c.pop();
@@ -372,8 +380,8 @@ function cloneQueue(queue, parent, transition2) {
372
380
  const clone = Object.create(Object.getPrototypeOf(queue));
373
381
  Object.assign(clone, queue, {
374
382
  d: queue,
375
- k: parent,
376
- g: [],
383
+ l: parent,
384
+ i: [],
377
385
  enqueue(type, fn) {
378
386
  transition2 = latestTransition(transition2);
379
387
  transition2.enqueue(type, fn);
@@ -390,9 +398,9 @@ function cloneQueue(queue, parent, transition2) {
390
398
  return queue.notify.call(this, node, type, flags);
391
399
  }
392
400
  });
393
- parent.g.push(clone);
401
+ parent.i.push(clone);
394
402
  transition2.J.set(queue, clone);
395
- for (const child of queue.g) {
403
+ for (const child of queue.i) {
396
404
  cloneQueue(child, clone, transition2);
397
405
  }
398
406
  }
@@ -400,27 +408,27 @@ function resolveQueues(children) {
400
408
  for (const child of children) {
401
409
  const og = child.d;
402
410
  if (og) {
403
- const clonedChildren = child.g;
411
+ const clonedChildren = child.i;
404
412
  delete child.enqueue;
405
413
  delete child.notify;
406
- delete child.k;
407
- delete child.g;
414
+ delete child.l;
415
+ delete child.i;
408
416
  Object.assign(og, child);
409
417
  delete og.d;
410
418
  resolveQueues(clonedChildren);
411
- } else if (child.k.d) {
412
- child.k.d.addChild(child);
419
+ } else if (child.l.d) {
420
+ child.l.d.addChild(child);
413
421
  }
414
422
  }
415
423
  }
416
424
  function mergeTransitions(t1, t2) {
417
- t2.a.forEach((value, key) => {
418
- key.j = t1;
419
- t1.a.set(key, value);
425
+ t2.b.forEach((value, key) => {
426
+ key.f = t1;
427
+ t1.b.set(key, value);
420
428
  });
421
- t2.r.forEach((c) => {
422
- c.j = t1;
423
- t1.r.add(c);
429
+ t2.j.forEach((c) => {
430
+ c.f = t1;
431
+ t1.j.add(c);
424
432
  });
425
433
  t2.K.forEach((p) => t1.K.add(p));
426
434
  t2.t.forEach((n) => t1.t.add(n));
@@ -428,59 +436,60 @@ function mergeTransitions(t1, t2) {
428
436
  t2.D = t1;
429
437
  }
430
438
  function getTransitionSource(input) {
431
- return ActiveTransition && ActiveTransition.a.get(input) || input;
439
+ return ActiveTransition && ActiveTransition.b.get(input) || input;
432
440
  }
433
441
  function getQueue(node) {
434
- const transition2 = ActiveTransition || node.d?.j;
442
+ const transition2 = ActiveTransition || node.d?.f;
435
443
  return transition2 && transition2.J.get(node.E) || node.E;
436
444
  }
437
445
  function initialDispose(node) {
438
- let current = node.m;
439
- while (current !== null && current.k === node) {
446
+ let current = node.n;
447
+ while (current !== null && current.l === node) {
440
448
  initialDispose(current);
441
- const clone = ActiveTransition.a.get(current);
449
+ const clone = ActiveTransition.b.get(current);
442
450
  if (clone && !clone.Z)
443
451
  clone.dispose(true);
444
- current = current.m;
452
+ current = current.n;
445
453
  }
446
454
  }
447
455
  function finishTransition(transition2) {
448
456
  if (transition2.D || transition2.Y || transition2.K.size || transition2.t.size)
449
457
  return;
450
- globalQueue.f[0].push.apply(globalQueue.f[0], transition2.f[0]);
451
- globalQueue.f[1].push.apply(globalQueue.f[1], transition2.f[1]);
452
- resolveQueues(transition2.g);
453
- for (const [source, clone] of transition2.a) {
454
- if (source === clone || source.j !== transition2) {
455
- delete source.j;
458
+ globalQueue.h[0].push.apply(globalQueue.h[0], transition2.h[0]);
459
+ globalQueue.h[1].push.apply(globalQueue.h[1], transition2.h[1]);
460
+ resolveQueues(transition2.i);
461
+ for (const [source, clone] of transition2.b) {
462
+ if (source === clone || source.f !== transition2) {
463
+ delete source.f;
456
464
  continue;
457
465
  }
458
- if (clone.a)
466
+ if (clone.b)
459
467
  replaceSourceObservers(clone, transition2);
460
- if (clone.Z || clone.b === STATE_DISPOSED) {
461
- source.dispose(clone.b === STATE_DISPOSED);
468
+ if (clone.Z || clone.a === STATE_DISPOSED) {
469
+ source.dispose(clone.a === STATE_DISPOSED);
462
470
  source.emptyDisposal();
463
471
  delete clone.Z;
464
472
  } else {
465
- delete clone.m;
466
473
  delete clone.n;
474
+ delete clone.o;
467
475
  }
468
476
  Object.assign(source, clone);
469
477
  delete source.d;
470
- let current = clone.m;
478
+ let current = clone.n;
471
479
  if (current?.z === clone)
472
480
  current.z = source;
473
- while (current?.k === clone) {
474
- current.k = source;
475
- current = current.m;
481
+ while (current?.l === clone) {
482
+ current.l = source;
483
+ current = current.n;
476
484
  }
477
- delete source.j;
485
+ delete source.f;
478
486
  }
479
487
  transition2.D = true;
480
- for (const reset of transition2.r) {
481
- delete reset.j;
488
+ for (const reset of transition2.j) {
489
+ delete reset.f;
482
490
  reset();
483
491
  }
492
+ transition2.aa.write(true);
484
493
  globalQueue.flush();
485
494
  }
486
495
 
@@ -499,14 +508,14 @@ var Owner = class {
499
508
  // We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
500
509
  // However, the children are actually added in reverse creation order
501
510
  // See comment at the top of the file for an example of the _nextSibling traversal
502
- k = null;
503
- m = null;
504
- z = null;
505
- b = STATE_CLEAN;
511
+ l = null;
506
512
  n = null;
513
+ z = null;
514
+ a = STATE_CLEAN;
515
+ o = null;
507
516
  A = defaultContext;
508
517
  E = globalQueue;
509
- fa = 0;
518
+ ga = 0;
510
519
  id = null;
511
520
  constructor(id = null, skipAppend = false) {
512
521
  this.id = id;
@@ -515,12 +524,12 @@ var Owner = class {
515
524
  }
516
525
  }
517
526
  append(child) {
518
- child.k = this;
527
+ child.l = this;
519
528
  child.z = this;
520
- if (this.m)
521
- this.m.z = child;
522
- child.m = this.m;
523
- this.m = child;
529
+ if (this.n)
530
+ this.n.z = child;
531
+ child.n = this.n;
532
+ this.n = child;
524
533
  if (this.id != null && child.id == null)
525
534
  child.id = this.getNextChildId();
526
535
  if (child.A !== this.A) {
@@ -530,48 +539,48 @@ var Owner = class {
530
539
  child.E = this.E;
531
540
  }
532
541
  dispose(self = true) {
533
- if (this.b === STATE_DISPOSED)
542
+ if (this.a === STATE_DISPOSED)
534
543
  return;
535
- let head = self ? this.z || this.k : this, current = this.m, next = null;
536
- while (current && current.k === this) {
544
+ let head = self ? this.z || this.l : this, current = this.n, next = null;
545
+ while (current && current.l === this) {
537
546
  current.dispose(true);
538
- next = current.m;
539
- current.m = null;
547
+ next = current.n;
548
+ current.n = null;
540
549
  current = next;
541
550
  }
542
- this.fa = 0;
551
+ this.ga = 0;
543
552
  if (self)
544
553
  this.M();
545
554
  if (current)
546
555
  current.z = !self ? this : this.z;
547
556
  if (head)
548
- head.m = current;
557
+ head.n = current;
549
558
  }
550
559
  M() {
551
560
  if (this.z)
552
- this.z.m = null;
553
- this.k = null;
561
+ this.z.n = null;
562
+ this.l = null;
554
563
  this.z = null;
555
564
  this.A = defaultContext;
556
- this.b = STATE_DISPOSED;
565
+ this.a = STATE_DISPOSED;
557
566
  this.emptyDisposal();
558
567
  }
559
568
  emptyDisposal() {
560
- if (!this.n)
569
+ if (!this.o)
561
570
  return;
562
- if (Array.isArray(this.n)) {
563
- for (let i = 0; i < this.n.length; i++) {
564
- const callable = this.n[i];
571
+ if (Array.isArray(this.o)) {
572
+ for (let i = 0; i < this.o.length; i++) {
573
+ const callable = this.o[i];
565
574
  callable.call(callable);
566
575
  }
567
576
  } else {
568
- this.n.call(this.n);
577
+ this.o.call(this.o);
569
578
  }
570
- this.n = null;
579
+ this.o = null;
571
580
  }
572
581
  getNextChildId() {
573
582
  if (this.id != null)
574
- return formatId(this.id, this.fa++);
583
+ return formatId(this.id, this.ga++);
575
584
  throw new Error("Cannot get child id from owner without an id");
576
585
  }
577
586
  };
@@ -604,12 +613,12 @@ function onCleanup(fn) {
604
613
  if (!currentOwner)
605
614
  return fn;
606
615
  const node = currentOwner;
607
- if (!node.n) {
608
- node.n = fn;
609
- } else if (Array.isArray(node.n)) {
610
- node.n.push(fn);
616
+ if (!node.o) {
617
+ node.o = fn;
618
+ } else if (Array.isArray(node.o)) {
619
+ node.o.push(fn);
611
620
  } else {
612
- node.n = [node.n, fn];
621
+ node.o = [node.o, fn];
613
622
  }
614
623
  return fn;
615
624
  }
@@ -635,49 +644,49 @@ function getObserver() {
635
644
  }
636
645
  var UNCHANGED = Symbol(0);
637
646
  var Computation = class extends Owner {
638
- a = null;
647
+ b = null;
639
648
  c = null;
640
- l;
649
+ m;
641
650
  O;
642
651
  P;
643
652
  // Used in __DEV__ mode, hopefully removed in production
644
- la;
653
+ na;
645
654
  // Using false is an optimization as an alternative to _equals: () => false
646
655
  // which could enable more efficient DIRTY notification
647
- aa = isEqual;
648
- ea;
649
- ha = false;
656
+ ba = isEqual;
657
+ fa;
658
+ ja = false;
650
659
  /** Whether the computation is an error or has ancestors that are unresolved */
651
- h = 0;
660
+ g = 0;
652
661
  /** Which flags raised by sources are handled, vs. being passed through. */
653
- ba = DEFAULT_FLAGS;
662
+ ca = DEFAULT_FLAGS;
654
663
  Q = -1;
655
664
  H = false;
656
- j;
665
+ f;
657
666
  d;
658
- r = false;
667
+ j;
659
668
  constructor(initialValue, compute2, options) {
660
669
  super(options?.id, compute2 === null);
661
670
  this.P = compute2;
662
- this.b = compute2 ? STATE_DIRTY : STATE_CLEAN;
663
- this.h = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
664
- this.l = initialValue;
671
+ this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
672
+ this.g = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
673
+ this.m = initialValue;
665
674
  if (options?.equals !== void 0)
666
- this.aa = options.equals;
667
- this.ha = !!options?.pureWrite;
668
- this.ea = options?.unobserved;
675
+ this.ba = options.equals;
676
+ this.ja = !!options?.pureWrite;
677
+ this.fa = options?.unobserved;
669
678
  if (ActiveTransition) {
670
- this.j = ActiveTransition;
671
- ActiveTransition.a.set(this, this);
679
+ this.f = ActiveTransition;
680
+ ActiveTransition.b.set(this, this);
672
681
  }
673
682
  }
674
- ga() {
683
+ ha() {
675
684
  track(this);
676
- newFlags |= this.h & ~currentMask;
677
- if (this.h & ERROR_BIT) {
685
+ newFlags |= this.g & ~currentMask;
686
+ if (this.g & ERROR_BIT) {
678
687
  throw this.O;
679
688
  } else {
680
- return this.l;
689
+ return this.m;
681
690
  }
682
691
  }
683
692
  /**
@@ -685,18 +694,18 @@ var Computation = class extends Owner {
685
694
  * Automatically re-executes the surrounding computation when the value changes
686
695
  */
687
696
  read() {
688
- if (ActiveTransition && (ActiveTransition.a.has(this) || !this.d && this.h & (UNINITIALIZED_BIT | ERROR_BIT))) {
689
- const clone = ActiveTransition.a.get(this) || cloneGraph(this);
697
+ if (ActiveTransition && (ActiveTransition.b.has(this) || !this.d && this.g & (UNINITIALIZED_BIT | ERROR_BIT))) {
698
+ const clone = ActiveTransition.b.get(this) || cloneGraph(this);
690
699
  if (clone !== this)
691
700
  return clone.read();
692
701
  }
693
702
  if (this.P) {
694
- if (this.h & ERROR_BIT && this.Q <= clock)
703
+ if (this.g & ERROR_BIT && this.Q <= clock)
695
704
  update(this);
696
705
  else
697
706
  this.F();
698
707
  }
699
- return this.ga();
708
+ return this.ha();
700
709
  }
701
710
  /**
702
711
  * Return the current value of this computation
@@ -706,25 +715,25 @@ var Computation = class extends Owner {
706
715
  * before continuing
707
716
  */
708
717
  wait() {
709
- if (ActiveTransition && (ActiveTransition.a.has(this) || !this.d && this.h & (UNINITIALIZED_BIT | ERROR_BIT))) {
710
- const clone = ActiveTransition.a.get(this) || cloneGraph(this);
718
+ if (ActiveTransition && (ActiveTransition.b.has(this) || !this.d && this.g & (UNINITIALIZED_BIT | ERROR_BIT))) {
719
+ const clone = ActiveTransition.b.get(this) || cloneGraph(this);
711
720
  if (clone !== this)
712
721
  return clone.wait();
713
722
  }
714
723
  if (this.P) {
715
- if (this.h & ERROR_BIT && this.Q <= clock)
724
+ if (this.g & ERROR_BIT && this.Q <= clock)
716
725
  update(this);
717
726
  else
718
727
  this.F();
719
728
  }
720
- if ((notStale || this.h & UNINITIALIZED_BIT) && this.h & LOADING_BIT) {
721
- track(this);
722
- throw new NotReadyError();
729
+ if ((notStale || this.g & UNINITIALIZED_BIT) && this.g & LOADING_BIT) {
730
+ throw new NotReadyError(this);
723
731
  }
724
- if (staleCheck && this.h & LOADING_BIT) {
725
- staleCheck.l = true;
732
+ if (staleCheck && (this.g & LOADING_BIT || this.f)) {
733
+ staleCheck.m = true;
734
+ this.f?.aa.read();
726
735
  }
727
- return this.ga();
736
+ return this.ha();
728
737
  }
729
738
  /** Update the computation with a new value. */
730
739
  write(value, flags = 0, raw = false) {
@@ -733,17 +742,17 @@ var Computation = class extends Owner {
733
742
  if (clone !== this)
734
743
  return clone.write(value, flags, raw);
735
744
  }
736
- const newValue = !raw && typeof value === "function" ? value(this.l) : value;
737
- const valueChanged = newValue !== UNCHANGED && (!!(this.h & UNINITIALIZED_BIT) || // this._stateFlags & LOADING_BIT & ~flags ||
738
- this.aa === false || !this.aa(this.l, newValue));
745
+ const newValue = !raw && typeof value === "function" ? value(this.m) : value;
746
+ const valueChanged = newValue !== UNCHANGED && (!!(this.g & UNINITIALIZED_BIT) || // this._stateFlags & LOADING_BIT & ~flags ||
747
+ this.ba === false || !this.ba(this.m, newValue));
739
748
  if (valueChanged) {
740
- this.l = newValue;
749
+ this.m = newValue;
741
750
  this.O = void 0;
742
751
  }
743
- const changedFlagsMask = this.h ^ flags, changedFlags = changedFlagsMask & flags;
744
- this.h = flags;
752
+ const changedFlagsMask = this.g ^ flags, changedFlags = changedFlagsMask & flags;
753
+ this.g = flags;
745
754
  this.Q = clock + 1;
746
- if (this.c && !(this.r && ActiveTransition)) {
755
+ if (this.c && !(this.j && ActiveTransition)) {
747
756
  for (let i = 0; i < this.c.length; i++) {
748
757
  if (valueChanged) {
749
758
  this.c[i].u(STATE_DIRTY);
@@ -752,17 +761,17 @@ var Computation = class extends Owner {
752
761
  }
753
762
  }
754
763
  }
755
- return this.l;
764
+ return this.m;
756
765
  }
757
766
  /**
758
767
  * Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
759
768
  */
760
769
  u(state, skipQueue) {
761
- if (this.b >= state && !this.H)
770
+ if (this.a >= state && !this.H)
762
771
  return;
763
772
  this.H = !!skipQueue;
764
- this.b = state;
765
- if (this.c && !(this.r && ActiveTransition)) {
773
+ this.a = state;
774
+ if (this.c && !(this.j && ActiveTransition)) {
766
775
  for (let i = 0; i < this.c.length; i++) {
767
776
  this.c[i].u(STATE_CHECK, skipQueue);
768
777
  }
@@ -775,20 +784,20 @@ var Computation = class extends Owner {
775
784
  * @param newFlags The source's new flags, masked to just the changed ones.
776
785
  */
777
786
  _(mask, newFlags2) {
778
- if (this.b >= STATE_DIRTY)
787
+ if (this.a >= STATE_DIRTY)
779
788
  return;
780
- if (mask & this.ba || this.r && ActiveTransition) {
789
+ if (mask & this.ca || this.j && ActiveTransition) {
781
790
  this.u(STATE_DIRTY);
782
791
  return;
783
792
  }
784
- if (this.b >= STATE_CHECK && !this.H)
793
+ if (this.a >= STATE_CHECK && !this.H)
785
794
  return;
786
- const prevFlags = this.h & mask;
795
+ const prevFlags = this.g & mask;
787
796
  const deltaFlags = prevFlags ^ newFlags2;
788
797
  if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
789
798
  this.u(STATE_CHECK);
790
799
  } else {
791
- this.h ^= deltaFlags;
800
+ this.g ^= deltaFlags;
792
801
  if (this.c) {
793
802
  for (let i = 0; i < this.c.length; i++) {
794
803
  this.c[i]._(mask, newFlags2);
@@ -803,7 +812,7 @@ var Computation = class extends Owner {
803
812
  return clone.N(error);
804
813
  }
805
814
  this.O = error;
806
- this.write(UNCHANGED, this.h & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
815
+ this.write(UNCHANGED, this.g & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
807
816
  }
808
817
  /**
809
818
  * This is the core part of the reactivity system, which makes sure that the values are updated
@@ -816,37 +825,37 @@ var Computation = class extends Owner {
816
825
  if (!this.P) {
817
826
  return;
818
827
  }
819
- if (this.b === STATE_DISPOSED) {
828
+ if (this.a === STATE_DISPOSED) {
820
829
  return;
821
830
  }
822
- if (this.b === STATE_CLEAN) {
831
+ if (this.a === STATE_CLEAN) {
823
832
  return;
824
833
  }
825
834
  let observerFlags = 0;
826
- if (this.b === STATE_CHECK) {
827
- for (let i = 0; i < this.a.length; i++) {
828
- const source = getTransitionSource(this.a[i]);
835
+ if (this.a === STATE_CHECK) {
836
+ for (let i = 0; i < this.b.length; i++) {
837
+ const source = getTransitionSource(this.b[i]);
829
838
  source.F();
830
- observerFlags |= source.h & ~UNINITIALIZED_BIT;
831
- if (this.b === STATE_DIRTY) {
839
+ observerFlags |= source.g & ~UNINITIALIZED_BIT;
840
+ if (this.a === STATE_DIRTY) {
832
841
  break;
833
842
  }
834
843
  }
835
844
  }
836
- if (this.b === STATE_DIRTY) {
845
+ if (this.a === STATE_DIRTY) {
837
846
  update(this);
838
847
  } else {
839
848
  this.write(UNCHANGED, observerFlags);
840
- this.b = STATE_CLEAN;
849
+ this.a = STATE_CLEAN;
841
850
  }
842
851
  }
843
852
  /**
844
853
  * Remove ourselves from the owner graph and the computation graph
845
854
  */
846
855
  M() {
847
- if (this.b === STATE_DISPOSED)
856
+ if (this.a === STATE_DISPOSED)
848
857
  return;
849
- if (this.a)
858
+ if (this.b)
850
859
  removeSourceObservers(this, 0);
851
860
  super.M();
852
861
  }
@@ -855,7 +864,7 @@ function track(computation) {
855
864
  if (ActiveTransition && computation.d)
856
865
  computation = computation.d;
857
866
  if (currentObserver) {
858
- if (!newSources && currentObserver.a && currentObserver.a[newSourcesIndex] === computation) {
867
+ if (!newSources && currentObserver.b && currentObserver.b[newSourcesIndex] === computation) {
859
868
  newSourcesIndex++;
860
869
  } else if (!newSources)
861
870
  newSources = [computation];
@@ -863,7 +872,7 @@ function track(computation) {
863
872
  newSources.push(computation);
864
873
  }
865
874
  if (updateCheck) {
866
- updateCheck.l = computation.Q > currentObserver.Q;
875
+ updateCheck.m = computation.Q > currentObserver.Q;
867
876
  }
868
877
  }
869
878
  }
@@ -883,39 +892,45 @@ function update(node) {
883
892
  node.write(result, newFlags, true);
884
893
  } catch (error) {
885
894
  if (error instanceof NotReadyError) {
886
- node.write(UNCHANGED, newFlags | LOADING_BIT | node.h & UNINITIALIZED_BIT);
895
+ if (error.cause !== node)
896
+ compute(
897
+ node,
898
+ () => track(error.cause),
899
+ node
900
+ );
901
+ node.write(UNCHANGED, newFlags | LOADING_BIT | node.g & UNINITIALIZED_BIT);
887
902
  } else {
888
903
  node.N(error);
889
904
  }
890
905
  } finally {
891
906
  if (newSources) {
892
- if (node.a)
907
+ if (node.b)
893
908
  removeSourceObservers(node, newSourcesIndex);
894
- if (node.a && newSourcesIndex > 0) {
895
- node.a.length = newSourcesIndex + newSources.length;
909
+ if (node.b && newSourcesIndex > 0) {
910
+ node.b.length = newSourcesIndex + newSources.length;
896
911
  for (let i = 0; i < newSources.length; i++) {
897
- node.a[newSourcesIndex + i] = newSources[i];
912
+ node.b[newSourcesIndex + i] = newSources[i];
898
913
  }
899
914
  } else {
900
- node.a = newSources;
915
+ node.b = newSources;
901
916
  }
902
917
  let source;
903
- for (let i = newSourcesIndex; i < node.a.length; i++) {
904
- source = getTransitionSource(node.a[i]);
918
+ for (let i = newSourcesIndex; i < node.b.length; i++) {
919
+ source = getTransitionSource(node.b[i]);
905
920
  if (!source.c)
906
921
  source.c = [node];
907
922
  else
908
923
  source.c.push(node);
909
924
  }
910
- } else if (node.a && newSourcesIndex < node.a.length) {
925
+ } else if (node.b && newSourcesIndex < node.b.length) {
911
926
  removeSourceObservers(node, newSourcesIndex);
912
- node.a.length = newSourcesIndex;
927
+ node.b.length = newSourcesIndex;
913
928
  }
914
929
  newSources = prevSources;
915
930
  newSourcesIndex = prevSourcesIndex;
916
931
  newFlags = prevFlags;
917
932
  node.Q = clock + 1;
918
- node.b = STATE_CLEAN;
933
+ node.a = STATE_CLEAN;
919
934
  }
920
935
  }
921
936
  function isEqual(a, b) {
@@ -928,20 +943,20 @@ function untrack(fn) {
928
943
  }
929
944
  function hasUpdated(fn) {
930
945
  const current = updateCheck;
931
- updateCheck = { l: false };
946
+ updateCheck = { m: false };
932
947
  try {
933
948
  fn();
934
- return updateCheck.l;
949
+ return updateCheck.m;
935
950
  } finally {
936
951
  updateCheck = current;
937
952
  }
938
953
  }
939
954
  function pendingCheck(fn, loadingValue) {
940
955
  const current = staleCheck;
941
- staleCheck = { l: false };
956
+ staleCheck = { m: false };
942
957
  try {
943
958
  latest(fn);
944
- return staleCheck.l;
959
+ return staleCheck.m;
945
960
  } catch (err) {
946
961
  if (!(err instanceof NotReadyError))
947
962
  return false;
@@ -956,8 +971,17 @@ function isPending(fn, loadingValue) {
956
971
  if (!currentObserver)
957
972
  return pendingCheck(fn, loadingValue);
958
973
  const c = new Computation(void 0, () => pendingCheck(fn, loadingValue));
959
- c.ba |= LOADING_BIT;
960
- return c.read();
974
+ c.j = () => c.write(false);
975
+ c.j.ia = () => globalQueue.enqueue(0, () => c.j.f && c.write(true));
976
+ c.ca |= LOADING_BIT;
977
+ const res = c.wait();
978
+ c.o = () => {
979
+ if (c.j.f) {
980
+ c.j.f.j.delete(c.j);
981
+ delete c.j.f;
982
+ }
983
+ };
984
+ return res;
961
985
  }
962
986
  function latest(fn, fallback) {
963
987
  const argLength = arguments.length;
@@ -978,10 +1002,10 @@ function latest(fn, fallback) {
978
1002
  function compute(owner, fn, observer) {
979
1003
  const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask, prevNotStale = notStale;
980
1004
  currentObserver = observer;
981
- currentMask = observer?.ba ?? DEFAULT_FLAGS;
1005
+ currentMask = observer?.ca ?? DEFAULT_FLAGS;
982
1006
  notStale = true;
983
1007
  try {
984
- return fn.call(observer, observer ? observer.l : void 0);
1008
+ return fn.call(observer, observer ? observer.m : void 0);
985
1009
  } finally {
986
1010
  setOwner(prevOwner);
987
1011
  currentObserver = prevObserver;
@@ -992,50 +1016,50 @@ function compute(owner, fn, observer) {
992
1016
 
993
1017
  // src/core/effect.ts
994
1018
  var Effect = class extends Computation {
995
- ca;
1019
+ da;
996
1020
  $;
997
1021
  w;
998
- da = false;
1022
+ ea = false;
999
1023
  T;
1000
1024
  s;
1001
1025
  constructor(initialValue, compute2, effect, error, options) {
1002
1026
  super(initialValue, compute2, options);
1003
- this.ca = effect;
1027
+ this.da = effect;
1004
1028
  this.$ = error;
1005
1029
  this.T = initialValue;
1006
1030
  this.s = options?.render ? EFFECT_RENDER : EFFECT_USER;
1007
1031
  if (this.s === EFFECT_RENDER) {
1008
1032
  this.P = function(p) {
1009
- return !this.d && clock > this.E.created && !(this.h & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
1033
+ return !this.d && clock > this.E.created && !(this.g & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
1010
1034
  };
1011
1035
  }
1012
1036
  this.F();
1013
1037
  !options?.defer && (this.s === EFFECT_USER ? getQueue(this).enqueue(this.s, this.x.bind(this)) : this.x(this.s));
1014
1038
  }
1015
1039
  write(value, flags = 0) {
1016
- if (this.b == STATE_DIRTY) {
1017
- this.h = flags;
1040
+ if (this.a == STATE_DIRTY) {
1041
+ this.g = flags;
1018
1042
  if (this.s === EFFECT_RENDER) {
1019
- getQueue(this).notify(this, LOADING_BIT | ERROR_BIT, this.h);
1043
+ getQueue(this).notify(this, LOADING_BIT | ERROR_BIT, this.g);
1020
1044
  }
1021
1045
  }
1022
1046
  if (value === UNCHANGED)
1023
- return this.l;
1024
- this.l = value;
1025
- this.da = true;
1047
+ return this.m;
1048
+ this.m = value;
1049
+ this.ea = true;
1026
1050
  this.O = void 0;
1027
1051
  return value;
1028
1052
  }
1029
1053
  u(state, skipQueue) {
1030
- if (this.b >= state || skipQueue)
1054
+ if (this.a >= state || skipQueue)
1031
1055
  return;
1032
- if (this.b === STATE_CLEAN || this.d && !ActiveTransition)
1056
+ if (this.a === STATE_CLEAN || this.d && !ActiveTransition)
1033
1057
  getQueue(this).enqueue(this.s, this.x.bind(this));
1034
- this.b = state;
1058
+ this.a = state;
1035
1059
  }
1036
1060
  _(mask, newFlags2) {
1037
1061
  if (this.d) {
1038
- if (this.b >= STATE_DIRTY)
1062
+ if (this.a >= STATE_DIRTY)
1039
1063
  return;
1040
1064
  if (mask & 3) {
1041
1065
  this.u(STATE_DIRTY);
@@ -1047,7 +1071,7 @@ var Effect = class extends Computation {
1047
1071
  N(error) {
1048
1072
  this.O = error;
1049
1073
  getQueue(this).notify(this, LOADING_BIT, 0);
1050
- this.h = ERROR_BIT;
1074
+ this.g = ERROR_BIT;
1051
1075
  if (this.s === EFFECT_USER) {
1052
1076
  try {
1053
1077
  return this.$ ? this.$(error, () => {
@@ -1062,9 +1086,9 @@ var Effect = class extends Computation {
1062
1086
  throw error;
1063
1087
  }
1064
1088
  M() {
1065
- if (this.b === STATE_DISPOSED)
1089
+ if (this.a === STATE_DISPOSED)
1066
1090
  return;
1067
- this.ca = void 0;
1091
+ this.da = void 0;
1068
1092
  this.T = void 0;
1069
1093
  this.$ = void 0;
1070
1094
  this.w?.();
@@ -1075,42 +1099,46 @@ var Effect = class extends Computation {
1075
1099
  x(type) {
1076
1100
  if (type) {
1077
1101
  const effect = this.d || this;
1078
- if (effect.da && effect.b !== STATE_DISPOSED) {
1102
+ if (effect.ea && effect.a !== STATE_DISPOSED) {
1079
1103
  effect.w?.();
1080
1104
  try {
1081
- effect.w = effect.ca(effect.l, effect.T);
1105
+ effect.w = effect.da(effect.m, effect.T);
1082
1106
  } catch (e) {
1083
1107
  if (!getQueue(effect).notify(effect, ERROR_BIT, ERROR_BIT))
1084
1108
  throw e;
1085
1109
  } finally {
1086
- effect.T = effect.l;
1087
- effect.da = false;
1110
+ effect.T = effect.m;
1111
+ effect.ea = false;
1088
1112
  }
1089
1113
  }
1090
1114
  } else
1091
- this.b !== STATE_CLEAN && runTop(this);
1115
+ this.a !== STATE_CLEAN && runTop(this);
1092
1116
  }
1093
1117
  };
1094
1118
  var TrackedEffect = class extends Computation {
1095
1119
  s = EFFECT_USER;
1096
1120
  w;
1097
1121
  constructor(compute2, options) {
1098
- super(void 0, () => {
1099
- this.w?.();
1100
- this.w = latest(compute2);
1101
- return void 0;
1102
- }, options);
1122
+ super(
1123
+ void 0,
1124
+ () => {
1125
+ this.w?.();
1126
+ this.w = latest(compute2);
1127
+ return void 0;
1128
+ },
1129
+ options
1130
+ );
1103
1131
  getQueue(this).enqueue(this.s, this.x.bind(this));
1104
1132
  }
1105
1133
  u(state, skipQueue) {
1106
- if (this.b >= state || skipQueue)
1134
+ if (this.a >= state || skipQueue)
1107
1135
  return;
1108
- if (this.b === STATE_CLEAN || this.d && !ActiveTransition)
1136
+ if (this.a === STATE_CLEAN || this.d && !ActiveTransition)
1109
1137
  getQueue(this).enqueue(this.s, this.x.bind(this));
1110
- this.b = state;
1138
+ this.a = state;
1111
1139
  }
1112
1140
  M() {
1113
- if (this.b === STATE_DISPOSED)
1141
+ if (this.a === STATE_DISPOSED)
1114
1142
  return;
1115
1143
  this.w?.();
1116
1144
  this.w = void 0;
@@ -1119,7 +1147,7 @@ var TrackedEffect = class extends Computation {
1119
1147
  }
1120
1148
  x(type) {
1121
1149
  if (type)
1122
- this.b !== STATE_CLEAN && runTop(this);
1150
+ this.a !== STATE_CLEAN && runTop(this);
1123
1151
  }
1124
1152
  };
1125
1153
  var EagerComputation = class extends Computation {
@@ -1128,14 +1156,14 @@ var EagerComputation = class extends Computation {
1128
1156
  !options?.defer && this.F();
1129
1157
  }
1130
1158
  u(state, skipQueue) {
1131
- if (this.b >= state && !this.H)
1159
+ if (this.a >= state && !this.H)
1132
1160
  return;
1133
- if (!skipQueue && (this.b === STATE_CLEAN || this.b === STATE_CHECK && this.H))
1161
+ if (!skipQueue && (this.a === STATE_CLEAN || this.a === STATE_CHECK && this.H))
1134
1162
  getQueue(this).enqueue(EFFECT_PURE, this.x.bind(this));
1135
1163
  super.u(state, skipQueue);
1136
1164
  }
1137
1165
  x() {
1138
- this.b !== STATE_CLEAN && runTop(this);
1166
+ this.a !== STATE_CLEAN && runTop(this);
1139
1167
  }
1140
1168
  };
1141
1169
  var FirewallComputation = class extends Computation {
@@ -1144,31 +1172,34 @@ var FirewallComputation = class extends Computation {
1144
1172
  super(void 0, compute2);
1145
1173
  }
1146
1174
  u(state, skipQueue) {
1147
- if (this.b >= state && !this.H)
1175
+ if (this.a >= state && !this.H)
1148
1176
  return;
1149
- if (!skipQueue && (this.b === STATE_CLEAN || this.b === STATE_CHECK && this.H))
1177
+ if (!skipQueue && (this.a === STATE_CLEAN || this.a === STATE_CHECK && this.H))
1150
1178
  getQueue(this).enqueue(EFFECT_PURE, this.x.bind(this));
1151
1179
  super.u(state, true);
1152
1180
  this.H = !!skipQueue;
1153
1181
  }
1154
1182
  x() {
1155
- const prevFlags = this.h;
1156
- this.b !== STATE_CLEAN && runTop(this);
1157
- if (ActiveTransition && this.r && this.h !== prevFlags)
1158
- getQueue(this).notify(this, LOADING_BIT | ERROR_BIT, this.h);
1183
+ const prevFlags = this.g;
1184
+ this.a !== STATE_CLEAN && runTop(this);
1185
+ if (ActiveTransition && this.j && (this.g !== prevFlags || this.g !== this.j.flags)) {
1186
+ getQueue(this).notify(this, LOADING_BIT | ERROR_BIT, this.g);
1187
+ this.j.flags = this.g;
1188
+ this.g = prevFlags;
1189
+ }
1159
1190
  }
1160
1191
  };
1161
1192
  function runTop(node) {
1162
1193
  const ancestors = [];
1163
- for (let current = node; current !== null; current = current.k) {
1164
- if (ActiveTransition && current.j)
1165
- current = ActiveTransition.a.get(current);
1166
- if (current.b !== STATE_CLEAN) {
1194
+ for (let current = node; current !== null; current = current.l) {
1195
+ if (ActiveTransition && current.f)
1196
+ current = ActiveTransition.b.get(current);
1197
+ if (current.a !== STATE_CLEAN) {
1167
1198
  ancestors.push(current);
1168
1199
  }
1169
1200
  }
1170
1201
  for (let i = ancestors.length - 1; i >= 0; i--) {
1171
- if (ancestors[i].b !== STATE_DISPOSED)
1202
+ if (ancestors[i].a !== STATE_DISPOSED)
1172
1203
  ancestors[i].F();
1173
1204
  }
1174
1205
  }
@@ -1177,10 +1208,13 @@ function runTop(node) {
1177
1208
  function createSignal(first, second, third) {
1178
1209
  if (typeof first === "function") {
1179
1210
  const node2 = new Computation(second, first, third);
1180
- return [node2.read.bind(node2), (v) => {
1181
- node2.F();
1182
- return node2.write(v);
1183
- }];
1211
+ return [
1212
+ node2.wait.bind(node2),
1213
+ (v) => {
1214
+ node2.F();
1215
+ return node2.write(v);
1216
+ }
1217
+ ];
1184
1218
  }
1185
1219
  const o = getOwner();
1186
1220
  const needsId = o?.id != null;
@@ -1200,12 +1234,12 @@ function createMemo(compute2, value, options) {
1200
1234
  let resolvedValue;
1201
1235
  return () => {
1202
1236
  if (node) {
1203
- if (node.b === STATE_DISPOSED) {
1237
+ if (node.a === STATE_DISPOSED) {
1204
1238
  node = void 0;
1205
1239
  return resolvedValue;
1206
1240
  }
1207
1241
  resolvedValue = node.wait();
1208
- if (!node.a?.length && node.m?.k !== node && !(node.h & UNINITIALIZED_BIT)) {
1242
+ if (!node.b?.length && node.n?.l !== node && !(node.g & UNINITIALIZED_BIT)) {
1209
1243
  node.dispose();
1210
1244
  node = void 0;
1211
1245
  }
@@ -1272,7 +1306,7 @@ function createAsync(compute2, value, options) {
1272
1306
  }
1273
1307
  })();
1274
1308
  }
1275
- throw new NotReadyError();
1309
+ throw new NotReadyError(getOwner());
1276
1310
  },
1277
1311
  options
1278
1312
  );
@@ -1282,7 +1316,7 @@ function createAsync(compute2, value, options) {
1282
1316
  if (ActiveTransition && !node.d) {
1283
1317
  n = cloneGraph(node);
1284
1318
  }
1285
- n.b = STATE_DIRTY;
1319
+ n.a = STATE_DIRTY;
1286
1320
  refreshing = true;
1287
1321
  n.F();
1288
1322
  };
@@ -1350,26 +1384,33 @@ function resolve(fn) {
1350
1384
  });
1351
1385
  }
1352
1386
  function createOptimistic(first, second, third) {
1353
- const node = typeof first === "function" ? new Computation(second, (prev) => {
1354
- const res = first(prev);
1355
- if (reset.j)
1356
- return prev;
1357
- return res;
1358
- }, third) : new Computation(first, null, second);
1359
- node.r = true;
1360
- const reset = () => node.write(first);
1387
+ const node = typeof first === "function" ? new Computation(
1388
+ second,
1389
+ (prev) => {
1390
+ const res = first(prev);
1391
+ if (node.j.f)
1392
+ return prev;
1393
+ return res;
1394
+ },
1395
+ third
1396
+ ) : new Computation(first, null, second);
1397
+ node.j = () => node.write(first);
1361
1398
  function write(v) {
1362
1399
  if (!ActiveTransition)
1363
1400
  throw new Error("createOptimistic can only be updated inside a transition");
1364
- ActiveTransition.addOptimistic(reset);
1401
+ ActiveTransition.addOptimistic(node.j);
1365
1402
  queueMicrotask(() => {
1366
- if (reset.j) {
1403
+ if (node.j.f) {
1367
1404
  node.F();
1368
1405
  node.write(v);
1369
1406
  }
1370
1407
  });
1371
1408
  }
1372
- return [node.read.bind(node), write];
1409
+ return [node.wait.bind(node), write];
1410
+ }
1411
+ function transition(fn) {
1412
+ let t = new Transition(new Computation(void 0, null));
1413
+ queueMicrotask(() => t.runTransition(() => fn((fn2) => t.runTransition(fn2))));
1373
1414
  }
1374
1415
  function useTransition() {
1375
1416
  const [pending, setPending] = createOptimistic(false);
@@ -1649,7 +1690,7 @@ var storeTraps = {
1649
1690
  return desc.get.call(receiver);
1650
1691
  }
1651
1692
  if (Writing?.has(receiver)) {
1652
- let value2 = tracked && (overridden || !proxySource) ? tracked.l : storeValue[property];
1693
+ let value2 = tracked && (overridden || !proxySource) ? tracked.m : storeValue[property];
1653
1694
  value2 === $DELETED && (value2 = void 0);
1654
1695
  if (!isWrappable(value2))
1655
1696
  return value2;
@@ -1840,28 +1881,28 @@ function deep(store) {
1840
1881
  // src/store/optimistic.ts
1841
1882
  function createOptimisticStore(first, second, options) {
1842
1883
  const derived = typeof first === "function";
1843
- const { store, node } = derived ? createProjectionInternal((draft) => {
1844
- const res = first(draft);
1845
- if (reset.j)
1846
- return draft;
1847
- return res;
1848
- }, second, options) : createProjectionInternal(() => {
1884
+ const { store, node } = derived ? createProjectionInternal(
1885
+ (draft) => {
1886
+ const res = first(draft);
1887
+ if (reset.f)
1888
+ return draft;
1889
+ return res;
1890
+ },
1891
+ second,
1892
+ options
1893
+ ) : createProjectionInternal(() => {
1849
1894
  }, first);
1850
- node.r = true;
1851
1895
  const reset = () => storeSetter(
1852
1896
  store,
1853
- reconcile(
1854
- derived ? first(store) || store : first,
1855
- options?.key || "id",
1856
- options?.all
1857
- )
1897
+ reconcile(derived ? first(store) || store : first, options?.key || "id", options?.all)
1858
1898
  );
1859
1899
  const write = (v) => {
1860
1900
  if (!ActiveTransition)
1861
1901
  throw new Error("createOptimisticStore can only be updated inside a transition");
1862
1902
  ActiveTransition.addOptimistic(reset);
1863
- queueMicrotask(() => reset.j && storeSetter(store, v));
1903
+ queueMicrotask(() => reset.f && storeSetter(store, v));
1864
1904
  };
1905
+ node.j = reset;
1865
1906
  return [store, write];
1866
1907
  }
1867
1908
 
@@ -2070,75 +2111,75 @@ function mapArray(list, map, options) {
2070
2111
  const keyFn = typeof options?.keyed === "function" ? options.keyed : void 0;
2071
2112
  return updateKeyedMap.bind({
2072
2113
  U: new Owner(),
2073
- o: 0,
2074
- ia: list,
2114
+ p: 0,
2115
+ ka: list,
2075
2116
  I: [],
2076
2117
  R: map,
2077
- i: [],
2118
+ k: [],
2078
2119
  e: [],
2079
2120
  S: keyFn,
2080
- p: keyFn || options?.keyed === false ? [] : void 0,
2081
- q: map.length > 1 ? [] : void 0,
2121
+ q: keyFn || options?.keyed === false ? [] : void 0,
2122
+ r: map.length > 1 ? [] : void 0,
2082
2123
  V: options?.fallback
2083
2124
  });
2084
2125
  }
2085
2126
  var pureOptions = { pureWrite: true };
2086
2127
  function updateKeyedMap() {
2087
- const newItems = this.ia() || [], newLen = newItems.length;
2128
+ const newItems = this.ka() || [], newLen = newItems.length;
2088
2129
  newItems[$TRACK];
2089
2130
  runWithOwner(this.U, () => {
2090
- let i, j, mapper = this.p ? () => {
2091
- this.p[j] = new Computation(newItems[j], null, pureOptions);
2092
- this.q && (this.q[j] = new Computation(j, null, pureOptions));
2131
+ let i, j, mapper = this.q ? () => {
2132
+ this.q[j] = new Computation(newItems[j], null, pureOptions);
2133
+ this.r && (this.r[j] = new Computation(j, null, pureOptions));
2093
2134
  return this.R(
2094
- Computation.prototype.read.bind(this.p[j]),
2095
- this.q ? Computation.prototype.read.bind(this.q[j]) : void 0
2135
+ Computation.prototype.read.bind(this.q[j]),
2136
+ this.r ? Computation.prototype.read.bind(this.r[j]) : void 0
2096
2137
  );
2097
- } : this.q ? () => {
2138
+ } : this.r ? () => {
2098
2139
  const item = newItems[j];
2099
- this.q[j] = new Computation(j, null, pureOptions);
2100
- return this.R(() => item, Computation.prototype.read.bind(this.q[j]));
2140
+ this.r[j] = new Computation(j, null, pureOptions);
2141
+ return this.R(() => item, Computation.prototype.read.bind(this.r[j]));
2101
2142
  } : () => {
2102
2143
  const item = newItems[j];
2103
2144
  return this.R(() => item);
2104
2145
  };
2105
2146
  if (newLen === 0) {
2106
- if (this.o !== 0) {
2147
+ if (this.p !== 0) {
2107
2148
  this.U.dispose(false);
2108
2149
  this.e = [];
2109
2150
  this.I = [];
2110
- this.i = [];
2111
- this.o = 0;
2112
- this.p && (this.p = []);
2151
+ this.k = [];
2152
+ this.p = 0;
2113
2153
  this.q && (this.q = []);
2154
+ this.r && (this.r = []);
2114
2155
  }
2115
- if (this.V && !this.i[0]) {
2116
- this.i[0] = compute(
2156
+ if (this.V && !this.k[0]) {
2157
+ this.k[0] = compute(
2117
2158
  this.e[0] = new Owner(),
2118
2159
  this.V,
2119
2160
  null
2120
2161
  );
2121
2162
  }
2122
- } else if (this.o === 0) {
2163
+ } else if (this.p === 0) {
2123
2164
  if (this.e[0])
2124
2165
  this.e[0].dispose();
2125
- this.i = new Array(newLen);
2166
+ this.k = new Array(newLen);
2126
2167
  for (j = 0; j < newLen; j++) {
2127
2168
  this.I[j] = newItems[j];
2128
- this.i[j] = compute(this.e[j] = new Owner(), mapper, null);
2169
+ this.k[j] = compute(this.e[j] = new Owner(), mapper, null);
2129
2170
  }
2130
- this.o = newLen;
2171
+ this.p = newLen;
2131
2172
  } else {
2132
- let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.p ? new Array(newLen) : void 0, tempIndexes = this.q ? new Array(newLen) : void 0;
2133
- for (start = 0, end = Math.min(this.o, newLen); start < end && (this.I[start] === newItems[start] || this.p && compare(this.S, this.I[start], newItems[start])); start++) {
2134
- if (this.p)
2135
- this.p[start].write(newItems[start]);
2173
+ let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.q ? new Array(newLen) : void 0, tempIndexes = this.r ? new Array(newLen) : void 0;
2174
+ for (start = 0, end = Math.min(this.p, newLen); start < end && (this.I[start] === newItems[start] || this.q && compare(this.S, this.I[start], newItems[start])); start++) {
2175
+ if (this.q)
2176
+ this.q[start].write(newItems[start]);
2136
2177
  }
2137
- for (end = this.o - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.I[end] === newItems[newEnd] || this.p && compare(this.S, this.I[end], newItems[newEnd])); end--, newEnd--) {
2138
- temp[newEnd] = this.i[end];
2178
+ 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--) {
2179
+ temp[newEnd] = this.k[end];
2139
2180
  tempNodes[newEnd] = this.e[end];
2140
- tempRows && (tempRows[newEnd] = this.p[end]);
2141
- tempIndexes && (tempIndexes[newEnd] = this.q[end]);
2181
+ tempRows && (tempRows[newEnd] = this.q[end]);
2182
+ tempIndexes && (tempIndexes[newEnd] = this.r[end]);
2142
2183
  }
2143
2184
  newIndices = /* @__PURE__ */ new Map();
2144
2185
  newIndicesNext = new Array(newEnd + 1);
@@ -2154,10 +2195,10 @@ function updateKeyedMap() {
2154
2195
  key = this.S ? this.S(item) : item;
2155
2196
  j = newIndices.get(key);
2156
2197
  if (j !== void 0 && j !== -1) {
2157
- temp[j] = this.i[i];
2198
+ temp[j] = this.k[i];
2158
2199
  tempNodes[j] = this.e[i];
2159
- tempRows && (tempRows[j] = this.p[i]);
2160
- tempIndexes && (tempIndexes[j] = this.q[i]);
2200
+ tempRows && (tempRows[j] = this.q[i]);
2201
+ tempIndexes && (tempIndexes[j] = this.r[i]);
2161
2202
  j = newIndicesNext[j];
2162
2203
  newIndices.set(key, j);
2163
2204
  } else
@@ -2165,52 +2206,52 @@ function updateKeyedMap() {
2165
2206
  }
2166
2207
  for (j = start; j < newLen; j++) {
2167
2208
  if (j in temp) {
2168
- this.i[j] = temp[j];
2209
+ this.k[j] = temp[j];
2169
2210
  this.e[j] = tempNodes[j];
2170
2211
  if (tempRows) {
2171
- this.p[j] = tempRows[j];
2172
- this.p[j].write(newItems[j]);
2212
+ this.q[j] = tempRows[j];
2213
+ this.q[j].write(newItems[j]);
2173
2214
  }
2174
2215
  if (tempIndexes) {
2175
- this.q[j] = tempIndexes[j];
2176
- this.q[j].write(j);
2216
+ this.r[j] = tempIndexes[j];
2217
+ this.r[j].write(j);
2177
2218
  }
2178
2219
  } else {
2179
- this.i[j] = compute(this.e[j] = new Owner(), mapper, null);
2220
+ this.k[j] = compute(this.e[j] = new Owner(), mapper, null);
2180
2221
  }
2181
2222
  }
2182
- this.i = this.i.slice(0, this.o = newLen);
2223
+ this.k = this.k.slice(0, this.p = newLen);
2183
2224
  this.I = newItems.slice(0);
2184
2225
  }
2185
2226
  });
2186
- return this.i;
2227
+ return this.k;
2187
2228
  }
2188
2229
  function repeat(count, map, options) {
2189
2230
  return updateRepeat.bind({
2190
2231
  U: new Owner(),
2191
- o: 0,
2232
+ p: 0,
2192
2233
  B: 0,
2193
- ja: count,
2234
+ la: count,
2194
2235
  R: map,
2195
2236
  e: [],
2196
- i: [],
2197
- ka: options?.from,
2237
+ k: [],
2238
+ ma: options?.from,
2198
2239
  V: options?.fallback
2199
2240
  });
2200
2241
  }
2201
2242
  function updateRepeat() {
2202
- const newLen = this.ja();
2203
- const from = this.ka?.() || 0;
2243
+ const newLen = this.la();
2244
+ const from = this.ma?.() || 0;
2204
2245
  runWithOwner(this.U, () => {
2205
2246
  if (newLen === 0) {
2206
- if (this.o !== 0) {
2247
+ if (this.p !== 0) {
2207
2248
  this.U.dispose(false);
2208
2249
  this.e = [];
2209
- this.i = [];
2210
- this.o = 0;
2250
+ this.k = [];
2251
+ this.p = 0;
2211
2252
  }
2212
- if (this.V && !this.i[0]) {
2213
- this.i[0] = compute(
2253
+ if (this.V && !this.k[0]) {
2254
+ this.k[0] = compute(
2214
2255
  this.e[0] = new Owner(),
2215
2256
  this.V,
2216
2257
  null
@@ -2219,28 +2260,28 @@ function updateRepeat() {
2219
2260
  return;
2220
2261
  }
2221
2262
  const to = from + newLen;
2222
- const prevTo = this.B + this.o;
2223
- if (this.o === 0 && this.e[0])
2263
+ const prevTo = this.B + this.p;
2264
+ if (this.p === 0 && this.e[0])
2224
2265
  this.e[0].dispose();
2225
2266
  for (let i = to; i < prevTo; i++)
2226
2267
  this.e[i - this.B].dispose();
2227
2268
  if (this.B < from) {
2228
2269
  let i = this.B;
2229
- while (i < from && i < this.o)
2270
+ while (i < from && i < this.p)
2230
2271
  this.e[i++].dispose();
2231
2272
  this.e.splice(0, from - this.B);
2232
- this.i.splice(0, from - this.B);
2273
+ this.k.splice(0, from - this.B);
2233
2274
  } else if (this.B > from) {
2234
2275
  let i = prevTo - this.B - 1;
2235
2276
  let difference = this.B - from;
2236
- this.e.length = this.i.length = newLen;
2277
+ this.e.length = this.k.length = newLen;
2237
2278
  while (i >= difference) {
2238
2279
  this.e[i] = this.e[i - difference];
2239
- this.i[i] = this.i[i - difference];
2280
+ this.k[i] = this.k[i - difference];
2240
2281
  i--;
2241
2282
  }
2242
2283
  for (let i2 = 0; i2 < difference; i2++) {
2243
- this.i[i2] = compute(
2284
+ this.k[i2] = compute(
2244
2285
  this.e[i2] = new Owner(),
2245
2286
  () => this.R(i2 + from),
2246
2287
  null
@@ -2248,17 +2289,17 @@ function updateRepeat() {
2248
2289
  }
2249
2290
  }
2250
2291
  for (let i = prevTo; i < to; i++) {
2251
- this.i[i - from] = compute(
2292
+ this.k[i - from] = compute(
2252
2293
  this.e[i - from] = new Owner(),
2253
2294
  () => this.R(i),
2254
2295
  null
2255
2296
  );
2256
2297
  }
2257
- this.i = this.i.slice(0, newLen);
2298
+ this.k = this.k.slice(0, newLen);
2258
2299
  this.B = from;
2259
- this.o = newLen;
2300
+ this.p = newLen;
2260
2301
  });
2261
- return this.i;
2302
+ return this.k;
2262
2303
  }
2263
2304
  function compare(key, a, b) {
2264
2305
  return key ? key(a) === key(b) : true;
@@ -2273,11 +2314,11 @@ var BoundaryComputation = class extends EagerComputation {
2273
2314
  }
2274
2315
  write(value, flags) {
2275
2316
  super.write(value, flags & ~this.W);
2276
- if (this.W & LOADING_BIT && !(this.h & UNINITIALIZED_BIT || ActiveTransition)) {
2317
+ if (this.W & LOADING_BIT && !(this.g & UNINITIALIZED_BIT || ActiveTransition)) {
2277
2318
  flags &= ~LOADING_BIT;
2278
2319
  }
2279
2320
  getQueue(this).notify(this, this.W, flags);
2280
- return this.l;
2321
+ return this.m;
2281
2322
  }
2282
2323
  };
2283
2324
  function createBoundChildren(owner, fn, queue, mask) {
@@ -2288,7 +2329,7 @@ function createBoundChildren(owner, fn, queue, mask) {
2288
2329
  owner,
2289
2330
  () => {
2290
2331
  const c = new Computation(void 0, fn);
2291
- return new BoundaryComputation(() => flatten(c.wait()), mask);
2332
+ return new BoundaryComputation(() => latest(() => flatten(c.wait())), mask);
2292
2333
  },
2293
2334
  null
2294
2335
  );
@@ -2407,7 +2448,7 @@ function createErrorBoundary(fn, fallback) {
2407
2448
  for (let node2 of queue.e) {
2408
2449
  if (ActiveTransition && !node2.d)
2409
2450
  node2 = cloneGraph(node2);
2410
- node2.b = STATE_DIRTY;
2451
+ node2.a = STATE_DIRTY;
2411
2452
  getQueue(node2).enqueue(node2.s, node2.x.bind(node2));
2412
2453
  }
2413
2454
  });