@solidjs/signals 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/prod.js CHANGED
@@ -24,8 +24,7 @@ var EffectError = class extends Error {
24
24
  var STATE_CLEAN = 0;
25
25
  var STATE_CHECK = 1;
26
26
  var STATE_DIRTY = 2;
27
- var STATE_UNINITIALIZED = 3;
28
- var STATE_DISPOSED = 4;
27
+ var STATE_DISPOSED = 3;
29
28
  var EFFECT_PURE = 0;
30
29
  var EFFECT_RENDER = 1;
31
30
  var EFFECT_USER = 2;
@@ -112,7 +111,7 @@ var Owner = class {
112
111
  l = null;
113
112
  p = defaultContext;
114
113
  m = null;
115
- g = null;
114
+ b = null;
116
115
  constructor(signal = false) {
117
116
  if (currentOwner && !signal)
118
117
  currentOwner.append(this);
@@ -130,8 +129,8 @@ var Owner = class {
130
129
  if (this.m) {
131
130
  child.m = !child.m ? this.m : [...child.m, ...this.m];
132
131
  }
133
- if (this.g)
134
- child.g = this.g;
132
+ if (this.b)
133
+ child.b = this.b;
135
134
  }
136
135
  dispose(self = true) {
137
136
  if (this.a === STATE_DISPOSED)
@@ -139,19 +138,19 @@ var Owner = class {
139
138
  let head = self ? this.s || this.r : this, current = this.n, next = null;
140
139
  while (current && current.r === this) {
141
140
  current.dispose(true);
142
- current.y();
141
+ current.z();
143
142
  next = current.n;
144
143
  current.n = null;
145
144
  current = next;
146
145
  }
147
146
  if (self)
148
- this.y();
147
+ this.z();
149
148
  if (current)
150
149
  current.s = !self ? this : this.s;
151
150
  if (head)
152
151
  head.n = current;
153
152
  }
154
- y() {
153
+ z() {
155
154
  if (this.s)
156
155
  this.s.n = null;
157
156
  this.r = null;
@@ -234,6 +233,8 @@ var ERROR_OFFSET = 0;
234
233
  var ERROR_BIT = 1 << ERROR_OFFSET;
235
234
  var LOADING_OFFSET = 1;
236
235
  var LOADING_BIT = 1 << LOADING_OFFSET;
236
+ var UNINITIALIZED_OFFSET = 2;
237
+ var UNINITIALIZED_BIT = 1 << UNINITIALIZED_OFFSET;
237
238
  var DEFAULT_FLAGS = ERROR_BIT;
238
239
 
239
240
  // src/core/core.ts
@@ -243,8 +244,9 @@ var newSources = null;
243
244
  var newSourcesIndex = 0;
244
245
  var newFlags = 0;
245
246
  var clock = 0;
246
- var syncResolve = false;
247
+ var notStale = false;
247
248
  var updateCheck = null;
249
+ var staleCheck = null;
248
250
  function getObserver() {
249
251
  return currentObserver;
250
252
  }
@@ -256,43 +258,45 @@ function incrementClock() {
256
258
  }
257
259
  var UNCHANGED = Symbol(0);
258
260
  var Computation = class extends Owner {
259
- d = null;
260
- b = null;
261
- e;
262
- w;
261
+ g = null;
262
+ e = null;
263
+ c;
264
+ D;
265
+ t;
263
266
  // Used in __DEV__ mode, hopefully removed in production
264
- Y;
267
+ Z;
265
268
  // Using false is an optimization as an alternative to _equals: () => false
266
269
  // which could enable more efficient DIRTY notification
267
- L = isEqual;
268
- S;
270
+ N = isEqual;
271
+ T;
269
272
  /** Whether the computation is an error or has ancestors that are unresolved */
270
- h = 0;
273
+ d = 0;
271
274
  /** Which flags raised by sources are handled, vs. being passed through. */
272
- M = DEFAULT_FLAGS;
273
- N = null;
274
- z = -1;
275
+ O = DEFAULT_FLAGS;
276
+ P = null;
277
+ A = -1;
275
278
  H = false;
276
279
  constructor(initialValue, compute2, options) {
277
280
  super(compute2 === null);
278
- this.w = compute2;
279
- this.a = compute2 ? STATE_UNINITIALIZED : STATE_CLEAN;
280
- this.e = initialValue;
281
+ this.t = compute2;
282
+ this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
283
+ this.d = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
284
+ this.c = initialValue;
281
285
  if (options?.equals !== void 0)
282
- this.L = options.equals;
286
+ this.N = options.equals;
283
287
  if (options?.unobserved)
284
- this.S = options?.unobserved;
288
+ this.T = options?.unobserved;
285
289
  }
286
- T() {
287
- if (this.w)
290
+ U() {
291
+ if (this.t)
288
292
  this.x();
289
- if (!this.w || this.d?.length)
293
+ if (!this.t || this.g?.length)
290
294
  track(this);
291
- newFlags |= this.h & ~currentMask;
292
- if (this.h & ERROR_BIT) {
293
- throw this.e;
295
+ newFlags |= this.d & ~currentMask;
296
+ if (this.d & ERROR_BIT) {
297
+ throw this.D;
294
298
  } else {
295
- return this.e;
299
+ return this.c;
296
300
  }
297
301
  }
298
302
  /**
@@ -300,7 +304,7 @@ var Computation = class extends Owner {
300
304
  * Automatically re-executes the surrounding computation when the value changes
301
305
  */
302
306
  read() {
303
- return this.T();
307
+ return this.U();
304
308
  }
305
309
  /**
306
310
  * Return the current value of this computation
@@ -310,13 +314,15 @@ var Computation = class extends Owner {
310
314
  * before continuing
311
315
  */
312
316
  wait() {
313
- if (this.w && this.h & ERROR_BIT && this.z <= clock) {
317
+ if (this.t && this.d & ERROR_BIT && this.A <= clock) {
314
318
  update(this);
315
319
  }
316
- if (!syncResolve && this.loading()) {
320
+ if ((notStale || this.d & UNINITIALIZED_BIT) && this.loading()) {
317
321
  throw new NotReadyError();
318
322
  }
319
- return this.T();
323
+ if (staleCheck && this.d & LOADING_BIT)
324
+ staleCheck.c = true;
325
+ return this.U();
320
326
  }
321
327
  /**
322
328
  * Return true if the computation is the value is dependent on an unresolved promise
@@ -326,30 +332,32 @@ var Computation = class extends Owner {
326
332
  * loading state changes
327
333
  */
328
334
  loading() {
329
- if (this.N === null) {
330
- this.N = loadingState(this);
335
+ if (this.P === null) {
336
+ this.P = loadingState(this);
331
337
  }
332
- return this.N.read();
338
+ return this.P.read();
333
339
  }
334
340
  /** Update the computation with a new value. */
335
341
  write(value, flags = 0, raw = false) {
336
- const newValue = !raw && typeof value === "function" ? value(this.e) : value;
337
- const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.a === STATE_UNINITIALIZED || this.L === false || !this.L(this.e, newValue));
338
- if (valueChanged)
339
- this.e = newValue;
340
- const changedFlagsMask = this.h ^ flags, changedFlags = changedFlagsMask & flags;
341
- this.h = flags;
342
- this.z = clock + 1;
343
- if (this.b) {
344
- for (let i = 0; i < this.b.length; i++) {
342
+ const newValue = !raw && typeof value === "function" ? value(this.c) : value;
343
+ const valueChanged = newValue !== UNCHANGED && (!!(this.d & UNINITIALIZED_BIT) || this.N === false || !this.N(this.c, newValue));
344
+ if (valueChanged) {
345
+ this.c = newValue;
346
+ this.D = void 0;
347
+ }
348
+ const changedFlagsMask = this.d ^ flags, changedFlags = changedFlagsMask & flags;
349
+ this.d = flags;
350
+ this.A = clock + 1;
351
+ if (this.e) {
352
+ for (let i = 0; i < this.e.length; i++) {
345
353
  if (valueChanged) {
346
- this.b[i].q(STATE_DIRTY);
354
+ this.e[i].q(STATE_DIRTY);
347
355
  } else if (changedFlagsMask) {
348
- this.b[i].U(changedFlagsMask, changedFlags);
356
+ this.e[i].V(changedFlagsMask, changedFlags);
349
357
  }
350
358
  }
351
359
  }
352
- return this.e;
360
+ return this.c;
353
361
  }
354
362
  /**
355
363
  * Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
@@ -359,9 +367,9 @@ var Computation = class extends Owner {
359
367
  return;
360
368
  this.H = !!skipQueue;
361
369
  this.a = state;
362
- if (this.b) {
363
- for (let i = 0; i < this.b.length; i++) {
364
- this.b[i].q(STATE_CHECK, skipQueue);
370
+ if (this.e) {
371
+ for (let i = 0; i < this.e.length; i++) {
372
+ this.e[i].q(STATE_CHECK, skipQueue);
365
373
  }
366
374
  }
367
375
  }
@@ -371,30 +379,31 @@ var Computation = class extends Owner {
371
379
  * @param mask A bitmask for which flag(s) were changed.
372
380
  * @param newFlags The source's new flags, masked to just the changed ones.
373
381
  */
374
- U(mask, newFlags2) {
382
+ V(mask, newFlags2) {
375
383
  if (this.a >= STATE_DIRTY)
376
384
  return;
377
- if (mask & this.M) {
385
+ if (mask & this.O) {
378
386
  this.q(STATE_DIRTY);
379
387
  return;
380
388
  }
381
389
  if (this.a >= STATE_CHECK)
382
390
  return;
383
- const prevFlags = this.h & mask;
391
+ const prevFlags = this.d & mask;
384
392
  const deltaFlags = prevFlags ^ newFlags2;
385
393
  if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
386
394
  this.q(STATE_CHECK);
387
395
  } else {
388
- this.h ^= deltaFlags;
389
- if (this.b) {
390
- for (let i = 0; i < this.b.length; i++) {
391
- this.b[i].U(mask, newFlags2);
396
+ this.d ^= deltaFlags;
397
+ if (this.e) {
398
+ for (let i = 0; i < this.e.length; i++) {
399
+ this.e[i].V(mask, newFlags2);
392
400
  }
393
401
  }
394
402
  }
395
403
  }
396
- O(error) {
397
- this.write(error, this.h & ~LOADING_BIT | ERROR_BIT);
404
+ I(error) {
405
+ this.D = error;
406
+ this.write(UNCHANGED, this.d & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
398
407
  }
399
408
  /**
400
409
  * This is the core part of the reactivity system, which makes sure that the values are updated
@@ -412,15 +421,15 @@ var Computation = class extends Owner {
412
421
  }
413
422
  let observerFlags = 0;
414
423
  if (this.a === STATE_CHECK) {
415
- for (let i = 0; i < this.d.length; i++) {
416
- this.d[i].x();
417
- observerFlags |= this.d[i].h;
424
+ for (let i = 0; i < this.g.length; i++) {
425
+ this.g[i].x();
426
+ observerFlags |= this.g[i].d;
418
427
  if (this.a === STATE_DIRTY) {
419
428
  break;
420
429
  }
421
430
  }
422
431
  }
423
- if (this.a === STATE_DIRTY || this.a === STATE_UNINITIALIZED) {
432
+ if (this.a === STATE_DIRTY) {
424
433
  update(this);
425
434
  } else {
426
435
  this.write(UNCHANGED, observerFlags);
@@ -430,12 +439,12 @@ var Computation = class extends Owner {
430
439
  /**
431
440
  * Remove ourselves from the owner graph and the computation graph
432
441
  */
433
- y() {
442
+ z() {
434
443
  if (this.a === STATE_DISPOSED)
435
444
  return;
436
- if (this.d)
445
+ if (this.g)
437
446
  removeSourceObservers(this, 0);
438
- super.y();
447
+ super.z();
439
448
  }
440
449
  };
441
450
  function loadingState(node) {
@@ -446,17 +455,17 @@ function loadingState(node) {
446
455
  () => {
447
456
  track(node);
448
457
  node.x();
449
- return !!(node.h & LOADING_BIT);
458
+ return !!(node.d & LOADING_BIT);
450
459
  },
451
460
  options
452
461
  );
453
- computation.M = ERROR_BIT | LOADING_BIT;
462
+ computation.O = ERROR_BIT | LOADING_BIT;
454
463
  setOwner(prevOwner);
455
464
  return computation;
456
465
  }
457
466
  function track(computation) {
458
467
  if (currentObserver) {
459
- if (!newSources && currentObserver.d && currentObserver.d[newSourcesIndex] === computation) {
468
+ if (!newSources && currentObserver.g && currentObserver.g[newSourcesIndex] === computation) {
460
469
  newSourcesIndex++;
461
470
  } else if (!newSources)
462
471
  newSources = [computation];
@@ -464,7 +473,7 @@ function track(computation) {
464
473
  newSources.push(computation);
465
474
  }
466
475
  if (updateCheck) {
467
- updateCheck.e = computation.z > currentObserver.z;
476
+ updateCheck.c = computation.A > currentObserver.A;
468
477
  }
469
478
  }
470
479
  }
@@ -476,56 +485,56 @@ function update(node) {
476
485
  try {
477
486
  node.dispose(false);
478
487
  node.emptyDisposal();
479
- const result = compute(node, node.w, node);
488
+ const result = compute(node, node.t, node);
480
489
  node.write(result, newFlags, true);
481
490
  } catch (error) {
482
491
  if (error instanceof NotReadyError) {
483
- node.write(UNCHANGED, newFlags | LOADING_BIT);
492
+ node.write(UNCHANGED, newFlags | LOADING_BIT | node.d & UNINITIALIZED_BIT);
484
493
  } else {
485
- node.O(error);
494
+ node.I(error);
486
495
  }
487
496
  } finally {
488
497
  if (newSources) {
489
- if (node.d)
498
+ if (node.g)
490
499
  removeSourceObservers(node, newSourcesIndex);
491
- if (node.d && newSourcesIndex > 0) {
492
- node.d.length = newSourcesIndex + newSources.length;
500
+ if (node.g && newSourcesIndex > 0) {
501
+ node.g.length = newSourcesIndex + newSources.length;
493
502
  for (let i = 0; i < newSources.length; i++) {
494
- node.d[newSourcesIndex + i] = newSources[i];
503
+ node.g[newSourcesIndex + i] = newSources[i];
495
504
  }
496
505
  } else {
497
- node.d = newSources;
506
+ node.g = newSources;
498
507
  }
499
508
  let source;
500
- for (let i = newSourcesIndex; i < node.d.length; i++) {
501
- source = node.d[i];
502
- if (!source.b)
503
- source.b = [node];
509
+ for (let i = newSourcesIndex; i < node.g.length; i++) {
510
+ source = node.g[i];
511
+ if (!source.e)
512
+ source.e = [node];
504
513
  else
505
- source.b.push(node);
514
+ source.e.push(node);
506
515
  }
507
- } else if (node.d && newSourcesIndex < node.d.length) {
516
+ } else if (node.g && newSourcesIndex < node.g.length) {
508
517
  removeSourceObservers(node, newSourcesIndex);
509
- node.d.length = newSourcesIndex;
518
+ node.g.length = newSourcesIndex;
510
519
  }
511
520
  newSources = prevSources;
512
521
  newSourcesIndex = prevSourcesIndex;
513
522
  newFlags = prevFlags;
514
- node.z = clock + 1;
523
+ node.A = clock + 1;
515
524
  node.a = STATE_CLEAN;
516
525
  }
517
526
  }
518
527
  function removeSourceObservers(node, index) {
519
528
  let source;
520
529
  let swap;
521
- for (let i = index; i < node.d.length; i++) {
522
- source = node.d[i];
523
- if (source.b) {
524
- swap = source.b.indexOf(node);
525
- source.b[swap] = source.b[source.b.length - 1];
526
- source.b.pop();
527
- if (!source.b.length)
528
- source.S?.();
530
+ for (let i = index; i < node.g.length; i++) {
531
+ source = node.g[i];
532
+ if (source.e) {
533
+ swap = source.e.indexOf(node);
534
+ source.e[swap] = source.e[source.e.length - 1];
535
+ source.e.pop();
536
+ if (!source.e.length)
537
+ source.T?.();
529
538
  }
530
539
  }
531
540
  }
@@ -539,31 +548,35 @@ function untrack(fn) {
539
548
  }
540
549
  function hasUpdated(fn) {
541
550
  const current = updateCheck;
542
- updateCheck = { e: false };
551
+ updateCheck = { c: false };
543
552
  try {
544
553
  fn();
545
- return updateCheck.e;
554
+ return updateCheck.c;
546
555
  } finally {
547
556
  updateCheck = current;
548
557
  }
549
558
  }
550
- function isPending(fn) {
559
+ function isStale(fn) {
560
+ const current = staleCheck;
561
+ staleCheck = { c: false };
551
562
  try {
552
- fn();
553
- return false;
554
- } catch (e) {
555
- return e instanceof NotReadyError;
563
+ latest(fn);
564
+ return staleCheck.c;
565
+ } catch {
566
+ } finally {
567
+ staleCheck = current;
556
568
  }
569
+ return false;
557
570
  }
558
- function resolveSync(fn) {
571
+ function latest(fn) {
559
572
  const prevFlags = newFlags;
560
- syncResolve = true;
573
+ const prevNotStale = notStale;
574
+ notStale = false;
561
575
  try {
562
576
  return fn();
563
- } catch {
564
577
  } finally {
565
578
  newFlags = prevFlags;
566
- syncResolve = false;
579
+ notStale = prevNotStale;
567
580
  }
568
581
  }
569
582
  function catchError(fn) {
@@ -575,16 +588,18 @@ function catchError(fn) {
575
588
  return e;
576
589
  }
577
590
  }
578
- function compute(owner, compute2, observer) {
579
- const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask;
591
+ function compute(owner, fn, observer) {
592
+ const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask, prevNotStale = notStale;
580
593
  currentObserver = observer;
581
- currentMask = observer?.M ?? DEFAULT_FLAGS;
594
+ currentMask = observer?.O ?? DEFAULT_FLAGS;
595
+ notStale = true;
582
596
  try {
583
- return compute2(observer ? observer.e : void 0);
597
+ return fn(observer ? observer.c : void 0);
584
598
  } finally {
585
599
  setOwner(prevOwner);
586
600
  currentObserver = prevObserver;
587
601
  currentMask = prevMask;
602
+ notStale = prevNotStale;
588
603
  }
589
604
  }
590
605
 
@@ -594,27 +609,27 @@ function schedule() {
594
609
  if (scheduled)
595
610
  return;
596
611
  scheduled = true;
597
- if (!globalQueue.I)
612
+ if (!globalQueue.J)
598
613
  queueMicrotask(flushSync);
599
614
  }
600
615
  var Queue = class {
601
- I = false;
602
- t = [[], [], []];
616
+ J = false;
617
+ u = [[], [], []];
603
618
  E = [];
604
619
  enqueue(type, node) {
605
- this.t[0].push(node);
620
+ this.u[0].push(node);
606
621
  if (type)
607
- this.t[type].push(node);
622
+ this.u[type].push(node);
608
623
  schedule();
609
624
  }
610
625
  run(type) {
611
- if (this.t[type].length) {
626
+ if (this.u[type].length) {
612
627
  if (type === EFFECT_PURE) {
613
- runPureQueue(this.t[type]);
614
- this.t[type] = [];
628
+ runPureQueue(this.u[type]);
629
+ this.u[type] = [];
615
630
  } else {
616
- const effects = this.t[type];
617
- this.t[type] = [];
631
+ const effects = this.u[type];
632
+ this.u[type] = [];
618
633
  runEffectQueue(effects);
619
634
  }
620
635
  }
@@ -622,13 +637,13 @@ var Queue = class {
622
637
  for (let i = 0; i < this.E.length; i++) {
623
638
  rerun = this.E[i].run(type) || rerun;
624
639
  }
625
- if (type === EFFECT_PURE && this.t[type].length)
640
+ if (type === EFFECT_PURE && this.u[type].length)
626
641
  return true;
627
642
  }
628
643
  flush() {
629
- if (this.I)
644
+ if (this.J)
630
645
  return;
631
- this.I = true;
646
+ this.J = true;
632
647
  try {
633
648
  while (this.run(EFFECT_PURE)) {
634
649
  }
@@ -637,7 +652,7 @@ var Queue = class {
637
652
  this.run(EFFECT_RENDER);
638
653
  this.run(EFFECT_USER);
639
654
  } finally {
640
- this.I = false;
655
+ this.J = false;
641
656
  }
642
657
  }
643
658
  addChild(child) {
@@ -657,9 +672,9 @@ function flushSync() {
657
672
  }
658
673
  function createBoundary(fn, queue) {
659
674
  const owner = new Owner();
660
- const parentQueue = owner.g || globalQueue;
661
- parentQueue.addChild(owner.g = queue);
662
- onCleanup(() => parentQueue.removeChild(owner.g));
675
+ const parentQueue = owner.b || globalQueue;
676
+ parentQueue.addChild(owner.b = queue);
677
+ onCleanup(() => parentQueue.removeChild(owner.b));
663
678
  return compute(owner, fn, null);
664
679
  }
665
680
  function runTop(node) {
@@ -682,138 +697,157 @@ function runPureQueue(queue) {
682
697
  }
683
698
  function runEffectQueue(queue) {
684
699
  for (let i = 0; i < queue.length; i++)
685
- queue[i].V();
700
+ queue[i].W();
686
701
  }
687
702
 
688
703
  // src/core/effect.ts
689
704
  var Effect = class extends Computation {
690
- J;
691
- A;
692
- B;
693
- P = false;
694
705
  K;
695
- C;
696
- g;
706
+ L;
707
+ B;
708
+ Q = false;
709
+ M;
710
+ y;
711
+ b;
697
712
  constructor(initialValue, compute2, effect, error, options) {
698
713
  super(initialValue, compute2, options);
699
- this.J = effect;
700
- this.A = error;
701
- this.K = initialValue;
702
- this.C = options?.render ? EFFECT_RENDER : EFFECT_USER;
703
- this.g = getOwner()?.g || globalQueue;
714
+ this.K = effect;
715
+ this.L = error;
716
+ this.M = initialValue;
717
+ this.y = options?.render ? EFFECT_RENDER : EFFECT_USER;
718
+ if (this.y === EFFECT_RENDER) {
719
+ this.t = (p) => latest(() => compute2(p));
720
+ }
721
+ this.b = getOwner()?.b || globalQueue;
704
722
  if (!options?.defer) {
705
723
  this.x();
706
- this.C === EFFECT_USER ? this.g.enqueue(this.C, this) : this.V();
724
+ this.y === EFFECT_USER ? this.b.enqueue(this.y, this) : this.W();
707
725
  }
708
726
  }
709
727
  write(value, flags = 0) {
710
- const currentFlags = this.h;
711
- this.h = flags;
712
- if (this.C === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
713
- this.g.Q?.(this);
728
+ if (this.a == STATE_DIRTY) {
729
+ const currentFlags = this.d;
730
+ this.d = flags;
731
+ if (this.y === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
732
+ this.b.R?.(this);
733
+ }
714
734
  }
715
735
  if (value === UNCHANGED)
716
- return this.e;
717
- this.e = value;
718
- this.P = true;
736
+ return this.c;
737
+ this.c = value;
738
+ this.Q = true;
719
739
  return value;
720
740
  }
721
741
  q(state, skipQueue) {
722
742
  if (this.a >= state || skipQueue)
723
743
  return;
724
744
  if (this.a === STATE_CLEAN)
725
- this.g.enqueue(this.C, this);
745
+ this.b.enqueue(this.y, this);
726
746
  this.a = state;
727
747
  }
728
- O(error) {
748
+ I(error) {
729
749
  this.B?.();
730
- if (this.h & LOADING_BIT) {
731
- this.h = 0;
732
- this.g.Q?.(this);
750
+ if (this.d & LOADING_BIT) {
751
+ this.d = 0;
752
+ this.b.R?.(this);
733
753
  }
734
- if (this.C === EFFECT_USER) {
754
+ if (this.y === EFFECT_USER) {
735
755
  try {
736
- return this.A ? this.B = this.A(error) : console.error(new EffectError(this.J, error));
756
+ return this.L ? this.B = this.L(error) : console.error(new EffectError(this.K, error));
737
757
  } catch (e) {
738
758
  error = e;
739
759
  }
740
760
  }
741
761
  this.handleError(error);
742
762
  }
743
- y() {
763
+ z() {
744
764
  if (this.a === STATE_DISPOSED)
745
765
  return;
746
- this.J = void 0;
747
766
  this.K = void 0;
748
- this.A = void 0;
767
+ this.M = void 0;
768
+ this.L = void 0;
749
769
  this.B?.();
750
770
  this.B = void 0;
751
- super.y();
771
+ super.z();
752
772
  }
753
- V() {
754
- if (this.P && this.a !== STATE_DISPOSED) {
773
+ W() {
774
+ if (this.Q && this.a !== STATE_DISPOSED) {
755
775
  this.B?.();
756
776
  try {
757
- this.B = this.J(this.e, this.K);
777
+ this.B = this.K(this.c, this.M);
758
778
  } catch (e) {
759
779
  this.handleError(e);
760
780
  } finally {
761
- this.K = this.e;
762
- this.P = false;
781
+ this.M = this.c;
782
+ this.Q = false;
763
783
  }
764
784
  }
765
785
  }
766
786
  };
767
787
  var EagerComputation = class extends Computation {
768
- g;
788
+ b;
769
789
  constructor(initialValue, compute2, options) {
770
790
  super(initialValue, compute2, options);
771
- this.g = getOwner()?.g || globalQueue;
791
+ this.b = getOwner()?.b || globalQueue;
772
792
  this.x();
773
793
  }
774
794
  q(state, skipQueue) {
775
795
  if (this.a >= state && !this.H)
776
796
  return;
777
797
  if (this.a === STATE_CLEAN && !skipQueue)
778
- this.g.enqueue(EFFECT_PURE, this);
798
+ this.b.enqueue(EFFECT_PURE, this);
779
799
  super.q(state, skipQueue);
780
800
  }
781
801
  };
802
+ var ProjectionComputation = class extends Computation {
803
+ b;
804
+ constructor(compute2) {
805
+ super(null, compute2);
806
+ this.b = getOwner()?.b || globalQueue;
807
+ }
808
+ q(state, skipQueue) {
809
+ if (this.a >= state && !this.H)
810
+ return;
811
+ if (this.a === STATE_CLEAN && !skipQueue)
812
+ this.b.enqueue(EFFECT_PURE, this);
813
+ super.q(state, true);
814
+ }
815
+ };
782
816
 
783
817
  // src/core/suspense.ts
784
818
  var SuspenseQueue = class extends Queue {
785
- c = /* @__PURE__ */ new Set();
819
+ f = /* @__PURE__ */ new Set();
786
820
  o = false;
787
- R = new Computation(false, null);
821
+ S = new Computation(false, null);
788
822
  run(type) {
789
823
  if (type && this.o)
790
824
  return;
791
825
  return super.run(type);
792
826
  }
793
- Q(node) {
794
- if (node.h & LOADING_BIT) {
795
- this.c.add(node);
827
+ R(node) {
828
+ if (node.d & LOADING_BIT) {
829
+ this.f.add(node);
796
830
  if (!this.o) {
797
831
  this.o = true;
798
- this.R.write(true);
832
+ this.S.write(true);
799
833
  }
800
834
  } else {
801
- this.c.delete(node);
802
- if (this.c.size === 0) {
835
+ this.f.delete(node);
836
+ if (this.f.size === 0) {
803
837
  this.o = false;
804
- this.R.write(false);
838
+ this.S.write(false);
805
839
  }
806
840
  }
807
841
  }
808
842
  };
809
843
  var LiveComputation = class extends EagerComputation {
810
844
  write(value, flags = 0) {
811
- const currentFlags = this.h;
845
+ const currentFlags = this.d;
812
846
  super.write(value, flags);
813
847
  if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
814
- this.g.Q?.(this);
848
+ this.b.R?.(this);
815
849
  }
816
- return this.e;
850
+ return this.c;
817
851
  }
818
852
  };
819
853
  function createSuspense(fn, fallback) {
@@ -822,7 +856,7 @@ function createSuspense(fn, fallback) {
822
856
  const child = new Computation(null, fn);
823
857
  return new LiveComputation(null, () => flatten(child.wait()));
824
858
  }, queue);
825
- const equality = new Computation(null, () => queue.R.read() || queue.o);
859
+ const equality = new Computation(null, () => queue.S.read() || queue.o);
826
860
  const comp = new Computation(null, () => equality.read() ? fallback() : tree.read());
827
861
  return comp.read.bind(comp);
828
862
  }
@@ -853,24 +887,25 @@ function createMemo(compute2, value, options) {
853
887
  return () => {
854
888
  if (node) {
855
889
  resolvedValue = node.wait();
856
- if (!node.d?.length && node.n?.r !== node) {
890
+ if (!node.g?.length && node.n?.r !== node) {
857
891
  node.dispose();
858
892
  node = void 0;
859
- } else if (!node.r && !node.b?.length) {
893
+ } else if (!node.r && !node.e?.length) {
860
894
  node.dispose();
861
- node.a = STATE_UNINITIALIZED;
895
+ node.a = STATE_DIRTY;
862
896
  }
863
897
  }
864
898
  return resolvedValue;
865
899
  };
866
900
  }
867
901
  function createAsync(compute2, value, options) {
902
+ let uninitialized = value === void 0;
868
903
  const lhs = new EagerComputation(
869
904
  {
870
- e: value
905
+ c: value
871
906
  },
872
907
  (p) => {
873
- const value2 = p?.e;
908
+ const value2 = p?.c;
874
909
  const source = compute2(value2);
875
910
  const isPromise = source instanceof Promise;
876
911
  const iterator = source[Symbol.asyncIterator];
@@ -879,26 +914,28 @@ function createAsync(compute2, value, options) {
879
914
  wait() {
880
915
  return source;
881
916
  },
882
- e: source
917
+ c: source
883
918
  };
884
919
  }
885
920
  const signal = new Computation(value2, null, options);
886
921
  const w = signal.wait;
887
922
  signal.wait = function() {
888
- if (signal.h & ERROR_BIT && signal.z <= getClock()) {
923
+ if (signal.d & ERROR_BIT && signal.A <= getClock()) {
889
924
  lhs.q(STATE_DIRTY);
890
925
  throw new NotReadyError();
891
926
  }
892
927
  return w.call(this);
893
928
  };
894
- signal.write(UNCHANGED, LOADING_BIT);
929
+ signal.write(UNCHANGED, LOADING_BIT | (uninitialized ? UNINITIALIZED_BIT : 0));
895
930
  if (isPromise) {
896
931
  source.then(
897
932
  (value3) => {
933
+ uninitialized = false;
898
934
  signal.write(value3, 0, true);
899
935
  },
900
936
  (error) => {
901
- signal.write(error, ERROR_BIT);
937
+ uninitialized = true;
938
+ signal.I(error);
902
939
  }
903
940
  );
904
941
  } else {
@@ -952,14 +989,14 @@ function createErrorBoundary(fn, fallback) {
952
989
  const owner = new Owner();
953
990
  const error = new Computation(null, null);
954
991
  const reset = new Computation(null, null, { equals: false });
955
- const handler = (err) => error.write({ A: err });
992
+ const handler = (err) => error.write({ D: err });
956
993
  owner.m = owner.m ? [handler, ...owner.m] : [handler];
957
994
  const guarded = compute(
958
995
  owner,
959
996
  () => {
960
997
  const c = new Computation(null, () => (reset.read(), fn()));
961
998
  const f = new Computation(null, () => flatten(c.read()));
962
- f.O = function(error2) {
999
+ f.I = function(error2) {
963
1000
  this.handleError(error2);
964
1001
  };
965
1002
  return f;
@@ -972,7 +1009,7 @@ function createErrorBoundary(fn, fallback) {
972
1009
  if (!error.read())
973
1010
  return resolved;
974
1011
  }
975
- return fallback(error.read().A, () => {
1012
+ return fallback(error.read().D, () => {
976
1013
  error.write(null);
977
1014
  reset.write(null);
978
1015
  });
@@ -1000,26 +1037,17 @@ function createReaction(effect, error, options) {
1000
1037
  ...void 0
1001
1038
  });
1002
1039
  return (tracking) => {
1003
- node.w = tracking;
1040
+ node.t = tracking;
1004
1041
  node.a = STATE_DIRTY;
1005
1042
  node.x();
1006
- node.w = null;
1043
+ node.t = null;
1007
1044
  };
1008
1045
  }
1009
1046
 
1010
1047
  // src/store/projection.ts
1011
- var ProjectionComputation = class extends EagerComputation {
1012
- q(state, skipQueue) {
1013
- if (this.a >= state && !this.H)
1014
- return;
1015
- if (this.a === STATE_CLEAN && !skipQueue)
1016
- this.g.enqueue(EFFECT_PURE, this);
1017
- super.q(state, true);
1018
- }
1019
- };
1020
1048
  function createProjection(fn, initialValue = {}) {
1021
1049
  const [store, setStore] = createStore(initialValue);
1022
- const node = new ProjectionComputation(void 0, () => {
1050
+ const node = new ProjectionComputation(() => {
1023
1051
  setStore(fn);
1024
1052
  });
1025
1053
  const wrapped = /* @__PURE__ */ new WeakMap();
@@ -1161,7 +1189,7 @@ var proxyTraps = {
1161
1189
  return desc.get.call(receiver);
1162
1190
  }
1163
1191
  if (Writing.has(storeValue)) {
1164
- const value2 = tracked ? tracked.e : storeValue[property];
1192
+ const value2 = tracked ? tracked.c : storeValue[property];
1165
1193
  return isWrappable(value2) ? (Writing.add(value2[$RAW] || value2), wrap2(value2)) : value2;
1166
1194
  }
1167
1195
  let value = tracked ? nodes[property].read() : storeValue[property];
@@ -1502,19 +1530,19 @@ function mapArray(list, map, options) {
1502
1530
  return updateKeyedMap.bind({
1503
1531
  F: new Owner(),
1504
1532
  i: 0,
1505
- W: list,
1506
- u: [],
1533
+ X: list,
1534
+ w: [],
1507
1535
  G: map,
1536
+ h: [],
1508
1537
  f: [],
1509
- c: [],
1510
- D: keyFn,
1538
+ C: keyFn,
1511
1539
  j: keyFn || options?.keyed === false ? [] : void 0,
1512
1540
  k: map.length > 1 ? [] : void 0,
1513
1541
  o: options?.fallback
1514
1542
  });
1515
1543
  }
1516
1544
  function updateKeyedMap() {
1517
- const newItems = this.W() || [], newLen = newItems.length;
1545
+ const newItems = this.X() || [], newLen = newItems.length;
1518
1546
  newItems[$TRACK];
1519
1547
  runWithOwner(this.F, () => {
1520
1548
  let i, j, mapper = this.j ? () => {
@@ -1535,38 +1563,38 @@ function updateKeyedMap() {
1535
1563
  if (newLen === 0) {
1536
1564
  if (this.i !== 0) {
1537
1565
  this.F.dispose(false);
1538
- this.c = [];
1539
- this.u = [];
1540
1566
  this.f = [];
1567
+ this.w = [];
1568
+ this.h = [];
1541
1569
  this.i = 0;
1542
1570
  this.j && (this.j = []);
1543
1571
  this.k && (this.k = []);
1544
1572
  }
1545
- if (this.o && !this.f[0]) {
1546
- this.f[0] = compute(
1547
- this.c[0] = new Owner(),
1573
+ if (this.o && !this.h[0]) {
1574
+ this.h[0] = compute(
1575
+ this.f[0] = new Owner(),
1548
1576
  this.o,
1549
1577
  null
1550
1578
  );
1551
1579
  }
1552
1580
  } else if (this.i === 0) {
1553
- if (this.c[0])
1554
- this.c[0].dispose();
1555
- this.f = new Array(newLen);
1581
+ if (this.f[0])
1582
+ this.f[0].dispose();
1583
+ this.h = new Array(newLen);
1556
1584
  for (j = 0; j < newLen; j++) {
1557
- this.u[j] = newItems[j];
1558
- this.f[j] = compute(this.c[j] = new Owner(), mapper, null);
1585
+ this.w[j] = newItems[j];
1586
+ this.h[j] = compute(this.f[j] = new Owner(), mapper, null);
1559
1587
  }
1560
1588
  this.i = newLen;
1561
1589
  } else {
1562
1590
  let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.j ? new Array(newLen) : void 0, tempIndexes = this.k ? new Array(newLen) : void 0;
1563
- for (start = 0, end = Math.min(this.i, newLen); start < end && (this.u[start] === newItems[start] || this.j && compare(this.D, this.u[start], newItems[start])); start++) {
1591
+ for (start = 0, end = Math.min(this.i, newLen); start < end && (this.w[start] === newItems[start] || this.j && compare(this.C, this.w[start], newItems[start])); start++) {
1564
1592
  if (this.j)
1565
1593
  this.j[start].write(newItems[start]);
1566
1594
  }
1567
- for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.u[end] === newItems[newEnd] || this.j && compare(this.D, this.u[end], newItems[newEnd])); end--, newEnd--) {
1568
- temp[newEnd] = this.f[end];
1569
- tempNodes[newEnd] = this.c[end];
1595
+ for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.w[end] === newItems[newEnd] || this.j && compare(this.C, this.w[end], newItems[newEnd])); end--, newEnd--) {
1596
+ temp[newEnd] = this.h[end];
1597
+ tempNodes[newEnd] = this.f[end];
1570
1598
  tempRows && (tempRows[newEnd] = this.j[end]);
1571
1599
  tempIndexes && (tempIndexes[newEnd] = this.k[end]);
1572
1600
  }
@@ -1574,29 +1602,29 @@ function updateKeyedMap() {
1574
1602
  newIndicesNext = new Array(newEnd + 1);
1575
1603
  for (j = newEnd; j >= start; j--) {
1576
1604
  item = newItems[j];
1577
- key = this.D ? this.D(item) : item;
1605
+ key = this.C ? this.C(item) : item;
1578
1606
  i = newIndices.get(key);
1579
1607
  newIndicesNext[j] = i === void 0 ? -1 : i;
1580
1608
  newIndices.set(key, j);
1581
1609
  }
1582
1610
  for (i = start; i <= end; i++) {
1583
- item = this.u[i];
1584
- key = this.D ? this.D(item) : item;
1611
+ item = this.w[i];
1612
+ key = this.C ? this.C(item) : item;
1585
1613
  j = newIndices.get(key);
1586
1614
  if (j !== void 0 && j !== -1) {
1587
- temp[j] = this.f[i];
1588
- tempNodes[j] = this.c[i];
1615
+ temp[j] = this.h[i];
1616
+ tempNodes[j] = this.f[i];
1589
1617
  tempRows && (tempRows[j] = this.j[i]);
1590
1618
  tempIndexes && (tempIndexes[j] = this.k[i]);
1591
1619
  j = newIndicesNext[j];
1592
1620
  newIndices.set(key, j);
1593
1621
  } else
1594
- this.c[i].dispose();
1622
+ this.f[i].dispose();
1595
1623
  }
1596
1624
  for (j = start; j < newLen; j++) {
1597
1625
  if (j in temp) {
1598
- this.f[j] = temp[j];
1599
- this.c[j] = tempNodes[j];
1626
+ this.h[j] = temp[j];
1627
+ this.f[j] = tempNodes[j];
1600
1628
  if (tempRows) {
1601
1629
  this.j[j] = tempRows[j];
1602
1630
  this.j[j].write(newItems[j]);
@@ -1606,63 +1634,63 @@ function updateKeyedMap() {
1606
1634
  this.k[j].write(j);
1607
1635
  }
1608
1636
  } else {
1609
- this.f[j] = compute(this.c[j] = new Owner(), mapper, null);
1637
+ this.h[j] = compute(this.f[j] = new Owner(), mapper, null);
1610
1638
  }
1611
1639
  }
1612
- this.f = this.f.slice(0, this.i = newLen);
1613
- this.u = newItems.slice(0);
1640
+ this.h = this.h.slice(0, this.i = newLen);
1641
+ this.w = newItems.slice(0);
1614
1642
  }
1615
1643
  });
1616
- return this.f;
1644
+ return this.h;
1617
1645
  }
1618
1646
  function repeat(count, map, options) {
1619
1647
  return updateRepeat.bind({
1620
1648
  F: new Owner(),
1621
1649
  i: 0,
1622
- X: count,
1650
+ Y: count,
1623
1651
  G: map,
1624
- c: [],
1625
1652
  f: [],
1653
+ h: [],
1626
1654
  o: options?.fallback
1627
1655
  });
1628
1656
  }
1629
1657
  function updateRepeat() {
1630
- const newLen = this.X();
1658
+ const newLen = this.Y();
1631
1659
  runWithOwner(this.F, () => {
1632
1660
  if (newLen === 0) {
1633
1661
  if (this.i !== 0) {
1634
1662
  this.F.dispose(false);
1635
- this.c = [];
1636
1663
  this.f = [];
1664
+ this.h = [];
1637
1665
  this.i = 0;
1638
1666
  }
1639
- if (this.o && !this.f[0]) {
1640
- this.f[0] = compute(
1641
- this.c[0] = new Owner(),
1667
+ if (this.o && !this.h[0]) {
1668
+ this.h[0] = compute(
1669
+ this.f[0] = new Owner(),
1642
1670
  this.o,
1643
1671
  null
1644
1672
  );
1645
1673
  }
1646
1674
  } else {
1647
- if (this.i === 0 && this.c[0])
1648
- this.c[0].dispose();
1675
+ if (this.i === 0 && this.f[0])
1676
+ this.f[0].dispose();
1649
1677
  for (let i = this.i; i < newLen; i++) {
1650
- this.f[i] = compute(
1651
- this.c[i] = new Owner(),
1678
+ this.h[i] = compute(
1679
+ this.f[i] = new Owner(),
1652
1680
  () => this.G(i),
1653
1681
  null
1654
1682
  );
1655
1683
  }
1656
1684
  for (let i = newLen; i < this.i; i++)
1657
- this.c[i].dispose();
1658
- this.f = this.f.slice(0, newLen);
1685
+ this.f[i].dispose();
1686
+ this.h = this.h.slice(0, newLen);
1659
1687
  this.i = newLen;
1660
1688
  }
1661
1689
  });
1662
- return this.f;
1690
+ return this.h;
1663
1691
  }
1664
1692
  function compare(key, a, b) {
1665
1693
  return key ? key(a) === key(b) : true;
1666
1694
  }
1667
1695
 
1668
- export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createProjection, createReaction, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, resolveSync, runWithOwner, setContext, untrack, unwrap };
1696
+ export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createProjection, createReaction, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isStale, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, runWithOwner, setContext, untrack, unwrap };