@solidjs/signals 0.6.3 → 0.7.0

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
@@ -47,14 +47,14 @@ function schedule() {
47
47
  if (scheduled)
48
48
  return;
49
49
  scheduled = true;
50
- if (!globalQueue.A)
50
+ if (!globalQueue.B)
51
51
  queueMicrotask(flush);
52
52
  }
53
53
  function notifyUnobserved() {
54
54
  var _a, _b;
55
55
  for (let i = 0; i < Unobserved.length; i++) {
56
56
  const source = Unobserved[i];
57
- if (!source.b || !source.b.length)
57
+ if (!source.c || !source.c.length)
58
58
  (_b = (_a = Unobserved[i]).ea) == null ? void 0 : _b.call(_a);
59
59
  }
60
60
  Unobserved = [];
@@ -62,7 +62,7 @@ function notifyUnobserved() {
62
62
  var pureQueue = [];
63
63
  var Queue = class {
64
64
  k = null;
65
- A = false;
65
+ B = false;
66
66
  g = [[], []];
67
67
  f = [];
68
68
  created = clock;
@@ -87,9 +87,9 @@ var Queue = class {
87
87
  }
88
88
  }
89
89
  flush() {
90
- if (this.A)
90
+ if (this.B)
91
91
  return;
92
- this.A = true;
92
+ this.B = true;
93
93
  try {
94
94
  this.run(EFFECT_PURE);
95
95
  incrementClock();
@@ -97,19 +97,19 @@ var Queue = class {
97
97
  this.run(EFFECT_RENDER);
98
98
  this.run(EFFECT_USER);
99
99
  } finally {
100
- this.A = false;
100
+ this.B = false;
101
101
  Unobserved.length && notifyUnobserved();
102
102
  }
103
103
  }
104
104
  addChild(child) {
105
- if (ActiveTransition && ActiveTransition.r.has(this))
106
- return ActiveTransition.r.get(this).addChild(child);
105
+ if (ActiveTransition && ActiveTransition.G.has(this))
106
+ return ActiveTransition.G.get(this).addChild(child);
107
107
  this.f.push(child);
108
108
  child.k = this;
109
109
  }
110
110
  removeChild(child) {
111
- if (ActiveTransition && ActiveTransition.r.has(this))
112
- return ActiveTransition.r.get(this).removeChild(child);
111
+ if (ActiveTransition && ActiveTransition.G.has(this))
112
+ return ActiveTransition.G.get(this).removeChild(child);
113
113
  const index = this.f.indexOf(child);
114
114
  if (index >= 0) {
115
115
  this.f.splice(index, 1);
@@ -125,7 +125,7 @@ var Queue = class {
125
125
  this.g[0].push.apply(this.g[0], queue.g[0]);
126
126
  this.g[1].push.apply(this.g[1], queue.g[1]);
127
127
  for (let i = 0; i < queue.f.length; i++) {
128
- const og = this.f.find((c) => c.e === queue.f[i].e);
128
+ const og = this.f.find((c) => c.d === queue.f[i].d);
129
129
  if (og)
130
130
  og.merge(queue.f[i]);
131
131
  else
@@ -144,12 +144,12 @@ function removeSourceObservers(node, index) {
144
144
  let swap;
145
145
  for (let i = index; i < node.a.length; i++) {
146
146
  source = getTransitionSource(node.a[i]);
147
- if (source.b) {
148
- if ((swap = source.b.indexOf(node)) !== -1) {
149
- source.b[swap] = source.b[source.b.length - 1];
150
- source.b.pop();
147
+ if (source.c) {
148
+ if ((swap = source.c.indexOf(node)) !== -1) {
149
+ source.c[swap] = source.c[source.c.length - 1];
150
+ source.c.pop();
151
151
  }
152
- if (!source.b.length)
152
+ if (!source.c.length)
153
153
  Unobserved.push(source);
154
154
  }
155
155
  }
@@ -162,33 +162,33 @@ var Transition = class _Transition {
162
162
  a = /* @__PURE__ */ new Map();
163
163
  s = /* @__PURE__ */ new Set();
164
164
  H = /* @__PURE__ */ new Set();
165
- W = /* @__PURE__ */ new Set();
166
- u = false;
165
+ I = /* @__PURE__ */ new Set();
166
+ D = false;
167
167
  g = [[], []];
168
- r = /* @__PURE__ */ new Map();
169
- I = [];
168
+ G = /* @__PURE__ */ new Map();
169
+ J = [];
170
170
  f = [];
171
171
  k = null;
172
- A = false;
173
- X = false;
174
- e = globalQueue;
172
+ B = false;
173
+ Y = false;
174
+ d = globalQueue;
175
175
  created = clock;
176
176
  constructor() {
177
- this.r.set(globalQueue, this);
177
+ this.G.set(globalQueue, this);
178
178
  for (const child of globalQueue.f) {
179
- cloneQueue(child, this, this.r);
179
+ cloneQueue(child, this, this);
180
180
  }
181
181
  }
182
182
  enqueue(type, fn) {
183
- this.I.push(fn);
183
+ this.J.push(fn);
184
184
  if (type)
185
185
  this.g[type - 1].push(fn);
186
186
  this.schedule();
187
187
  }
188
188
  run(type) {
189
189
  if (type === EFFECT_PURE) {
190
- this.I.length && runQueue(this.I, type);
191
- this.I = [];
190
+ this.J.length && runQueue(this.J, type);
191
+ this.J = [];
192
192
  return;
193
193
  } else if (this.g[type - 1].length) {
194
194
  const effects = this.g[type - 1];
@@ -200,19 +200,19 @@ var Transition = class _Transition {
200
200
  }
201
201
  }
202
202
  flush() {
203
- if (this.A)
203
+ if (this.B)
204
204
  return;
205
- this.A = true;
205
+ this.B = true;
206
206
  let currentTransition = ActiveTransition;
207
207
  ActiveTransition = this;
208
208
  try {
209
209
  this.run(EFFECT_PURE);
210
210
  incrementClock();
211
- this.X = false;
211
+ this.Y = false;
212
212
  ActiveTransition = currentTransition;
213
213
  finishTransition(this);
214
214
  } finally {
215
- this.A = false;
215
+ this.B = false;
216
216
  ActiveTransition = currentTransition;
217
217
  }
218
218
  }
@@ -238,9 +238,9 @@ var Transition = class _Transition {
238
238
  merge(queue) {
239
239
  this.g[0].push.apply(this.g[0], queue.g[0]);
240
240
  this.g[1].push.apply(this.g[1], queue.g[1]);
241
- this.I.push.apply(this.I, queue.I);
241
+ this.J.push.apply(this.J, queue.J);
242
242
  for (let i = 0; i < queue.f.length; i++) {
243
- const og = this.f.find((c) => c.e === queue.f[i].e);
243
+ const og = this.f.find((c) => c.d === queue.f[i].d);
244
244
  if (og)
245
245
  og.merge(queue.f[i]);
246
246
  else
@@ -248,16 +248,16 @@ var Transition = class _Transition {
248
248
  }
249
249
  }
250
250
  schedule() {
251
- if (this.X)
251
+ if (this.Y)
252
252
  return;
253
- this.X = true;
254
- if (!this.A)
253
+ this.Y = true;
254
+ if (!this.B)
255
255
  queueMicrotask(() => this.flush());
256
256
  }
257
257
  runTransition(fn, force = false) {
258
- if (this.u) {
259
- if (this.u instanceof _Transition)
260
- return this.u.runTransition(fn, force);
258
+ if (this.D) {
259
+ if (this.D instanceof _Transition)
260
+ return this.D.runTransition(fn, force);
261
261
  if (!force)
262
262
  throw new Error("Transition already completed");
263
263
  fn();
@@ -276,8 +276,7 @@ var Transition = class _Transition {
276
276
  try {
277
277
  value = await temp.value;
278
278
  } finally {
279
- while (transition2.u instanceof _Transition)
280
- transition2 = transition2.u;
279
+ transition2 = latestTransition(transition2);
281
280
  transition2.H.delete(temp.value);
282
281
  }
283
282
  ActiveTransition = transition2;
@@ -291,8 +290,7 @@ var Transition = class _Transition {
291
290
  if (result instanceof Promise) {
292
291
  transition2.H.add(result);
293
292
  result.finally(() => {
294
- while (transition2.u instanceof _Transition)
295
- transition2 = transition2.u;
293
+ transition2 = latestTransition(transition2);
296
294
  transition2.H.delete(result);
297
295
  ActiveTransition = null;
298
296
  finishTransition(transition2);
@@ -311,14 +309,14 @@ var Transition = class _Transition {
311
309
  return;
312
310
  }
313
311
  fn.j = this;
314
- this.W.add(fn);
312
+ this.I.add(fn);
315
313
  }
316
314
  };
317
315
  function transition(fn) {
318
316
  let t = new Transition();
319
317
  queueMicrotask(() => t.runTransition(() => fn((fn2) => t.runTransition(fn2))));
320
318
  }
321
- function cloneGraph(node) {
319
+ function cloneGraph(node, optimistic) {
322
320
  if (node.j) {
323
321
  if (node.j !== ActiveTransition) {
324
322
  mergeTransitions(node.j, ActiveTransition);
@@ -330,50 +328,60 @@ function cloneGraph(node) {
330
328
  Object.assign(clone, node, {
331
329
  n: null,
332
330
  m: null,
333
- b: null,
331
+ c: null,
334
332
  a: node.a ? [...node.a] : null,
335
- e: node
333
+ d: node,
334
+ I: !!optimistic
336
335
  });
336
+ delete clone.T;
337
337
  ActiveTransition.a.set(node, clone);
338
338
  node.j = ActiveTransition;
339
- if (node.a) {
339
+ if (!optimistic && node.a) {
340
340
  for (let i = 0; i < node.a.length; i++)
341
- node.a[i].b.push(clone);
341
+ node.a[i].c.push(clone);
342
342
  }
343
- if (node.b) {
344
- clone.b = [];
345
- for (let i = 0, length = node.b.length; i < length; i++) {
346
- !node.b[i].e && clone.b.push(cloneGraph(node.b[i]));
343
+ if (node.c) {
344
+ clone.c = [];
345
+ for (let i = 0, length = node.c.length; i < length; i++) {
346
+ !node.c[i].d && clone.c.push(cloneGraph(node.c[i], optimistic));
347
347
  }
348
348
  }
349
349
  return clone;
350
350
  }
351
+ function latestTransition(t) {
352
+ while (t.D instanceof Transition)
353
+ t = t.D;
354
+ return t;
355
+ }
351
356
  function replaceSourceObservers(node, transition2) {
352
357
  let source;
358
+ let transitionSource;
353
359
  let swap;
354
360
  for (let i = 0; i < node.a.length; i++) {
355
- source = transition2.a.get(node.a[i]) || node.a[i];
356
- if (source.b && (swap = source.b.indexOf(node)) !== -1) {
357
- const remove = source.b.indexOf(node.e) > -1;
358
- source.b[swap] = !remove ? node.e : source.b[source.b.length - 1];
359
- remove && source.b.pop();
361
+ transitionSource = transition2.a.get(node.a[i]);
362
+ source = transitionSource || node.a[i];
363
+ if (source.c && (swap = source.c.indexOf(node)) !== -1) {
364
+ source.c[swap] = transitionSource ? node.d : source.c[source.c.length - 1];
365
+ !transitionSource && source.c.pop();
360
366
  }
361
367
  }
362
368
  }
363
- function cloneQueue(queue, parent, clonedQueues) {
369
+ function cloneQueue(queue, parent, transition2) {
364
370
  const clone = Object.create(Object.getPrototypeOf(queue));
365
371
  Object.assign(clone, queue, {
366
- e: queue,
372
+ d: queue,
367
373
  k: parent,
368
374
  f: [],
369
375
  enqueue(type, fn) {
370
- ActiveTransition == null ? void 0 : ActiveTransition.enqueue(type, fn);
376
+ transition2 = latestTransition(transition2);
377
+ transition2.enqueue(type, fn);
371
378
  },
372
379
  notify(node, type, flags) {
373
- node = node.e || node;
374
- if (!clone.J || type & LOADING_BIT) {
380
+ node = node.d || node;
381
+ if (!clone.K || type & LOADING_BIT) {
375
382
  type &= ~LOADING_BIT;
376
- ActiveTransition == null ? void 0 : ActiveTransition.notify(node, LOADING_BIT, flags);
383
+ transition2 = latestTransition(transition2);
384
+ transition2.notify(node, LOADING_BIT, flags);
377
385
  if (!type)
378
386
  return true;
379
387
  }
@@ -381,14 +389,14 @@ function cloneQueue(queue, parent, clonedQueues) {
381
389
  }
382
390
  });
383
391
  parent.f.push(clone);
384
- clonedQueues.set(queue, clone);
392
+ transition2.G.set(queue, clone);
385
393
  for (const child of queue.f) {
386
- cloneQueue(child, clone, clonedQueues);
394
+ cloneQueue(child, clone, transition2);
387
395
  }
388
396
  }
389
397
  function resolveQueues(children) {
390
398
  for (const child of children) {
391
- const og = child.e;
399
+ const og = child.d;
392
400
  if (og) {
393
401
  const clonedChildren = child.f;
394
402
  delete child.enqueue;
@@ -396,10 +404,10 @@ function resolveQueues(children) {
396
404
  delete child.k;
397
405
  delete child.f;
398
406
  Object.assign(og, child);
399
- delete og.e;
407
+ delete og.d;
400
408
  resolveQueues(clonedChildren);
401
- } else if (child.k.e) {
402
- child.k.e.addChild(child);
409
+ } else if (child.k.d) {
410
+ child.k.d.addChild(child);
403
411
  }
404
412
  }
405
413
  }
@@ -408,35 +416,35 @@ function mergeTransitions(t1, t2) {
408
416
  key.j = t1;
409
417
  t1.a.set(key, value);
410
418
  });
411
- t2.W.forEach((c) => {
419
+ t2.I.forEach((c) => {
412
420
  c.j = t1;
413
- t1.W.add(c);
421
+ t1.I.add(c);
414
422
  });
415
423
  t2.H.forEach((p) => t1.H.add(p));
416
424
  t2.s.forEach((n) => t1.s.add(n));
417
425
  t1.merge(t2);
418
- t2.u = t1;
426
+ t2.D = t1;
419
427
  }
420
428
  function getTransitionSource(input) {
421
429
  return ActiveTransition && ActiveTransition.a.get(input) || input;
422
430
  }
423
431
  function getQueue(node) {
424
432
  var _a;
425
- const transition2 = ActiveTransition || ((_a = node.e) == null ? void 0 : _a.j);
426
- return transition2 && transition2.r.get(node.B) || node.B;
433
+ const transition2 = ActiveTransition || ((_a = node.d) == null ? void 0 : _a.j);
434
+ return transition2 && transition2.G.get(node.C) || node.C;
427
435
  }
428
436
  function initialDispose(node) {
429
437
  let current = node.m;
430
438
  while (current !== null && current.k === node) {
431
439
  initialDispose(current);
432
440
  const clone = ActiveTransition.a.get(current);
433
- if (clone && !clone.Y)
441
+ if (clone && !clone.Z)
434
442
  clone.dispose(true);
435
443
  current = current.m;
436
444
  }
437
445
  }
438
446
  function finishTransition(transition2) {
439
- if (transition2.u || transition2.X || transition2.H.size || transition2.s.size)
447
+ if (transition2.D || transition2.Y || transition2.H.size || transition2.s.size)
440
448
  return;
441
449
  globalQueue.g[0].push.apply(globalQueue.g[0], transition2.g[0]);
442
450
  globalQueue.g[1].push.apply(globalQueue.g[1], transition2.g[1]);
@@ -448,27 +456,33 @@ function finishTransition(transition2) {
448
456
  }
449
457
  if (clone.a)
450
458
  replaceSourceObservers(clone, transition2);
451
- if (clone.Y || clone.c === STATE_DISPOSED) {
452
- source.dispose(clone.c === STATE_DISPOSED);
459
+ if (clone.I) {
460
+ clone.dispose();
461
+ clone.emptyDisposal();
462
+ delete source.j;
463
+ continue;
464
+ }
465
+ if (clone.Z || clone.b === STATE_DISPOSED) {
466
+ source.dispose(clone.b === STATE_DISPOSED);
453
467
  source.emptyDisposal();
454
- delete clone.Y;
468
+ delete clone.Z;
455
469
  } else {
456
470
  delete clone.m;
457
471
  delete clone.n;
458
472
  }
459
473
  Object.assign(source, clone);
460
- delete source.e;
474
+ delete source.d;
461
475
  let current = clone.m;
462
- if ((current == null ? void 0 : current.w) === clone)
463
- current.w = source;
476
+ if ((current == null ? void 0 : current.y) === clone)
477
+ current.y = source;
464
478
  while ((current == null ? void 0 : current.k) === clone) {
465
479
  current.k = source;
466
480
  current = current.m;
467
481
  }
468
482
  delete source.j;
469
483
  }
470
- transition2.u = true;
471
- for (const reset of transition2.W) {
484
+ transition2.D = true;
485
+ for (const reset of transition2.I) {
472
486
  delete reset.j;
473
487
  reset();
474
488
  }
@@ -492,11 +506,11 @@ var Owner = class {
492
506
  // See comment at the top of the file for an example of the _nextSibling traversal
493
507
  k = null;
494
508
  m = null;
495
- w = null;
496
- c = STATE_CLEAN;
509
+ y = null;
510
+ b = STATE_CLEAN;
497
511
  n = null;
498
- x = defaultContext;
499
- B = globalQueue;
512
+ z = defaultContext;
513
+ C = globalQueue;
500
514
  fa = 0;
501
515
  id = null;
502
516
  constructor(id = null, skipAppend = false) {
@@ -507,23 +521,23 @@ var Owner = class {
507
521
  }
508
522
  append(child) {
509
523
  child.k = this;
510
- child.w = this;
524
+ child.y = this;
511
525
  if (this.m)
512
- this.m.w = child;
526
+ this.m.y = child;
513
527
  child.m = this.m;
514
528
  this.m = child;
515
529
  if (this.id != null && child.id == null)
516
530
  child.id = this.getNextChildId();
517
- if (child.x !== this.x) {
518
- child.x = { ...this.x, ...child.x };
531
+ if (child.z !== this.z) {
532
+ child.z = { ...this.z, ...child.z };
519
533
  }
520
- if (this.B)
521
- child.B = this.B;
534
+ if (this.C)
535
+ child.C = this.C;
522
536
  }
523
537
  dispose(self = true) {
524
- if (this.c === STATE_DISPOSED)
538
+ if (this.b === STATE_DISPOSED)
525
539
  return;
526
- let head = self ? this.w || this.k : this, current = this.m, next = null;
540
+ let head = self ? this.y || this.k : this, current = this.m, next = null;
527
541
  while (current && current.k === this) {
528
542
  current.dispose(true);
529
543
  next = current.m;
@@ -532,19 +546,19 @@ var Owner = class {
532
546
  }
533
547
  this.fa = 0;
534
548
  if (self)
535
- this.R();
549
+ this.L();
536
550
  if (current)
537
- current.w = !self ? this : this.w;
551
+ current.y = !self ? this : this.y;
538
552
  if (head)
539
553
  head.m = current;
540
554
  }
541
- R() {
542
- if (this.w)
543
- this.w.m = null;
555
+ L() {
556
+ if (this.y)
557
+ this.y.m = null;
544
558
  this.k = null;
545
- this.w = null;
546
- this.x = defaultContext;
547
- this.c = STATE_DISPOSED;
559
+ this.y = null;
560
+ this.z = defaultContext;
561
+ this.b = STATE_DISPOSED;
548
562
  this.emptyDisposal();
549
563
  }
550
564
  emptyDisposal() {
@@ -573,7 +587,7 @@ function getContext(context, owner = currentOwner) {
573
587
  if (!owner) {
574
588
  throw new NoOwnerError();
575
589
  }
576
- const value = hasContext(context, owner) ? owner.x[context.id] : context.defaultValue;
590
+ const value = hasContext(context, owner) ? owner.z[context.id] : context.defaultValue;
577
591
  if (isUndefined(value)) {
578
592
  throw new ContextNotFoundError();
579
593
  }
@@ -583,13 +597,13 @@ function setContext(context, value, owner = currentOwner) {
583
597
  if (!owner) {
584
598
  throw new NoOwnerError();
585
599
  }
586
- owner.x = {
587
- ...owner.x,
600
+ owner.z = {
601
+ ...owner.z,
588
602
  [context.id]: isUndefined(value) ? context.defaultValue : value
589
603
  };
590
604
  }
591
605
  function hasContext(context, owner = currentOwner) {
592
- return !isUndefined(owner == null ? void 0 : owner.x[context.id]);
606
+ return !isUndefined(owner == null ? void 0 : owner.z[context.id]);
593
607
  }
594
608
  function onCleanup(fn) {
595
609
  if (!currentOwner)
@@ -627,10 +641,10 @@ function getObserver() {
627
641
  var UNCHANGED = Symbol(0);
628
642
  var Computation = class extends Owner {
629
643
  a = null;
630
- b = null;
644
+ c = null;
631
645
  l;
632
- L;
633
- M;
646
+ O;
647
+ P;
634
648
  // Used in __DEV__ mode, hopefully removed in production
635
649
  la;
636
650
  // Using false is an optimization as an alternative to _equals: () => false
@@ -639,25 +653,24 @@ var Computation = class extends Owner {
639
653
  ea;
640
654
  ha = false;
641
655
  /** Whether the computation is an error or has ancestors that are unresolved */
642
- h = 0;
656
+ i = 0;
643
657
  /** Which flags raised by sources are handled, vs. being passed through. */
644
658
  ba = DEFAULT_FLAGS;
645
- N = -1;
646
- D = false;
659
+ Q = -1;
660
+ E = false;
647
661
  j;
648
- e;
662
+ d;
663
+ I = false;
649
664
  constructor(initialValue, compute2, options) {
650
665
  super(options == null ? void 0 : options.id, compute2 === null);
651
- this.M = compute2;
652
- this.c = compute2 ? STATE_DIRTY : STATE_CLEAN;
653
- this.h = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
666
+ this.P = compute2;
667
+ this.b = compute2 ? STATE_DIRTY : STATE_CLEAN;
668
+ this.i = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
654
669
  this.l = initialValue;
655
670
  if ((options == null ? void 0 : options.equals) !== void 0)
656
671
  this.aa = options.equals;
657
- if (options == null ? void 0 : options.pureWrite)
658
- this.ha = true;
659
- if (options == null ? void 0 : options.unobserved)
660
- this.ea = options == null ? void 0 : options.unobserved;
672
+ this.ha = !!(options == null ? void 0 : options.pureWrite);
673
+ this.ea = options == null ? void 0 : options.unobserved;
661
674
  if (ActiveTransition) {
662
675
  this.j = ActiveTransition;
663
676
  ActiveTransition.a.set(this, this);
@@ -665,9 +678,9 @@ var Computation = class extends Owner {
665
678
  }
666
679
  ga() {
667
680
  track(this);
668
- newFlags |= this.h & ~currentMask;
669
- if (this.h & ERROR_BIT) {
670
- throw this.L;
681
+ newFlags |= this.i & ~currentMask;
682
+ if (this.i & ERROR_BIT) {
683
+ throw this.O;
671
684
  } else {
672
685
  return this.l;
673
686
  }
@@ -677,16 +690,16 @@ var Computation = class extends Owner {
677
690
  * Automatically re-executes the surrounding computation when the value changes
678
691
  */
679
692
  read() {
680
- if (ActiveTransition && (ActiveTransition.a.has(this) || !this.e && this.h & (UNINITIALIZED_BIT | ERROR_BIT))) {
693
+ if (ActiveTransition && (ActiveTransition.a.has(this) || !this.d && this.i & (UNINITIALIZED_BIT | ERROR_BIT))) {
681
694
  const clone = ActiveTransition.a.get(this) || cloneGraph(this);
682
695
  if (clone !== this)
683
696
  return clone.read();
684
697
  }
685
- if (this.M) {
686
- if (this.h & ERROR_BIT && this.N <= clock)
698
+ if (this.P) {
699
+ if (this.i & ERROR_BIT && this.Q <= clock)
687
700
  update(this);
688
701
  else
689
- this.K();
702
+ this.M();
690
703
  }
691
704
  return this.ga();
692
705
  }
@@ -698,49 +711,49 @@ var Computation = class extends Owner {
698
711
  * before continuing
699
712
  */
700
713
  wait() {
701
- if (ActiveTransition && (ActiveTransition.a.has(this) || !this.e && this.h & (UNINITIALIZED_BIT | ERROR_BIT))) {
714
+ if (ActiveTransition && (ActiveTransition.a.has(this) || !this.d && this.i & (UNINITIALIZED_BIT | ERROR_BIT))) {
702
715
  const clone = ActiveTransition.a.get(this) || cloneGraph(this);
703
716
  if (clone !== this)
704
717
  return clone.wait();
705
718
  }
706
- if (this.M) {
707
- if (this.h & ERROR_BIT && this.N <= clock)
719
+ if (this.P) {
720
+ if (this.i & ERROR_BIT && this.Q <= clock)
708
721
  update(this);
709
722
  else
710
- this.K();
723
+ this.M();
711
724
  }
712
- if ((notStale || this.h & UNINITIALIZED_BIT) && this.h & LOADING_BIT) {
725
+ if ((notStale || this.i & UNINITIALIZED_BIT) && this.i & LOADING_BIT) {
713
726
  track(this);
714
727
  throw new NotReadyError();
715
728
  }
716
- if (staleCheck && this.h & LOADING_BIT) {
729
+ if (staleCheck && this.i & LOADING_BIT) {
717
730
  staleCheck.l = true;
718
731
  }
719
732
  return this.ga();
720
733
  }
721
734
  /** Update the computation with a new value. */
722
735
  write(value, flags = 0, raw = false) {
723
- if (ActiveTransition && !this.e) {
736
+ if (ActiveTransition && !this.d) {
724
737
  const clone = cloneGraph(this);
725
738
  if (clone !== this)
726
739
  return clone.write(value, flags, raw);
727
740
  }
728
741
  const newValue = !raw && typeof value === "function" ? value(this.l) : value;
729
- const valueChanged = newValue !== UNCHANGED && (!!(this.h & UNINITIALIZED_BIT) || // this._stateFlags & LOADING_BIT & ~flags ||
742
+ const valueChanged = newValue !== UNCHANGED && (!!(this.i & UNINITIALIZED_BIT) || // this._stateFlags & LOADING_BIT & ~flags ||
730
743
  this.aa === false || !this.aa(this.l, newValue));
731
744
  if (valueChanged) {
732
745
  this.l = newValue;
733
- this.L = void 0;
746
+ this.O = void 0;
734
747
  }
735
- const changedFlagsMask = this.h ^ flags, changedFlags = changedFlagsMask & flags;
736
- this.h = flags;
737
- this.N = clock + 1;
738
- if (this.b) {
739
- for (let i = 0; i < this.b.length; i++) {
748
+ const changedFlagsMask = this.i ^ flags, changedFlags = changedFlagsMask & flags;
749
+ this.i = flags;
750
+ this.Q = clock + 1;
751
+ if (this.c) {
752
+ for (let i = 0; i < this.c.length; i++) {
740
753
  if (valueChanged) {
741
- this.b[i].y(STATE_DIRTY);
754
+ this.c[i].t(STATE_DIRTY);
742
755
  } else if (changedFlagsMask) {
743
- this.b[i].Z(changedFlagsMask, changedFlags);
756
+ this.c[i]._(changedFlagsMask, changedFlags);
744
757
  }
745
758
  }
746
759
  }
@@ -749,14 +762,14 @@ var Computation = class extends Owner {
749
762
  /**
750
763
  * Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
751
764
  */
752
- y(state, skipQueue) {
753
- if (this.c >= state && !this.D)
765
+ t(state, skipQueue) {
766
+ if (this.b >= state && !this.E)
754
767
  return;
755
- this.D = !!skipQueue;
756
- this.c = state;
757
- if (this.b) {
758
- for (let i = 0; i < this.b.length; i++) {
759
- this.b[i].y(STATE_CHECK, skipQueue);
768
+ this.E = !!skipQueue;
769
+ this.b = state;
770
+ if (this.c) {
771
+ for (let i = 0; i < this.c.length; i++) {
772
+ this.c[i].t(STATE_CHECK, skipQueue);
760
773
  }
761
774
  }
762
775
  }
@@ -766,36 +779,36 @@ var Computation = class extends Owner {
766
779
  * @param mask A bitmask for which flag(s) were changed.
767
780
  * @param newFlags The source's new flags, masked to just the changed ones.
768
781
  */
769
- Z(mask, newFlags2) {
770
- if (this.c >= STATE_DIRTY)
782
+ _(mask, newFlags2) {
783
+ if (this.b >= STATE_DIRTY)
771
784
  return;
772
785
  if (mask & this.ba) {
773
- this.y(STATE_DIRTY);
786
+ this.t(STATE_DIRTY);
774
787
  return;
775
788
  }
776
- if (this.c >= STATE_CHECK && !this.D)
789
+ if (this.b >= STATE_CHECK && !this.E)
777
790
  return;
778
- const prevFlags = this.h & mask;
791
+ const prevFlags = this.i & mask;
779
792
  const deltaFlags = prevFlags ^ newFlags2;
780
793
  if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
781
- this.y(STATE_CHECK);
794
+ this.t(STATE_CHECK);
782
795
  } else {
783
- this.h ^= deltaFlags;
784
- if (this.b) {
785
- for (let i = 0; i < this.b.length; i++) {
786
- this.b[i].Z(mask, newFlags2);
796
+ this.i ^= deltaFlags;
797
+ if (this.c) {
798
+ for (let i = 0; i < this.c.length; i++) {
799
+ this.c[i]._(mask, newFlags2);
787
800
  }
788
801
  }
789
802
  }
790
803
  }
791
- E(error) {
792
- if (ActiveTransition && !this.e) {
804
+ N(error) {
805
+ if (ActiveTransition && !this.d) {
793
806
  const clone = cloneGraph(this);
794
807
  if (clone !== this)
795
- return clone.E(error);
808
+ return clone.N(error);
796
809
  }
797
- this.L = error;
798
- this.write(UNCHANGED, this.h & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
810
+ this.O = error;
811
+ this.write(UNCHANGED, this.i & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
799
812
  }
800
813
  /**
801
814
  * This is the core part of the reactivity system, which makes sure that the values are updated
@@ -804,48 +817,48 @@ var Computation = class extends Owner {
804
817
  *
805
818
  * This function will ensure that the value and states we read from the computation are up to date
806
819
  */
807
- K() {
808
- if (!this.M) {
820
+ M() {
821
+ if (!this.P) {
809
822
  return;
810
823
  }
811
- if (this.c === STATE_DISPOSED) {
824
+ if (this.b === STATE_DISPOSED) {
812
825
  return;
813
826
  }
814
- if (this.c === STATE_CLEAN) {
827
+ if (this.b === STATE_CLEAN) {
815
828
  return;
816
829
  }
817
830
  let observerFlags = 0;
818
- if (this.c === STATE_CHECK) {
831
+ if (this.b === STATE_CHECK) {
819
832
  for (let i = 0; i < this.a.length; i++) {
820
833
  const source = getTransitionSource(this.a[i]);
821
- source.K();
822
- observerFlags |= source.h & ~UNINITIALIZED_BIT;
823
- if (this.c === STATE_DIRTY) {
834
+ source.M();
835
+ observerFlags |= source.i & ~UNINITIALIZED_BIT;
836
+ if (this.b === STATE_DIRTY) {
824
837
  break;
825
838
  }
826
839
  }
827
840
  }
828
- if (this.c === STATE_DIRTY) {
841
+ if (this.b === STATE_DIRTY) {
829
842
  update(this);
830
843
  } else {
831
844
  this.write(UNCHANGED, observerFlags);
832
- this.c = STATE_CLEAN;
845
+ this.b = STATE_CLEAN;
833
846
  }
834
847
  }
835
848
  /**
836
849
  * Remove ourselves from the owner graph and the computation graph
837
850
  */
838
- R() {
839
- if (this.c === STATE_DISPOSED)
851
+ L() {
852
+ if (this.b === STATE_DISPOSED)
840
853
  return;
841
854
  if (this.a)
842
855
  removeSourceObservers(this, 0);
843
- super.R();
856
+ super.L();
844
857
  }
845
858
  };
846
859
  function track(computation) {
847
- if (ActiveTransition && computation.e)
848
- computation = computation.e;
860
+ if (ActiveTransition && computation.d)
861
+ computation = computation.d;
849
862
  if (currentObserver) {
850
863
  if (!newSources && currentObserver.a && currentObserver.a[newSourcesIndex] === computation) {
851
864
  newSourcesIndex++;
@@ -855,7 +868,7 @@ function track(computation) {
855
868
  newSources.push(computation);
856
869
  }
857
870
  if (updateCheck) {
858
- updateCheck.l = computation.N > currentObserver.N;
871
+ updateCheck.l = computation.Q > currentObserver.Q;
859
872
  }
860
873
  }
861
874
  }
@@ -865,19 +878,19 @@ function update(node) {
865
878
  newSourcesIndex = 0;
866
879
  newFlags = 0;
867
880
  try {
868
- if (ActiveTransition && node.e && !node.Y) {
869
- initialDispose(node.e);
870
- node.Y = true;
881
+ if (ActiveTransition && node.d && !node.Z) {
882
+ initialDispose(node.d);
883
+ node.Z = true;
871
884
  }
872
885
  node.dispose(false);
873
886
  node.emptyDisposal();
874
- const result = compute(node, node.M, node);
887
+ const result = compute(node, node.P, node);
875
888
  node.write(result, newFlags, true);
876
889
  } catch (error) {
877
890
  if (error instanceof NotReadyError) {
878
- node.write(UNCHANGED, newFlags | LOADING_BIT | node.h & UNINITIALIZED_BIT);
891
+ node.write(UNCHANGED, newFlags | LOADING_BIT | node.i & UNINITIALIZED_BIT);
879
892
  } else {
880
- node.E(error);
893
+ node.N(error);
881
894
  }
882
895
  } finally {
883
896
  if (newSources) {
@@ -894,10 +907,10 @@ function update(node) {
894
907
  let source;
895
908
  for (let i = newSourcesIndex; i < node.a.length; i++) {
896
909
  source = getTransitionSource(node.a[i]);
897
- if (!source.b)
898
- source.b = [node];
910
+ if (!source.c)
911
+ source.c = [node];
899
912
  else
900
- source.b.push(node);
913
+ source.c.push(node);
901
914
  }
902
915
  } else if (node.a && newSourcesIndex < node.a.length) {
903
916
  removeSourceObservers(node, newSourcesIndex);
@@ -906,8 +919,8 @@ function update(node) {
906
919
  newSources = prevSources;
907
920
  newSourcesIndex = prevSourcesIndex;
908
921
  newFlags = prevFlags;
909
- node.N = clock + 1;
910
- node.c = STATE_CLEAN;
922
+ node.Q = clock + 1;
923
+ node.b = STATE_CLEAN;
911
924
  }
912
925
  }
913
926
  function isEqual(a, b) {
@@ -967,46 +980,6 @@ function latest(fn, fallback) {
967
980
  notStale = prevNotStale;
968
981
  }
969
982
  }
970
- function runWithObserver(observer, run) {
971
- const prevSources = newSources, prevSourcesIndex = newSourcesIndex, prevFlags = newFlags;
972
- newSources = null;
973
- newSourcesIndex = observer.a ? observer.a.length : 0;
974
- newFlags = 0;
975
- try {
976
- return compute(observer, run, observer);
977
- } catch (error) {
978
- if (error instanceof NotReadyError) {
979
- observer.write(
980
- UNCHANGED,
981
- newFlags | LOADING_BIT | observer.h & UNINITIALIZED_BIT
982
- );
983
- } else {
984
- observer.E(error);
985
- }
986
- } finally {
987
- if (newSources) {
988
- if (newSourcesIndex > 0) {
989
- observer.a.length = newSourcesIndex + newSources.length;
990
- for (let i = 0; i < newSources.length; i++) {
991
- observer.a[newSourcesIndex + i] = newSources[i];
992
- }
993
- } else {
994
- observer.a = newSources;
995
- }
996
- let source;
997
- for (let i = newSourcesIndex; i < observer.a.length; i++) {
998
- source = observer.a[i];
999
- if (!source.b)
1000
- source.b = [observer];
1001
- else
1002
- source.b.push(observer);
1003
- }
1004
- }
1005
- newSources = prevSources;
1006
- newSourcesIndex = prevSourcesIndex;
1007
- newFlags = prevFlags;
1008
- }
1009
- }
1010
983
  function compute(owner, fn, observer) {
1011
984
  const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask, prevNotStale = notStale;
1012
985
  currentObserver = observer;
@@ -1025,67 +998,67 @@ function compute(owner, fn, observer) {
1025
998
  // src/core/effect.ts
1026
999
  var Effect = class extends Computation {
1027
1000
  ca;
1028
- _;
1029
- O;
1030
- da = false;
1031
1001
  $;
1032
- C;
1002
+ u;
1003
+ da = false;
1004
+ T;
1005
+ r;
1033
1006
  constructor(initialValue, compute2, effect, error, options) {
1034
1007
  super(initialValue, compute2, options);
1035
1008
  this.ca = effect;
1036
- this._ = error;
1037
- this.$ = initialValue;
1038
- this.C = (options == null ? void 0 : options.render) ? EFFECT_RENDER : EFFECT_USER;
1039
- if (this.C === EFFECT_RENDER) {
1040
- this.M = function(p) {
1041
- return !this.e && clock > this.B.created && !(this.h & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
1009
+ this.$ = error;
1010
+ this.T = initialValue;
1011
+ this.r = (options == null ? void 0 : options.render) ? EFFECT_RENDER : EFFECT_USER;
1012
+ if (this.r === EFFECT_RENDER) {
1013
+ this.P = function(p) {
1014
+ return !this.d && clock > this.C.created && !(this.i & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
1042
1015
  };
1043
1016
  }
1044
- this.K();
1045
- !(options == null ? void 0 : options.defer) && (this.C === EFFECT_USER ? getQueue(this).enqueue(this.C, this.F.bind(this)) : this.F(this.C));
1017
+ this.M();
1018
+ !(options == null ? void 0 : options.defer) && (this.r === EFFECT_USER ? getQueue(this).enqueue(this.r, this.w.bind(this)) : this.w(this.r));
1046
1019
  }
1047
1020
  write(value, flags = 0) {
1048
- if (this.c == STATE_DIRTY) {
1049
- this.h = flags;
1050
- if (this.C === EFFECT_RENDER) {
1051
- getQueue(this).notify(this, LOADING_BIT | ERROR_BIT, this.h);
1021
+ if (this.b == STATE_DIRTY) {
1022
+ this.i = flags;
1023
+ if (this.r === EFFECT_RENDER) {
1024
+ getQueue(this).notify(this, LOADING_BIT | ERROR_BIT, this.i);
1052
1025
  }
1053
1026
  }
1054
1027
  if (value === UNCHANGED)
1055
1028
  return this.l;
1056
1029
  this.l = value;
1057
1030
  this.da = true;
1058
- this.L = void 0;
1031
+ this.O = void 0;
1059
1032
  return value;
1060
1033
  }
1061
- y(state, skipQueue) {
1062
- if (this.c >= state || skipQueue)
1034
+ t(state, skipQueue) {
1035
+ if (this.b >= state || skipQueue)
1063
1036
  return;
1064
- if (this.c === STATE_CLEAN)
1065
- getQueue(this).enqueue(this.C, this.F.bind(this));
1066
- this.c = state;
1037
+ if (this.b === STATE_CLEAN || this.d && !ActiveTransition)
1038
+ getQueue(this).enqueue(this.r, this.w.bind(this));
1039
+ this.b = state;
1067
1040
  }
1068
- Z(mask, newFlags2) {
1069
- if (this.e) {
1070
- if (this.c >= STATE_DIRTY)
1041
+ _(mask, newFlags2) {
1042
+ if (this.d) {
1043
+ if (this.b >= STATE_DIRTY)
1071
1044
  return;
1072
1045
  if (mask & 3) {
1073
- this.y(STATE_DIRTY);
1046
+ this.t(STATE_DIRTY);
1074
1047
  return;
1075
1048
  }
1076
1049
  }
1077
- super.Z(mask, newFlags2);
1050
+ super._(mask, newFlags2);
1078
1051
  }
1079
- E(error) {
1080
- this.L = error;
1052
+ N(error) {
1053
+ this.O = error;
1081
1054
  getQueue(this).notify(this, LOADING_BIT, 0);
1082
- this.h = ERROR_BIT;
1083
- if (this.C === EFFECT_USER) {
1055
+ this.i = ERROR_BIT;
1056
+ if (this.r === EFFECT_USER) {
1084
1057
  try {
1085
- return this._ ? this._(error, () => {
1058
+ return this.$ ? this.$(error, () => {
1086
1059
  var _a;
1087
- (_a = this.O) == null ? void 0 : _a.call(this);
1088
- this.O = void 0;
1060
+ (_a = this.u) == null ? void 0 : _a.call(this);
1061
+ this.u = void 0;
1089
1062
  }) : console.error(error);
1090
1063
  } catch (e) {
1091
1064
  error = e;
@@ -1094,52 +1067,85 @@ var Effect = class extends Computation {
1094
1067
  if (!getQueue(this).notify(this, ERROR_BIT, ERROR_BIT))
1095
1068
  throw error;
1096
1069
  }
1097
- R() {
1070
+ L() {
1098
1071
  var _a;
1099
- if (this.c === STATE_DISPOSED)
1072
+ if (this.b === STATE_DISPOSED)
1100
1073
  return;
1101
1074
  this.ca = void 0;
1075
+ this.T = void 0;
1102
1076
  this.$ = void 0;
1103
- this._ = void 0;
1104
- (_a = this.O) == null ? void 0 : _a.call(this);
1105
- this.O = void 0;
1077
+ (_a = this.u) == null ? void 0 : _a.call(this);
1078
+ this.u = void 0;
1106
1079
  getQueue(this).notify(this, ERROR_BIT | LOADING_BIT, 0);
1107
- super.R();
1080
+ super.L();
1108
1081
  }
1109
- F(type) {
1082
+ w(type) {
1110
1083
  var _a;
1111
1084
  if (type) {
1112
- const effect = this.e || this;
1113
- if (effect.da && effect.c !== STATE_DISPOSED) {
1114
- (_a = effect.O) == null ? void 0 : _a.call(effect);
1085
+ const effect = this.d || this;
1086
+ if (effect.da && effect.b !== STATE_DISPOSED) {
1087
+ (_a = effect.u) == null ? void 0 : _a.call(effect);
1115
1088
  try {
1116
- effect.O = effect.ca(effect.l, effect.$);
1089
+ effect.u = effect.ca(effect.l, effect.T);
1117
1090
  } catch (e) {
1118
1091
  if (!getQueue(effect).notify(effect, ERROR_BIT, ERROR_BIT))
1119
1092
  throw e;
1120
1093
  } finally {
1121
- effect.$ = effect.l;
1094
+ effect.T = effect.l;
1122
1095
  effect.da = false;
1123
1096
  }
1124
1097
  }
1125
1098
  } else
1126
- this.c !== STATE_CLEAN && runTop(this);
1099
+ this.b !== STATE_CLEAN && runTop(this);
1100
+ }
1101
+ };
1102
+ var TrackedEffect = class extends Computation {
1103
+ r = EFFECT_USER;
1104
+ u;
1105
+ constructor(compute2, options) {
1106
+ super(void 0, () => {
1107
+ var _a;
1108
+ (_a = this.u) == null ? void 0 : _a.call(this);
1109
+ this.u = latest(compute2);
1110
+ return void 0;
1111
+ }, options);
1112
+ getQueue(this).enqueue(this.r, this.w.bind(this));
1113
+ }
1114
+ t(state, skipQueue) {
1115
+ if (this.b >= state || skipQueue)
1116
+ return;
1117
+ if (this.b === STATE_CLEAN || this.d && !ActiveTransition)
1118
+ getQueue(this).enqueue(this.r, this.w.bind(this));
1119
+ this.b = state;
1120
+ }
1121
+ L() {
1122
+ var _a;
1123
+ if (this.b === STATE_DISPOSED)
1124
+ return;
1125
+ (_a = this.u) == null ? void 0 : _a.call(this);
1126
+ this.u = void 0;
1127
+ getQueue(this).notify(this, ERROR_BIT | LOADING_BIT, 0);
1128
+ super.L();
1129
+ }
1130
+ w(type) {
1131
+ if (type)
1132
+ this.b !== STATE_CLEAN && runTop(this);
1127
1133
  }
1128
1134
  };
1129
1135
  var EagerComputation = class extends Computation {
1130
1136
  constructor(initialValue, compute2, options) {
1131
1137
  super(initialValue, compute2, options);
1132
- !(options == null ? void 0 : options.defer) && this.K();
1138
+ !(options == null ? void 0 : options.defer) && this.M();
1133
1139
  }
1134
- y(state, skipQueue) {
1135
- if (this.c >= state && !this.D)
1140
+ t(state, skipQueue) {
1141
+ if (this.b >= state && !this.E)
1136
1142
  return;
1137
- if (!skipQueue && (this.c === STATE_CLEAN || this.c === STATE_CHECK && this.D))
1138
- getQueue(this).enqueue(EFFECT_PURE, this.F.bind(this));
1139
- super.y(state, skipQueue);
1143
+ if (!skipQueue && (this.b === STATE_CLEAN || this.b === STATE_CHECK && this.E))
1144
+ getQueue(this).enqueue(EFFECT_PURE, this.w.bind(this));
1145
+ super.t(state, skipQueue);
1140
1146
  }
1141
- F() {
1142
- this.c !== STATE_CLEAN && runTop(this);
1147
+ w() {
1148
+ this.b !== STATE_CLEAN && runTop(this);
1143
1149
  }
1144
1150
  };
1145
1151
  var FirewallComputation = class extends Computation {
@@ -1147,16 +1153,16 @@ var FirewallComputation = class extends Computation {
1147
1153
  constructor(compute2) {
1148
1154
  super(void 0, compute2);
1149
1155
  }
1150
- y(state, skipQueue) {
1151
- if (this.c >= state && !this.D)
1156
+ t(state, skipQueue) {
1157
+ if (this.b >= state && !this.E)
1152
1158
  return;
1153
- if (!skipQueue && (this.c === STATE_CLEAN || this.c === STATE_CHECK && this.D))
1154
- getQueue(this).enqueue(EFFECT_PURE, this.F.bind(this));
1155
- super.y(state, true);
1156
- this.D = !!skipQueue;
1159
+ if (!skipQueue && (this.b === STATE_CLEAN || this.b === STATE_CHECK && this.E))
1160
+ getQueue(this).enqueue(EFFECT_PURE, this.w.bind(this));
1161
+ super.t(state, true);
1162
+ this.E = !!skipQueue;
1157
1163
  }
1158
- F() {
1159
- this.c !== STATE_CLEAN && runTop(this);
1164
+ w() {
1165
+ this.b !== STATE_CLEAN && runTop(this);
1160
1166
  }
1161
1167
  };
1162
1168
  function runTop(node) {
@@ -1164,14 +1170,212 @@ function runTop(node) {
1164
1170
  for (let current = node; current !== null; current = current.k) {
1165
1171
  if (ActiveTransition && current.j)
1166
1172
  current = ActiveTransition.a.get(current);
1167
- if (current.c !== STATE_CLEAN) {
1173
+ if (current.b !== STATE_CLEAN) {
1168
1174
  ancestors.push(current);
1169
1175
  }
1170
1176
  }
1171
1177
  for (let i = ancestors.length - 1; i >= 0; i--) {
1172
- if (ancestors[i].c !== STATE_DISPOSED)
1173
- ancestors[i].K();
1178
+ if (ancestors[i].b !== STATE_DISPOSED)
1179
+ ancestors[i].M();
1180
+ }
1181
+ }
1182
+
1183
+ // src/signals.ts
1184
+ function createSignal(first, second, third) {
1185
+ if (typeof first === "function") {
1186
+ const node2 = new Computation(second, first, third);
1187
+ return [node2.read.bind(node2), node2.write.bind(node2)];
1188
+ }
1189
+ const o = getOwner();
1190
+ const needsId = (o == null ? void 0 : o.id) != null;
1191
+ const node = new Computation(
1192
+ first,
1193
+ null,
1194
+ needsId ? { id: o.getNextChildId(), ...second } : second
1195
+ );
1196
+ return [node.read.bind(node), node.write.bind(node)];
1197
+ }
1198
+ function createMemo(compute2, value, options) {
1199
+ let node = new Computation(
1200
+ value,
1201
+ compute2,
1202
+ options
1203
+ );
1204
+ let resolvedValue;
1205
+ return () => {
1206
+ var _a, _b;
1207
+ if (node) {
1208
+ if (node.b === STATE_DISPOSED) {
1209
+ node = void 0;
1210
+ return resolvedValue;
1211
+ }
1212
+ resolvedValue = node.wait();
1213
+ if (!((_a = node.a) == null ? void 0 : _a.length) && ((_b = node.m) == null ? void 0 : _b.k) !== node && !(node.i & UNINITIALIZED_BIT)) {
1214
+ node.dispose();
1215
+ node = void 0;
1216
+ }
1217
+ }
1218
+ return resolvedValue;
1219
+ };
1220
+ }
1221
+ function createAsync(compute2, value, options) {
1222
+ let refreshing = false;
1223
+ const node = new EagerComputation(
1224
+ value,
1225
+ (p) => {
1226
+ const source = compute2(p, refreshing);
1227
+ refreshing = false;
1228
+ const isPromise = source instanceof Promise;
1229
+ const iterator = source[Symbol.asyncIterator];
1230
+ if (!isPromise && !iterator) {
1231
+ return source;
1232
+ }
1233
+ let abort = false;
1234
+ onCleanup(() => abort = true);
1235
+ let transition2 = ActiveTransition;
1236
+ if (isPromise) {
1237
+ source.then(
1238
+ (value3) => {
1239
+ if (abort)
1240
+ return;
1241
+ if (transition2)
1242
+ return transition2.runTransition(() => {
1243
+ node.write(value3, 0, true);
1244
+ }, true);
1245
+ node.write(value3, 0, true);
1246
+ },
1247
+ (error) => {
1248
+ if (abort)
1249
+ return;
1250
+ if (transition2)
1251
+ return transition2.runTransition(() => node.N(error), true);
1252
+ node.N(error);
1253
+ }
1254
+ );
1255
+ } else {
1256
+ (async () => {
1257
+ try {
1258
+ for await (let value3 of source) {
1259
+ if (abort)
1260
+ return;
1261
+ if (transition2)
1262
+ return transition2.runTransition(() => {
1263
+ node.write(value3, 0, true);
1264
+ transition2 = null;
1265
+ }, true);
1266
+ node.write(value3, 0, true);
1267
+ }
1268
+ } catch (error) {
1269
+ if (abort)
1270
+ return;
1271
+ if (transition2)
1272
+ return transition2.runTransition(() => {
1273
+ node.N(error);
1274
+ transition2 = null;
1275
+ }, true);
1276
+ node.N(error);
1277
+ }
1278
+ })();
1279
+ }
1280
+ throw new NotReadyError();
1281
+ },
1282
+ options
1283
+ );
1284
+ const read = node.wait.bind(node);
1285
+ read.refresh = () => {
1286
+ let n = node;
1287
+ if (ActiveTransition && !node.d) {
1288
+ n = cloneGraph(node);
1289
+ }
1290
+ n.b = STATE_DIRTY;
1291
+ refreshing = true;
1292
+ n.M();
1293
+ };
1294
+ return read;
1295
+ }
1296
+ function createEffect(compute2, effect, value, options) {
1297
+ void new Effect(
1298
+ value,
1299
+ compute2,
1300
+ effect.effect || effect,
1301
+ effect.error,
1302
+ options
1303
+ );
1304
+ }
1305
+ function createRenderEffect(compute2, effect, value, options) {
1306
+ void new Effect(value, compute2, effect, void 0, {
1307
+ render: true,
1308
+ ...options
1309
+ });
1310
+ }
1311
+ function createTrackedEffect(compute2, options) {
1312
+ void new TrackedEffect(compute2, options);
1313
+ }
1314
+ function createReaction(effect, options) {
1315
+ let cleanup = void 0;
1316
+ onCleanup(() => cleanup == null ? void 0 : cleanup());
1317
+ return (tracking) => {
1318
+ const node = new Effect(
1319
+ void 0,
1320
+ tracking,
1321
+ () => {
1322
+ var _a;
1323
+ cleanup == null ? void 0 : cleanup();
1324
+ cleanup = (_a = effect.effect || effect) == null ? void 0 : _a();
1325
+ node.dispose(true);
1326
+ },
1327
+ effect.error,
1328
+ {
1329
+ defer: true,
1330
+ ...options
1331
+ }
1332
+ );
1333
+ };
1334
+ }
1335
+ function createRoot(init, options) {
1336
+ const owner = new Owner(options == null ? void 0 : options.id);
1337
+ return compute(owner, !init.length ? init : () => init(() => owner.dispose()), null);
1338
+ }
1339
+ function runWithOwner(owner, run) {
1340
+ return compute(owner, run, null);
1341
+ }
1342
+ function resolve(fn) {
1343
+ return new Promise((res, rej) => {
1344
+ createRoot((dispose) => {
1345
+ new EagerComputation(void 0, () => {
1346
+ try {
1347
+ res(fn());
1348
+ } catch (err) {
1349
+ if (err instanceof NotReadyError)
1350
+ throw err;
1351
+ rej(err);
1352
+ }
1353
+ dispose();
1354
+ });
1355
+ });
1356
+ });
1357
+ }
1358
+ function createOptimistic(first, second, third) {
1359
+ const node = typeof first === "function" ? new Computation(second, first, third) : new Computation(first, null, second);
1360
+ const reset = () => node.write(first);
1361
+ function write(v) {
1362
+ if (!ActiveTransition)
1363
+ throw new Error("createOptimistic can only be updated inside a transition");
1364
+ ActiveTransition.addOptimistic(reset);
1365
+ cloneGraph(node, true);
1366
+ queueMicrotask(() => reset.j && node.write(v));
1367
+ }
1368
+ return [node.read.bind(node), write];
1369
+ }
1370
+ function useTransition() {
1371
+ const [pending, setPending] = createOptimistic(false);
1372
+ function start(fn) {
1373
+ transition((resume) => {
1374
+ setPending(true);
1375
+ return fn(resume);
1376
+ });
1174
1377
  }
1378
+ return [pending, start];
1175
1379
  }
1176
1380
 
1177
1381
  // src/store/reconcile.ts
@@ -1179,8 +1383,8 @@ function unwrap(value) {
1179
1383
  var _a;
1180
1384
  return ((_a = value == null ? void 0 : value[$TARGET]) == null ? void 0 : _a[STORE_NODE]) ?? value;
1181
1385
  }
1182
- function getOverrideValue(value, override, key) {
1183
- return override && key in override ? override[key] : value[key];
1386
+ function getOverrideValue(value, override, nodes, key) {
1387
+ return nodes && key in nodes ? nodes[key].read() : override && key in override ? override[key] : value[key];
1184
1388
  }
1185
1389
  function getAllKeys(value, override, next) {
1186
1390
  const keys = getKeys(value, override);
@@ -1194,6 +1398,7 @@ function applyState(next, state, keyFn, all) {
1194
1398
  return;
1195
1399
  const previous = target[STORE_VALUE];
1196
1400
  const override = target[STORE_OVERRIDE];
1401
+ let nodes = target[STORE_NODE];
1197
1402
  if (next === previous && !override)
1198
1403
  return;
1199
1404
  (target[STORE_LOOKUP] || storeLookup).set(next, target[$PROXY]);
@@ -1201,14 +1406,14 @@ function applyState(next, state, keyFn, all) {
1201
1406
  target[STORE_OVERRIDE] = void 0;
1202
1407
  if (Array.isArray(previous)) {
1203
1408
  let changed = false;
1204
- const prevLength = getOverrideValue(previous, override, "length");
1409
+ const prevLength = getOverrideValue(previous, override, nodes, "length");
1205
1410
  if (next.length && prevLength && next[0] && keyFn(next[0]) != null) {
1206
1411
  let i, j, start, end, newEnd, item, newIndicesNext, keyVal;
1207
- for (start = 0, end = Math.min(prevLength, next.length); start < end && ((item = getOverrideValue(previous, override, start)) === next[start] || item && next[start] && keyFn(item) === keyFn(next[start])); start++) {
1412
+ for (start = 0, end = Math.min(prevLength, next.length); start < end && ((item = getOverrideValue(previous, override, nodes, start)) === next[start] || item && next[start] && keyFn(item) === keyFn(next[start])); start++) {
1208
1413
  applyState(next[start], wrap(item, target), keyFn, all);
1209
1414
  }
1210
1415
  const temp = new Array(next.length), newIndices = /* @__PURE__ */ new Map();
1211
- for (end = prevLength - 1, newEnd = next.length - 1; end >= start && newEnd >= start && ((item = getOverrideValue(previous, override, end)) === next[newEnd] || item && next[newEnd] && keyFn(item) === keyFn(next[newEnd])); end--, newEnd--) {
1416
+ for (end = prevLength - 1, newEnd = next.length - 1; end >= start && newEnd >= start && ((item = getOverrideValue(previous, override, nodes, end)) === next[newEnd] || item && next[newEnd] && keyFn(item) === keyFn(next[newEnd])); end--, newEnd--) {
1212
1417
  temp[newEnd] = item;
1213
1418
  }
1214
1419
  if (start > newEnd || start > end) {
@@ -1235,7 +1440,7 @@ function applyState(next, state, keyFn, all) {
1235
1440
  newIndices.set(keyVal, j);
1236
1441
  }
1237
1442
  for (i = start; i <= end; i++) {
1238
- item = getOverrideValue(previous, override, i);
1443
+ item = getOverrideValue(previous, override, nodes, i);
1239
1444
  keyVal = item ? keyFn(item) : item;
1240
1445
  j = newIndices.get(keyVal);
1241
1446
  if (j !== void 0 && j !== -1) {
@@ -1256,7 +1461,7 @@ function applyState(next, state, keyFn, all) {
1256
1461
  changed = true;
1257
1462
  } else if (prevLength && next.length) {
1258
1463
  for (let i = 0, len = next.length; i < len; i++) {
1259
- const item = getOverrideValue(previous, override, i);
1464
+ const item = getOverrideValue(previous, override, nodes, i);
1260
1465
  isWrappable(item) && applyState(next[i], wrap(item, target), keyFn, all);
1261
1466
  }
1262
1467
  }
@@ -1267,14 +1472,13 @@ function applyState(next, state, keyFn, all) {
1267
1472
  changed && ((_h = target[STORE_NODE][$TRACK]) == null ? void 0 : _h.write(void 0));
1268
1473
  return;
1269
1474
  }
1270
- let nodes = target[STORE_NODE];
1271
1475
  if (nodes) {
1272
1476
  const tracked = nodes[$TRACK];
1273
1477
  const keys = tracked || all ? getAllKeys(previous, override, next) : Object.keys(nodes);
1274
1478
  for (let i = 0, len = keys.length; i < len; i++) {
1275
1479
  const key = keys[i];
1276
1480
  const node = nodes[key];
1277
- const previousValue = unwrap(getOverrideValue(previous, override, key));
1481
+ const previousValue = unwrap(getOverrideValue(previous, override, nodes, key));
1278
1482
  let nextValue = unwrap(next[key]);
1279
1483
  if (previousValue === nextValue)
1280
1484
  continue;
@@ -1305,16 +1509,7 @@ function reconcile(value, key, all = false) {
1305
1509
  }
1306
1510
 
1307
1511
  // src/store/projection.ts
1308
- function createProjection(fn, initialValue = {}, options) {
1309
- let wrappedStore;
1310
- const node = new FirewallComputation(() => {
1311
- storeSetter(wrappedStore, (s) => {
1312
- const value = fn(s);
1313
- if (value !== s && value !== void 0) {
1314
- reconcile(value, (options == null ? void 0 : options.key) || "id", options == null ? void 0 : options.all)(s);
1315
- }
1316
- });
1317
- });
1512
+ function createProjectionInternal(fn, initialValue = {}, options) {
1318
1513
  const wrappedMap = /* @__PURE__ */ new WeakMap();
1319
1514
  const traps = {
1320
1515
  ...storeTraps,
@@ -1325,7 +1520,7 @@ function createProjection(fn, initialValue = {}, options) {
1325
1520
  return storeTraps.get(target, property, receiver);
1326
1521
  }
1327
1522
  };
1328
- function wrapProjection(source) {
1523
+ const wrapProjection = (source) => {
1329
1524
  var _a;
1330
1525
  if (wrappedMap.has(source))
1331
1526
  return wrappedMap.get(source);
@@ -1337,8 +1532,20 @@ function createProjection(fn, initialValue = {}, options) {
1337
1532
  });
1338
1533
  wrappedMap.set(source, wrapped);
1339
1534
  return wrapped;
1340
- }
1341
- return wrappedStore = wrapProjection(initialValue);
1535
+ };
1536
+ const wrappedStore = wrapProjection(initialValue);
1537
+ const node = new FirewallComputation(() => {
1538
+ storeSetter(wrappedStore, (s) => {
1539
+ const value = fn(s);
1540
+ if (value !== s && value !== void 0) {
1541
+ reconcile(value, (options == null ? void 0 : options.key) || "id", options == null ? void 0 : options.all)(s);
1542
+ }
1543
+ });
1544
+ });
1545
+ return { store: wrappedStore, node };
1546
+ }
1547
+ function createProjection(fn, initialValue = {}, options) {
1548
+ return createProjectionInternal(fn, initialValue, options).store;
1342
1549
  }
1343
1550
 
1344
1551
  // src/store/store.ts
@@ -1472,14 +1679,14 @@ var storeTraps = {
1472
1679
  const store = target[$PROXY];
1473
1680
  if (Writing == null ? void 0 : Writing.has(target[$PROXY])) {
1474
1681
  untrack(() => {
1475
- var _a, _b, _c, _d, _e, _f, _g, _h;
1682
+ var _a, _b, _c, _d, _e, _f, _g;
1476
1683
  const state = target[STORE_VALUE];
1477
1684
  const base = state[property];
1478
- const prev = ((_a = target[STORE_OVERRIDE]) == null ? void 0 : _a[property]) || base;
1479
- const value = ((_b = rawValue == null ? void 0 : rawValue[$TARGET]) == null ? void 0 : _b[STORE_VALUE]) ?? rawValue;
1685
+ const prev = target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE] ? target[STORE_OVERRIDE][property] : base;
1686
+ const value = ((_a = rawValue == null ? void 0 : rawValue[$TARGET]) == null ? void 0 : _a[STORE_VALUE]) ?? rawValue;
1480
1687
  if (prev === value)
1481
1688
  return true;
1482
- const len = ((_c = target[STORE_OVERRIDE]) == null ? void 0 : _c.length) || state.length;
1689
+ const len = ((_b = target[STORE_OVERRIDE]) == null ? void 0 : _b.length) || state.length;
1483
1690
  if (value !== void 0 && value === base)
1484
1691
  delete target[STORE_OVERRIDE][property];
1485
1692
  else
@@ -1491,15 +1698,15 @@ var storeTraps = {
1491
1698
  }
1492
1699
  if (recursivelyNotify(store, storeLookup) && wrappable)
1493
1700
  recursivelyAddParent(value, store);
1494
- (_e = (_d = target[STORE_HAS]) == null ? void 0 : _d[property]) == null ? void 0 : _e.write(true);
1701
+ (_d = (_c = target[STORE_HAS]) == null ? void 0 : _c[property]) == null ? void 0 : _d.write(true);
1495
1702
  const nodes = getNodes(target, STORE_NODE);
1496
- (_f = nodes[property]) == null ? void 0 : _f.write(wrappable ? wrap(value, target) : value);
1703
+ (_e = nodes[property]) == null ? void 0 : _e.write(wrappable ? wrap(value, target) : value);
1497
1704
  if (Array.isArray(state)) {
1498
1705
  const index = parseInt(property) + 1;
1499
1706
  if (index > len)
1500
- (_g = nodes.length) == null ? void 0 : _g.write(index);
1707
+ (_f = nodes.length) == null ? void 0 : _f.write(index);
1501
1708
  }
1502
- (_h = nodes[$TRACK]) == null ? void 0 : _h.write(void 0);
1709
+ (_g = nodes[$TRACK]) == null ? void 0 : _g.write(void 0);
1503
1710
  });
1504
1711
  }
1505
1712
  return true;
@@ -1508,8 +1715,8 @@ var storeTraps = {
1508
1715
  var _a;
1509
1716
  if ((Writing == null ? void 0 : Writing.has(target[$PROXY])) && ((_a = target[STORE_OVERRIDE]) == null ? void 0 : _a[property]) !== $DELETED) {
1510
1717
  untrack(() => {
1511
- var _a2, _b, _c, _d, _e;
1512
- const prev = ((_a2 = target[STORE_OVERRIDE]) == null ? void 0 : _a2[property]) || target[STORE_VALUE][property];
1718
+ var _a2, _b, _c, _d;
1719
+ const prev = target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE] ? target[STORE_OVERRIDE][property] : target[STORE_VALUE][property];
1513
1720
  if (property in target[STORE_VALUE]) {
1514
1721
  (target[STORE_OVERRIDE] || (target[STORE_OVERRIDE] = /* @__PURE__ */ Object.create(null)))[property] = $DELETED;
1515
1722
  } else if (target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE]) {
@@ -1520,10 +1727,10 @@ var storeTraps = {
1520
1727
  const parents = PARENTS.get(prev);
1521
1728
  parents && (parents instanceof Set ? parents.delete(target) : PARENTS.delete(prev));
1522
1729
  }
1523
- (_c = (_b = target[STORE_HAS]) == null ? void 0 : _b[property]) == null ? void 0 : _c.write(false);
1730
+ (_b = (_a2 = target[STORE_HAS]) == null ? void 0 : _a2[property]) == null ? void 0 : _b.write(false);
1524
1731
  const nodes = getNodes(target, STORE_NODE);
1525
- (_d = nodes[property]) == null ? void 0 : _d.write(void 0);
1526
- (_e = nodes[$TRACK]) == null ? void 0 : _e.write(void 0);
1732
+ (_c = nodes[property]) == null ? void 0 : _c.write(void 0);
1733
+ (_d = nodes[$TRACK]) == null ? void 0 : _d.write(void 0);
1527
1734
  });
1528
1735
  }
1529
1736
  return true;
@@ -1568,7 +1775,7 @@ function storeSetter(store, fn) {
1568
1775
  }
1569
1776
  }
1570
1777
  function createStore(first, second, options) {
1571
- const derived = typeof first === "function", wrappedStore = derived ? createProjection(first, second, options) : wrap(first);
1778
+ const derived = typeof first === "function", wrappedStore = derived ? createProjectionInternal(first, second, options).store : wrap(first);
1572
1779
  return [wrappedStore, (fn) => storeSetter(wrappedStore, fn)];
1573
1780
  }
1574
1781
  function recursivelyNotify(state, lookup) {
@@ -1633,6 +1840,29 @@ function deep(store) {
1633
1840
  return store[$DEEP];
1634
1841
  }
1635
1842
 
1843
+ // src/store/optimistic.ts
1844
+ function createOptimisticStore(first, second, options) {
1845
+ const derived = typeof first === "function";
1846
+ const { store, node } = derived ? createProjectionInternal(first, second, options) : createProjectionInternal(() => {
1847
+ }, first);
1848
+ const reset = () => storeSetter(
1849
+ store,
1850
+ reconcile(
1851
+ derived ? first(store) || store : first,
1852
+ (options == null ? void 0 : options.key) || "id",
1853
+ options == null ? void 0 : options.all
1854
+ )
1855
+ );
1856
+ const write = (v) => {
1857
+ if (!ActiveTransition)
1858
+ throw new Error("createOptimisticStore can only be updated inside a transition");
1859
+ ActiveTransition.addOptimistic(reset);
1860
+ cloneGraph(node, true);
1861
+ queueMicrotask(() => reset.j && storeSetter(store, v));
1862
+ };
1863
+ return [store, write];
1864
+ }
1865
+
1636
1866
  // src/store/utils.ts
1637
1867
  function snapshot(item, map, lookup) {
1638
1868
  var _a;
@@ -1834,288 +2064,78 @@ function omit(props, ...keys) {
1834
2064
  return result;
1835
2065
  }
1836
2066
 
1837
- // src/signals.ts
1838
- function createSignal(first, second, third) {
1839
- if (typeof first === "function") {
1840
- const memo = createMemo((p) => {
1841
- const node2 = new Computation(
1842
- first(p ? untrack(p[0]) : second),
1843
- null,
1844
- third
1845
- );
1846
- return [node2.read.bind(node2), node2.write.bind(node2)];
1847
- });
1848
- return [() => memo()[0](), (value) => memo()[1](value)];
1849
- }
1850
- const o = getOwner();
1851
- const needsId = (o == null ? void 0 : o.id) != null;
1852
- const node = new Computation(
1853
- first,
1854
- null,
1855
- needsId ? { id: o.getNextChildId(), ...second } : second
1856
- );
1857
- return [node.read.bind(node), node.write.bind(node)];
1858
- }
1859
- function createMemo(compute2, value, options) {
1860
- let node = new Computation(
1861
- value,
1862
- compute2,
1863
- options
1864
- );
1865
- let resolvedValue;
1866
- return () => {
1867
- var _a, _b;
1868
- if (node) {
1869
- if (node.c === STATE_DISPOSED) {
1870
- node = void 0;
1871
- return resolvedValue;
1872
- }
1873
- resolvedValue = node.wait();
1874
- if (!((_a = node.a) == null ? void 0 : _a.length) && ((_b = node.m) == null ? void 0 : _b.k) !== node && !(node.h & UNINITIALIZED_BIT)) {
1875
- node.dispose();
1876
- node = void 0;
1877
- }
1878
- }
1879
- return resolvedValue;
1880
- };
1881
- }
1882
- function createAsync(compute2, value, options) {
1883
- let refreshing = false;
1884
- const node = new EagerComputation(
1885
- value,
1886
- (p) => {
1887
- const source = compute2(p, refreshing);
1888
- refreshing = false;
1889
- const isPromise = source instanceof Promise;
1890
- const iterator = source[Symbol.asyncIterator];
1891
- if (!isPromise && !iterator) {
1892
- return source;
1893
- }
1894
- let abort = false;
1895
- onCleanup(() => abort = true);
1896
- let transition2 = ActiveTransition;
1897
- if (isPromise) {
1898
- source.then(
1899
- (value3) => {
1900
- if (abort)
1901
- return;
1902
- if (transition2)
1903
- return transition2.runTransition(() => {
1904
- node.write(value3, 0, true);
1905
- }, true);
1906
- node.write(value3, 0, true);
1907
- },
1908
- (error) => {
1909
- if (abort)
1910
- return;
1911
- if (transition2)
1912
- return transition2.runTransition(() => node.E(error), true);
1913
- node.E(error);
1914
- }
1915
- );
1916
- } else {
1917
- (async () => {
1918
- try {
1919
- for await (let value3 of source) {
1920
- if (abort)
1921
- return;
1922
- if (transition2)
1923
- return transition2.runTransition(() => {
1924
- node.write(value3, 0, true);
1925
- transition2 = null;
1926
- }, true);
1927
- node.write(value3, 0, true);
1928
- }
1929
- } catch (error) {
1930
- if (abort)
1931
- return;
1932
- if (transition2)
1933
- return transition2.runTransition(() => {
1934
- node.E(error);
1935
- transition2 = null;
1936
- }, true);
1937
- node.E(error);
1938
- }
1939
- })();
1940
- }
1941
- throw new NotReadyError();
1942
- },
1943
- options
1944
- );
1945
- const read = node.wait.bind(node);
1946
- read.refresh = () => {
1947
- let n = node;
1948
- if (ActiveTransition && !node.e) {
1949
- n = cloneGraph(node);
1950
- }
1951
- n.c = STATE_DIRTY;
1952
- refreshing = true;
1953
- n.K();
1954
- };
1955
- return read;
1956
- }
1957
- function createEffect(compute2, effect, value, options) {
1958
- void new Effect(
1959
- value,
1960
- compute2,
1961
- effect.effect ? effect.effect : effect,
1962
- effect.error,
1963
- options
1964
- );
1965
- }
1966
- function createRenderEffect(compute2, effect, value, options) {
1967
- void new Effect(value, compute2, effect, void 0, {
1968
- render: true,
1969
- ...options
1970
- });
1971
- }
1972
- function createRoot(init, options) {
1973
- const owner = new Owner(options == null ? void 0 : options.id);
1974
- return compute(owner, !init.length ? init : () => init(() => owner.dispose()), null);
1975
- }
1976
- function runWithOwner(owner, run) {
1977
- return compute(owner, run, null);
1978
- }
1979
- function resolve(fn) {
1980
- return new Promise((res, rej) => {
1981
- createRoot((dispose) => {
1982
- new EagerComputation(void 0, () => {
1983
- try {
1984
- res(fn());
1985
- } catch (err) {
1986
- if (err instanceof NotReadyError)
1987
- throw err;
1988
- rej(err);
1989
- }
1990
- dispose();
1991
- });
1992
- });
1993
- });
1994
- }
1995
- function createPending() {
1996
- const node = new Computation(false, null);
1997
- const reset = () => node.write(false);
1998
- function write() {
1999
- if (!ActiveTransition)
2000
- return false;
2001
- ActiveTransition.addOptimistic(reset);
2002
- queueMicrotask(() => reset.j && node.write(true));
2003
- }
2004
- function read() {
2005
- const v = node.read();
2006
- return ActiveTransition ? false : v;
2007
- }
2008
- return [read, write];
2009
- }
2010
- function useTransition() {
2011
- const [pending, setPending] = createPending();
2012
- function start(fn) {
2013
- transition((resume) => {
2014
- setPending(true);
2015
- return fn(resume);
2016
- });
2017
- }
2018
- return [pending, start];
2019
- }
2020
- function createOptimistic(first, second, options) {
2021
- let store, setStore;
2022
- if (typeof first === "function") {
2023
- [store, setStore] = createStore((s) => {
2024
- const value = first(s);
2025
- if (!ActiveTransition)
2026
- return value;
2027
- ActiveTransition.addOptimistic(reset);
2028
- }, {});
2029
- } else
2030
- [store, setStore] = createStore(first);
2031
- const reset = () => setStore(
2032
- reconcile(
2033
- typeof first === "function" ? first(second) : first,
2034
- (options == null ? void 0 : options.key) || "id",
2035
- options == null ? void 0 : options.all
2036
- )
2037
- );
2038
- function write(v) {
2039
- if (!ActiveTransition)
2040
- throw new Error("createOptimistic can only be updated inside a transition");
2041
- ActiveTransition.addOptimistic(reset);
2042
- queueMicrotask(() => reset.j && setStore(v));
2043
- }
2044
- return [store, write];
2045
- }
2046
-
2047
2067
  // src/map.ts
2048
2068
  function mapArray(list, map, options) {
2049
2069
  const keyFn = typeof (options == null ? void 0 : options.keyed) === "function" ? options.keyed : void 0;
2050
2070
  return updateKeyedMap.bind({
2051
- S: new Owner(),
2071
+ U: new Owner(),
2052
2072
  o: 0,
2053
2073
  ia: list,
2054
- G: [],
2055
- P: map,
2056
- i: [],
2057
- d: [],
2058
- Q: keyFn,
2074
+ F: [],
2075
+ R: map,
2076
+ h: [],
2077
+ e: [],
2078
+ S: keyFn,
2059
2079
  p: keyFn || (options == null ? void 0 : options.keyed) === false ? [] : void 0,
2060
2080
  q: map.length > 1 ? [] : void 0,
2061
- T: options == null ? void 0 : options.fallback
2081
+ V: options == null ? void 0 : options.fallback
2062
2082
  });
2063
2083
  }
2064
2084
  var pureOptions = { pureWrite: true };
2065
2085
  function updateKeyedMap() {
2066
2086
  const newItems = this.ia() || [], newLen = newItems.length;
2067
2087
  newItems[$TRACK];
2068
- runWithOwner(this.S, () => {
2088
+ runWithOwner(this.U, () => {
2069
2089
  let i, j, mapper = this.p ? () => {
2070
2090
  this.p[j] = new Computation(newItems[j], null, pureOptions);
2071
2091
  this.q && (this.q[j] = new Computation(j, null, pureOptions));
2072
- return this.P(
2092
+ return this.R(
2073
2093
  Computation.prototype.read.bind(this.p[j]),
2074
2094
  this.q ? Computation.prototype.read.bind(this.q[j]) : void 0
2075
2095
  );
2076
2096
  } : this.q ? () => {
2077
2097
  const item = newItems[j];
2078
2098
  this.q[j] = new Computation(j, null, pureOptions);
2079
- return this.P(() => item, Computation.prototype.read.bind(this.q[j]));
2099
+ return this.R(() => item, Computation.prototype.read.bind(this.q[j]));
2080
2100
  } : () => {
2081
2101
  const item = newItems[j];
2082
- return this.P(() => item);
2102
+ return this.R(() => item);
2083
2103
  };
2084
2104
  if (newLen === 0) {
2085
2105
  if (this.o !== 0) {
2086
- this.S.dispose(false);
2087
- this.d = [];
2088
- this.G = [];
2089
- this.i = [];
2106
+ this.U.dispose(false);
2107
+ this.e = [];
2108
+ this.F = [];
2109
+ this.h = [];
2090
2110
  this.o = 0;
2091
2111
  this.p && (this.p = []);
2092
2112
  this.q && (this.q = []);
2093
2113
  }
2094
- if (this.T && !this.i[0]) {
2095
- this.i[0] = compute(
2096
- this.d[0] = new Owner(),
2097
- this.T,
2114
+ if (this.V && !this.h[0]) {
2115
+ this.h[0] = compute(
2116
+ this.e[0] = new Owner(),
2117
+ this.V,
2098
2118
  null
2099
2119
  );
2100
2120
  }
2101
2121
  } else if (this.o === 0) {
2102
- if (this.d[0])
2103
- this.d[0].dispose();
2104
- this.i = new Array(newLen);
2122
+ if (this.e[0])
2123
+ this.e[0].dispose();
2124
+ this.h = new Array(newLen);
2105
2125
  for (j = 0; j < newLen; j++) {
2106
- this.G[j] = newItems[j];
2107
- this.i[j] = compute(this.d[j] = new Owner(), mapper, null);
2126
+ this.F[j] = newItems[j];
2127
+ this.h[j] = compute(this.e[j] = new Owner(), mapper, null);
2108
2128
  }
2109
2129
  this.o = newLen;
2110
2130
  } else {
2111
2131
  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;
2112
- for (start = 0, end = Math.min(this.o, newLen); start < end && (this.G[start] === newItems[start] || this.p && compare(this.Q, this.G[start], newItems[start])); start++) {
2132
+ for (start = 0, end = Math.min(this.o, newLen); start < end && (this.F[start] === newItems[start] || this.p && compare(this.S, this.F[start], newItems[start])); start++) {
2113
2133
  if (this.p)
2114
2134
  this.p[start].write(newItems[start]);
2115
2135
  }
2116
- for (end = this.o - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.G[end] === newItems[newEnd] || this.p && compare(this.Q, this.G[end], newItems[newEnd])); end--, newEnd--) {
2117
- temp[newEnd] = this.i[end];
2118
- tempNodes[newEnd] = this.d[end];
2136
+ for (end = this.o - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.F[end] === newItems[newEnd] || this.p && compare(this.S, this.F[end], newItems[newEnd])); end--, newEnd--) {
2137
+ temp[newEnd] = this.h[end];
2138
+ tempNodes[newEnd] = this.e[end];
2119
2139
  tempRows && (tempRows[newEnd] = this.p[end]);
2120
2140
  tempIndexes && (tempIndexes[newEnd] = this.q[end]);
2121
2141
  }
@@ -2123,29 +2143,29 @@ function updateKeyedMap() {
2123
2143
  newIndicesNext = new Array(newEnd + 1);
2124
2144
  for (j = newEnd; j >= start; j--) {
2125
2145
  item = newItems[j];
2126
- key = this.Q ? this.Q(item) : item;
2146
+ key = this.S ? this.S(item) : item;
2127
2147
  i = newIndices.get(key);
2128
2148
  newIndicesNext[j] = i === void 0 ? -1 : i;
2129
2149
  newIndices.set(key, j);
2130
2150
  }
2131
2151
  for (i = start; i <= end; i++) {
2132
- item = this.G[i];
2133
- key = this.Q ? this.Q(item) : item;
2152
+ item = this.F[i];
2153
+ key = this.S ? this.S(item) : item;
2134
2154
  j = newIndices.get(key);
2135
2155
  if (j !== void 0 && j !== -1) {
2136
- temp[j] = this.i[i];
2137
- tempNodes[j] = this.d[i];
2156
+ temp[j] = this.h[i];
2157
+ tempNodes[j] = this.e[i];
2138
2158
  tempRows && (tempRows[j] = this.p[i]);
2139
2159
  tempIndexes && (tempIndexes[j] = this.q[i]);
2140
2160
  j = newIndicesNext[j];
2141
2161
  newIndices.set(key, j);
2142
2162
  } else
2143
- this.d[i].dispose();
2163
+ this.e[i].dispose();
2144
2164
  }
2145
2165
  for (j = start; j < newLen; j++) {
2146
2166
  if (j in temp) {
2147
- this.i[j] = temp[j];
2148
- this.d[j] = tempNodes[j];
2167
+ this.h[j] = temp[j];
2168
+ this.e[j] = tempNodes[j];
2149
2169
  if (tempRows) {
2150
2170
  this.p[j] = tempRows[j];
2151
2171
  this.p[j].write(newItems[j]);
@@ -2155,90 +2175,90 @@ function updateKeyedMap() {
2155
2175
  this.q[j].write(j);
2156
2176
  }
2157
2177
  } else {
2158
- this.i[j] = compute(this.d[j] = new Owner(), mapper, null);
2178
+ this.h[j] = compute(this.e[j] = new Owner(), mapper, null);
2159
2179
  }
2160
2180
  }
2161
- this.i = this.i.slice(0, this.o = newLen);
2162
- this.G = newItems.slice(0);
2181
+ this.h = this.h.slice(0, this.o = newLen);
2182
+ this.F = newItems.slice(0);
2163
2183
  }
2164
2184
  });
2165
- return this.i;
2185
+ return this.h;
2166
2186
  }
2167
2187
  function repeat(count, map, options) {
2168
2188
  return updateRepeat.bind({
2169
- S: new Owner(),
2189
+ U: new Owner(),
2170
2190
  o: 0,
2171
- z: 0,
2191
+ A: 0,
2172
2192
  ja: count,
2173
- P: map,
2174
- d: [],
2175
- i: [],
2193
+ R: map,
2194
+ e: [],
2195
+ h: [],
2176
2196
  ka: options == null ? void 0 : options.from,
2177
- T: options == null ? void 0 : options.fallback
2197
+ V: options == null ? void 0 : options.fallback
2178
2198
  });
2179
2199
  }
2180
2200
  function updateRepeat() {
2181
2201
  var _a;
2182
2202
  const newLen = this.ja();
2183
2203
  const from = ((_a = this.ka) == null ? void 0 : _a.call(this)) || 0;
2184
- runWithOwner(this.S, () => {
2204
+ runWithOwner(this.U, () => {
2185
2205
  if (newLen === 0) {
2186
2206
  if (this.o !== 0) {
2187
- this.S.dispose(false);
2188
- this.d = [];
2189
- this.i = [];
2207
+ this.U.dispose(false);
2208
+ this.e = [];
2209
+ this.h = [];
2190
2210
  this.o = 0;
2191
2211
  }
2192
- if (this.T && !this.i[0]) {
2193
- this.i[0] = compute(
2194
- this.d[0] = new Owner(),
2195
- this.T,
2212
+ if (this.V && !this.h[0]) {
2213
+ this.h[0] = compute(
2214
+ this.e[0] = new Owner(),
2215
+ this.V,
2196
2216
  null
2197
2217
  );
2198
2218
  }
2199
2219
  return;
2200
2220
  }
2201
2221
  const to = from + newLen;
2202
- const prevTo = this.z + this.o;
2203
- if (this.o === 0 && this.d[0])
2204
- this.d[0].dispose();
2222
+ const prevTo = this.A + this.o;
2223
+ if (this.o === 0 && this.e[0])
2224
+ this.e[0].dispose();
2205
2225
  for (let i = to; i < prevTo; i++)
2206
- this.d[i - this.z].dispose();
2207
- if (this.z < from) {
2208
- let i = this.z;
2226
+ this.e[i - this.A].dispose();
2227
+ if (this.A < from) {
2228
+ let i = this.A;
2209
2229
  while (i < from && i < this.o)
2210
- this.d[i++].dispose();
2211
- this.d.splice(0, from - this.z);
2212
- this.i.splice(0, from - this.z);
2213
- } else if (this.z > from) {
2214
- let i = prevTo - this.z - 1;
2215
- let difference = this.z - from;
2216
- this.d.length = this.i.length = newLen;
2230
+ this.e[i++].dispose();
2231
+ this.e.splice(0, from - this.A);
2232
+ this.h.splice(0, from - this.A);
2233
+ } else if (this.A > from) {
2234
+ let i = prevTo - this.A - 1;
2235
+ let difference = this.A - from;
2236
+ this.e.length = this.h.length = newLen;
2217
2237
  while (i >= difference) {
2218
- this.d[i] = this.d[i - difference];
2219
- this.i[i] = this.i[i - difference];
2238
+ this.e[i] = this.e[i - difference];
2239
+ this.h[i] = this.h[i - difference];
2220
2240
  i--;
2221
2241
  }
2222
2242
  for (let i2 = 0; i2 < difference; i2++) {
2223
- this.i[i2] = compute(
2224
- this.d[i2] = new Owner(),
2225
- () => this.P(i2 + from),
2243
+ this.h[i2] = compute(
2244
+ this.e[i2] = new Owner(),
2245
+ () => this.R(i2 + from),
2226
2246
  null
2227
2247
  );
2228
2248
  }
2229
2249
  }
2230
2250
  for (let i = prevTo; i < to; i++) {
2231
- this.i[i - from] = compute(
2232
- this.d[i - from] = new Owner(),
2233
- () => this.P(i),
2251
+ this.h[i - from] = compute(
2252
+ this.e[i - from] = new Owner(),
2253
+ () => this.R(i),
2234
2254
  null
2235
2255
  );
2236
2256
  }
2237
- this.i = this.i.slice(0, newLen);
2238
- this.z = from;
2257
+ this.h = this.h.slice(0, newLen);
2258
+ this.A = from;
2239
2259
  this.o = newLen;
2240
2260
  });
2241
- return this.i;
2261
+ return this.h;
2242
2262
  }
2243
2263
  function compare(key, a, b) {
2244
2264
  return key ? key(a) === key(b) : true;
@@ -2246,24 +2266,24 @@ function compare(key, a, b) {
2246
2266
 
2247
2267
  // src/boundaries.ts
2248
2268
  var BoundaryComputation = class extends EagerComputation {
2249
- U;
2269
+ W;
2250
2270
  constructor(compute2, propagationMask) {
2251
2271
  super(void 0, compute2, { defer: true });
2252
- this.U = propagationMask;
2272
+ this.W = propagationMask;
2253
2273
  }
2254
2274
  write(value, flags) {
2255
- super.write(value, flags & ~this.U);
2256
- if (this.U & LOADING_BIT && !(this.h & UNINITIALIZED_BIT || ActiveTransition)) {
2275
+ super.write(value, flags & ~this.W);
2276
+ if (this.W & LOADING_BIT && !(this.i & UNINITIALIZED_BIT || ActiveTransition)) {
2257
2277
  flags &= ~LOADING_BIT;
2258
2278
  }
2259
- getQueue(this).notify(this, this.U, flags);
2279
+ getQueue(this).notify(this, this.W, flags);
2260
2280
  return this.l;
2261
2281
  }
2262
2282
  };
2263
2283
  function createBoundChildren(owner, fn, queue, mask) {
2264
- const parentQueue = owner.B;
2265
- parentQueue.addChild(owner.B = queue);
2266
- onCleanup(() => parentQueue.removeChild(owner.B));
2284
+ const parentQueue = owner.C;
2285
+ parentQueue.addChild(owner.C = queue);
2286
+ onCleanup(() => parentQueue.removeChild(owner.C));
2267
2287
  return compute(
2268
2288
  owner,
2269
2289
  () => {
@@ -2274,22 +2294,20 @@ function createBoundChildren(owner, fn, queue, mask) {
2274
2294
  );
2275
2295
  }
2276
2296
  var ConditionalQueue = class extends Queue {
2277
- t;
2278
- V = /* @__PURE__ */ new Set();
2297
+ x;
2298
+ X = /* @__PURE__ */ new Set();
2279
2299
  s = /* @__PURE__ */ new Set();
2280
2300
  constructor(disabled) {
2281
2301
  super();
2282
- this.t = disabled;
2302
+ this.x = disabled;
2283
2303
  }
2284
2304
  run(type) {
2285
- if (!type || this.t.read())
2305
+ if (!type || this.x.read())
2286
2306
  return;
2287
2307
  return super.run(type);
2288
2308
  }
2289
2309
  notify(node, type, flags) {
2290
- if (ActiveTransition && ActiveTransition.r.has(this))
2291
- return ActiveTransition.r.get(this).notify(node, type, flags);
2292
- if (this.t.read()) {
2310
+ if (this.x.read()) {
2293
2311
  if (type & LOADING_BIT) {
2294
2312
  if (flags & LOADING_BIT) {
2295
2313
  this.s.add(node);
@@ -2299,9 +2317,9 @@ var ConditionalQueue = class extends Queue {
2299
2317
  }
2300
2318
  if (type & ERROR_BIT) {
2301
2319
  if (flags & ERROR_BIT) {
2302
- this.V.add(node);
2320
+ this.X.add(node);
2303
2321
  type &= ~ERROR_BIT;
2304
- } else if (this.V.delete(node))
2322
+ } else if (this.X.delete(node))
2305
2323
  type &= ~ERROR_BIT;
2306
2324
  }
2307
2325
  }
@@ -2309,42 +2327,40 @@ var ConditionalQueue = class extends Queue {
2309
2327
  }
2310
2328
  merge(queue) {
2311
2329
  queue.s.forEach((n) => this.notify(n, LOADING_BIT, LOADING_BIT));
2312
- queue.V.forEach((n) => this.notify(n, ERROR_BIT, ERROR_BIT));
2330
+ queue.X.forEach((n) => this.notify(n, ERROR_BIT, ERROR_BIT));
2313
2331
  super.merge(queue);
2314
2332
  }
2315
2333
  };
2316
2334
  var CollectionQueue = class extends Queue {
2317
- J;
2318
- d = /* @__PURE__ */ new Set();
2319
- t = new Computation(false, null, { pureWrite: true });
2335
+ K;
2336
+ e = /* @__PURE__ */ new Set();
2337
+ x = new Computation(false, null, { pureWrite: true });
2320
2338
  constructor(type) {
2321
2339
  super();
2322
- this.J = type;
2340
+ this.K = type;
2323
2341
  }
2324
2342
  run(type) {
2325
- if (!type || this.t.read())
2343
+ if (!type || this.x.read())
2326
2344
  return;
2327
2345
  return super.run(type);
2328
2346
  }
2329
2347
  notify(node, type, flags) {
2330
- if (ActiveTransition && ActiveTransition.r.has(this))
2331
- return ActiveTransition.r.get(this).notify(node, type, flags);
2332
- if (!(type & this.J))
2348
+ if (!(type & this.K))
2333
2349
  return super.notify(node, type, flags);
2334
- if (flags & this.J) {
2335
- this.d.add(node);
2336
- if (this.d.size === 1)
2337
- this.t.write(true);
2338
- } else if (this.d.size > 0) {
2339
- this.d.delete(node);
2340
- if (this.d.size === 0)
2341
- this.t.write(false);
2342
- }
2343
- type &= ~this.J;
2350
+ if (flags & this.K) {
2351
+ this.e.add(node);
2352
+ if (this.e.size === 1)
2353
+ this.x.write(true);
2354
+ } else if (this.e.size > 0) {
2355
+ this.e.delete(node);
2356
+ if (this.e.size === 0)
2357
+ this.x.write(false);
2358
+ }
2359
+ type &= ~this.K;
2344
2360
  return type ? super.notify(node, type, flags) : true;
2345
2361
  }
2346
2362
  merge(queue) {
2347
- queue.d.forEach((n) => this.notify(n, this.J, this.J));
2363
+ queue.e.forEach((n) => this.notify(n, this.K, this.K));
2348
2364
  super.merge(queue);
2349
2365
  }
2350
2366
  };
@@ -2355,25 +2371,25 @@ function createBoundary(fn, condition) {
2355
2371
  );
2356
2372
  const tree = createBoundChildren(owner, fn, queue, 0);
2357
2373
  new EagerComputation(void 0, () => {
2358
- const disabled = queue.t.read();
2359
- tree.U = disabled ? ERROR_BIT | LOADING_BIT : 0;
2374
+ const disabled = queue.x.read();
2375
+ tree.W = disabled ? ERROR_BIT | LOADING_BIT : 0;
2360
2376
  if (!disabled) {
2361
2377
  queue.s.forEach((node) => queue.notify(node, LOADING_BIT, LOADING_BIT));
2362
- queue.V.forEach((node) => queue.notify(node, ERROR_BIT, ERROR_BIT));
2378
+ queue.X.forEach((node) => queue.notify(node, ERROR_BIT, ERROR_BIT));
2363
2379
  queue.s.clear();
2364
- queue.V.clear();
2380
+ queue.X.clear();
2365
2381
  }
2366
2382
  });
2367
- return () => queue.t.read() ? void 0 : tree.read();
2383
+ return () => queue.x.read() ? void 0 : tree.read();
2368
2384
  }
2369
2385
  function createCollectionBoundary(type, fn, fallback) {
2370
2386
  const owner = new Owner();
2371
2387
  const queue = new CollectionQueue(type);
2372
2388
  const tree = createBoundChildren(owner, fn, queue, type);
2373
2389
  const decision = new Computation(void 0, () => {
2374
- if (!queue.t.read()) {
2390
+ if (!queue.x.read()) {
2375
2391
  const resolved = tree.read();
2376
- if (!untrack(() => queue.t.read()))
2392
+ if (!untrack(() => queue.x.read()))
2377
2393
  return resolved;
2378
2394
  }
2379
2395
  return fallback(queue);
@@ -2385,14 +2401,14 @@ function createSuspense(fn, fallback) {
2385
2401
  }
2386
2402
  function createErrorBoundary(fn, fallback) {
2387
2403
  return createCollectionBoundary(ERROR_BIT, fn, (queue) => {
2388
- let node = getTransitionSource(queue.d.values().next().value);
2389
- return fallback(node.L, () => {
2404
+ let node = getTransitionSource(queue.e.values().next().value);
2405
+ return fallback(node.O, () => {
2390
2406
  incrementClock();
2391
- for (let node2 of queue.d) {
2392
- if (ActiveTransition && !node2.e)
2407
+ for (let node2 of queue.e) {
2408
+ if (ActiveTransition && !node2.d)
2393
2409
  node2 = cloneGraph(node2);
2394
- node2.c = STATE_DIRTY;
2395
- getQueue(node2).enqueue(node2.C, node2.F.bind(node2));
2410
+ node2.b = STATE_DIRTY;
2411
+ getQueue(node2).enqueue(node2.r, node2.w.bind(node2));
2396
2412
  }
2397
2413
  });
2398
2414
  });
@@ -2469,12 +2485,15 @@ exports.createEffect = createEffect;
2469
2485
  exports.createErrorBoundary = createErrorBoundary;
2470
2486
  exports.createMemo = createMemo;
2471
2487
  exports.createOptimistic = createOptimistic;
2488
+ exports.createOptimisticStore = createOptimisticStore;
2472
2489
  exports.createProjection = createProjection;
2490
+ exports.createReaction = createReaction;
2473
2491
  exports.createRenderEffect = createRenderEffect;
2474
2492
  exports.createRoot = createRoot;
2475
2493
  exports.createSignal = createSignal;
2476
2494
  exports.createStore = createStore;
2477
2495
  exports.createSuspense = createSuspense;
2496
+ exports.createTrackedEffect = createTrackedEffect;
2478
2497
  exports.deep = deep;
2479
2498
  exports.flatten = flatten;
2480
2499
  exports.flush = flush;
@@ -2494,7 +2513,6 @@ exports.onCleanup = onCleanup;
2494
2513
  exports.reconcile = reconcile;
2495
2514
  exports.repeat = repeat;
2496
2515
  exports.resolve = resolve;
2497
- exports.runWithObserver = runWithObserver;
2498
2516
  exports.runWithOwner = runWithOwner;
2499
2517
  exports.setContext = setContext;
2500
2518
  exports.snapshot = snapshot;