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