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