@solidjs/signals 2.0.0-beta.11 → 2.0.0-beta.12

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
@@ -3376,8 +3376,9 @@ function mapArray(e, t, n) {
3376
3376
  et: [],
3377
3377
  tt: i,
3378
3378
  nt: i || n?.keyed === false ? [] : undefined,
3379
- it: r ? [] : undefined,
3380
- rt: n?.fallback
3379
+ it: r && n?.keyed !== false ? [] : undefined,
3380
+ rt: n?.keyed === false,
3381
+ st: n?.fallback
3381
3382
  };
3382
3383
  const u = computed(updateKeyedMap.bind(o));
3383
3384
  o.Ze.u = u;
@@ -3393,20 +3394,25 @@ function updateKeyedMap() {
3393
3394
  let n,
3394
3395
  i,
3395
3396
  r = this.nt
3396
- ? () => {
3397
- this.nt[i] = signal(e[i], pureOptions);
3398
- this.it && (this.it[i] = signal(i, pureOptions));
3399
- return this.Xe(accessor(this.nt[i]), this.it ? accessor(this.it[i]) : undefined);
3400
- }
3397
+ ? this.rt
3398
+ ? () => {
3399
+ this.nt[i] = signal(e[i], pureOptions);
3400
+ return this.Xe(accessor(this.nt[i]), i);
3401
+ }
3402
+ : () => {
3403
+ this.nt[i] = signal(e[i], pureOptions);
3404
+ this.it && (this.it[i] = signal(i, pureOptions));
3405
+ return this.Xe(accessor(this.nt[i]), this.it ? accessor(this.it[i]) : undefined);
3406
+ }
3401
3407
  : this.it
3402
3408
  ? () => {
3403
3409
  const t = e[i];
3404
3410
  this.it[i] = signal(i, pureOptions);
3405
- return this.Xe(() => t, accessor(this.it[i]));
3411
+ return this.Xe(t, accessor(this.it[i]));
3406
3412
  }
3407
3413
  : () => {
3408
3414
  const t = e[i];
3409
- return this.Xe(() => t);
3415
+ return this.Xe(t);
3410
3416
  };
3411
3417
  if (t === 0) {
3412
3418
  if (this.qe !== 0) {
@@ -3418,8 +3424,8 @@ function updateKeyedMap() {
3418
3424
  this.nt && (this.nt = []);
3419
3425
  this.it && (this.it = []);
3420
3426
  }
3421
- if (this.rt && !this.Je[0]) {
3422
- this.Je[0] = runWithOwner((this.et[0] = createOwner()), this.rt);
3427
+ if (this.st && !this.Je[0]) {
3428
+ this.Je[0] = runWithOwner((this.et[0] = createOwner()), this.st);
3423
3429
  }
3424
3430
  } else if (this.qe === 0) {
3425
3431
  if (this.et[0]) this.et[0].dispose();
@@ -3510,21 +3516,21 @@ function repeat(e, t, n) {
3510
3516
  updateRepeat.bind({
3511
3517
  Ze: createOwner(),
3512
3518
  qe: 0,
3513
- st: 0,
3514
- ot: e,
3519
+ ot: 0,
3520
+ ut: e,
3515
3521
  Xe: i,
3516
3522
  et: [],
3517
3523
  Je: [],
3518
- ut: n?.from,
3519
- rt: n?.fallback
3524
+ lt: n?.from,
3525
+ st: n?.fallback
3520
3526
  })
3521
3527
  );
3522
3528
  r._e &= ~CONFIG_AUTO_DISPOSE;
3523
3529
  return accessor(r);
3524
3530
  }
3525
3531
  function updateRepeat() {
3526
- const e = this.ot();
3527
- const t = this.ut?.() || 0;
3532
+ const e = this.ut();
3533
+ const t = this.lt?.() || 0;
3528
3534
  runWithOwner(this.Ze, () => {
3529
3535
  if (e === 0) {
3530
3536
  if (this.qe !== 0) {
@@ -3533,23 +3539,23 @@ function updateRepeat() {
3533
3539
  this.Je = [];
3534
3540
  this.qe = 0;
3535
3541
  }
3536
- if (this.rt && !this.Je[0]) {
3537
- this.Je[0] = runWithOwner((this.et[0] = createOwner()), this.rt);
3542
+ if (this.st && !this.Je[0]) {
3543
+ this.Je[0] = runWithOwner((this.et[0] = createOwner()), this.st);
3538
3544
  }
3539
3545
  return;
3540
3546
  }
3541
3547
  const n = t + e;
3542
- const i = this.st + this.qe;
3548
+ const i = this.ot + this.qe;
3543
3549
  if (this.qe === 0 && this.et[0]) this.et[0].dispose();
3544
- for (let e = n; e < i; e++) this.et[e - this.st].dispose();
3545
- if (this.st < t) {
3546
- let e = this.st;
3550
+ for (let e = n; e < i; e++) this.et[e - this.ot].dispose();
3551
+ if (this.ot < t) {
3552
+ let e = this.ot;
3547
3553
  while (e < t && e < this.qe) this.et[e++].dispose();
3548
- this.et.splice(0, t - this.st);
3549
- this.Je.splice(0, t - this.st);
3550
- } else if (this.st > t) {
3551
- let n = i - this.st - 1;
3552
- let r = this.st - t;
3554
+ this.et.splice(0, t - this.ot);
3555
+ this.Je.splice(0, t - this.ot);
3556
+ } else if (this.ot > t) {
3557
+ let n = i - this.ot - 1;
3558
+ let r = this.ot - t;
3553
3559
  this.et.length = this.Je.length = e;
3554
3560
  while (n >= r) {
3555
3561
  this.et[n] = this.et[n - r];
@@ -3564,7 +3570,7 @@ function updateRepeat() {
3564
3570
  this.Je[e - t] = runWithOwner((this.et[e - t] = createOwner()), () => this.Xe(e));
3565
3571
  }
3566
3572
  this.Je = this.Je.slice(0, e);
3567
- this.st = t;
3573
+ this.ot = t;
3568
3574
  this.qe = e;
3569
3575
  });
3570
3576
  return this.Je;
@@ -3577,10 +3583,10 @@ function boundaryComputed(e, t) {
3577
3583
  n.xe = (e, t) => {
3578
3584
  const i = e !== undefined ? e : n.he;
3579
3585
  const r = t !== undefined ? t : n.Re;
3580
- n.he &= ~n.lt;
3581
- n.te.notify(n, n.lt, i, r);
3586
+ n.he &= ~n.ct;
3587
+ n.te.notify(n, n.ct, i, r);
3582
3588
  };
3583
- n.lt = t;
3589
+ n.ct = t;
3584
3590
  n._e &= ~CONFIG_AUTO_DISPOSE;
3585
3591
  recompute(n, true);
3586
3592
  return n;
@@ -3603,52 +3609,52 @@ function isRevealController(e) {
3603
3609
  return e instanceof RevealController;
3604
3610
  }
3605
3611
  function isSlotReady(e) {
3606
- return isRevealController(e) ? e.isReady() : e.ct.size === 0 && !e.ft;
3612
+ return isRevealController(e) ? e.isReady() : e.ft.size === 0 && !e.Et;
3607
3613
  }
3608
3614
  function isSlotMinimallyReady(e) {
3609
3615
  return isRevealController(e) ? e.isMinimallyReady() : isSlotReady(e);
3610
3616
  }
3611
3617
  function setSlotState(e, t, n, i) {
3612
- setSignal(e.Et, n);
3613
- setSignal(e.St, i);
3618
+ setSignal(e.St, n);
3619
+ setSignal(e.Tt, i);
3614
3620
  if (isRevealController(e)) {
3615
- if (!n && e.Tt === t) e.Tt = undefined;
3621
+ if (!n && e.dt === t) e.dt = undefined;
3616
3622
  return e.evaluate(n, i);
3617
3623
  }
3618
- if (!n && e.dt === t && e.Ot) e.dt = undefined;
3624
+ if (!n && e.Ot === t && e._t) e.Ot = undefined;
3619
3625
  }
3620
3626
  class RevealController {
3621
- _t;
3622
3627
  Rt;
3623
- It = [];
3624
- Tt;
3625
- Et = signal(false, { ownedWrite: true, Ye: true });
3628
+ It;
3629
+ ht = [];
3630
+ dt;
3626
3631
  St = signal(false, { ownedWrite: true, Ye: true });
3627
- ht = true;
3632
+ Tt = signal(false, { ownedWrite: true, Ye: true });
3628
3633
  Nt = true;
3629
- At = false;
3634
+ At = true;
3635
+ Ct = false;
3630
3636
  constructor(e, t) {
3631
- this._t = e;
3632
- this.Rt = t;
3637
+ this.Rt = e;
3638
+ this.It = t;
3633
3639
  }
3634
- Ct(e) {
3635
- for (let t = 0; t < this.It.length; t++) {
3636
- const n = this.It[t];
3637
- if ((isRevealController(n) ? n.Tt : n.dt) !== this) continue;
3640
+ Pt(e) {
3641
+ for (let t = 0; t < this.ht.length; t++) {
3642
+ const n = this.ht[t];
3643
+ if ((isRevealController(n) ? n.dt : n.Ot) !== this) continue;
3638
3644
  if (e(n) === false) return false;
3639
3645
  }
3640
3646
  return true;
3641
3647
  }
3642
3648
  isReady() {
3643
- return this.Ct(isSlotReady);
3649
+ return this.Pt(isSlotReady);
3644
3650
  }
3645
3651
  isMinimallyReady() {
3646
- const e = untrack(this._t);
3652
+ const e = untrack(this.Rt);
3647
3653
  if (e === "together") return this.isReady();
3648
3654
  if (e === "natural") {
3649
3655
  let e = false;
3650
3656
  let t = false;
3651
- this.Ct(n => {
3657
+ this.Pt(n => {
3652
3658
  e = true;
3653
3659
  if (isSlotMinimallyReady(n)) {
3654
3660
  t = true;
@@ -3658,58 +3664,58 @@ class RevealController {
3658
3664
  return !e || t;
3659
3665
  }
3660
3666
  let t = true;
3661
- this.Ct(e => {
3667
+ this.Pt(e => {
3662
3668
  t = isSlotMinimallyReady(e);
3663
3669
  return false;
3664
3670
  });
3665
3671
  return t;
3666
3672
  }
3667
3673
  register(e) {
3668
- if (this.It.includes(e)) return;
3669
- this.It.push(e);
3670
- const t = untrack(this._t);
3671
- (setSignal(e.Et, true), setSignal(e.St, t === "sequential" ? !!untrack(this.Rt) : false));
3674
+ if (this.ht.includes(e)) return;
3675
+ this.ht.push(e);
3676
+ const t = untrack(this.Rt);
3677
+ (setSignal(e.St, true), setSignal(e.Tt, t === "sequential" ? !!untrack(this.It) : false));
3672
3678
  untrack(() => this.evaluate());
3673
3679
  }
3674
3680
  unregister(e) {
3675
- const t = this.It.indexOf(e);
3676
- if (t >= 0) this.It.splice(t, 1);
3681
+ const t = this.ht.indexOf(e);
3682
+ if (t >= 0) this.ht.splice(t, 1);
3677
3683
  untrack(() => this.evaluate());
3678
3684
  }
3679
3685
  evaluate(e, t) {
3680
- if (this.At) return;
3681
- this.At = true;
3682
- const n = this.ht;
3683
- const i = this.Nt;
3686
+ if (this.Ct) return;
3687
+ this.Ct = true;
3688
+ const n = this.Nt;
3689
+ const i = this.At;
3684
3690
  try {
3685
- const n = e ?? read(this.Et),
3686
- i = untrack(this._t),
3687
- r = i === "sequential" && !!untrack(this.Rt),
3691
+ const n = e ?? read(this.St),
3692
+ i = untrack(this.Rt),
3693
+ r = i === "sequential" && !!untrack(this.It),
3688
3694
  s = t ?? r;
3689
3695
  if (n) {
3690
- this.Ct(e => setSlotState(e, this, true, s));
3696
+ this.Pt(e => setSlotState(e, this, true, s));
3691
3697
  } else if (i === "natural") {
3692
- this.Ct(e => {
3698
+ this.Pt(e => {
3693
3699
  if (isRevealController(e)) {
3700
+ setSignal(e.Tt, false);
3694
3701
  setSignal(e.St, false);
3695
- setSignal(e.Et, false);
3696
3702
  e.evaluate(false, false);
3697
3703
  } else {
3698
3704
  setSlotState(e, this, !isSlotReady(e), false);
3699
3705
  }
3700
3706
  });
3701
3707
  } else if (i === "together") {
3702
- const e = this.Ct(isSlotMinimallyReady);
3703
- this.Ct(t => setSlotState(t, this, !e, false));
3708
+ const e = this.Pt(isSlotMinimallyReady);
3709
+ this.Pt(t => setSlotState(t, this, !e, false));
3704
3710
  } else {
3705
3711
  let e = false;
3706
- this.Ct(t => {
3712
+ this.Pt(t => {
3707
3713
  if (e) return setSlotState(t, this, true, r);
3708
3714
  if (isSlotReady(t)) return setSlotState(t, this, false, false);
3709
3715
  e = true;
3710
3716
  if (isRevealController(t)) {
3717
+ setSignal(t.Tt, false);
3711
3718
  setSignal(t.St, false);
3712
- setSignal(t.Et, false);
3713
3719
  t.evaluate(false, false);
3714
3720
  } else {
3715
3721
  setSlotState(t, this, true, false);
@@ -3717,96 +3723,96 @@ class RevealController {
3717
3723
  });
3718
3724
  }
3719
3725
  } finally {
3720
- this.ht = this.isReady();
3721
- this.Nt = this.isMinimallyReady();
3722
- this.At = false;
3726
+ this.Nt = this.isReady();
3727
+ this.At = this.isMinimallyReady();
3728
+ this.Ct = false;
3723
3729
  }
3724
- if (this.Tt && (n !== this.ht || i !== this.Nt)) this.Tt.evaluate();
3730
+ if (this.dt && (n !== this.Nt || i !== this.At)) this.dt.evaluate();
3725
3731
  }
3726
3732
  }
3727
3733
  class CollectionQueue extends Queue {
3728
- Pt;
3729
- ct = new Set();
3730
3734
  gt;
3731
- ft = true;
3732
- Et = signal(false, { ownedWrite: true, Ye: true });
3733
- St = signal(false, { ownedWrite: true, Ye: true });
3734
- dt;
3735
- Ot = false;
3735
+ ft = new Set();
3736
3736
  Dt;
3737
- yt = ON_INIT;
3737
+ Et = true;
3738
+ St = signal(false, { ownedWrite: true, Ye: true });
3739
+ Tt = signal(false, { ownedWrite: true, Ye: true });
3740
+ Ot;
3741
+ _t = false;
3742
+ yt;
3743
+ vt = ON_INIT;
3738
3744
  constructor(e) {
3739
3745
  super();
3740
- this.Pt = e;
3746
+ this.gt = e;
3741
3747
  }
3742
3748
  run(e) {
3743
- if (!e || (read(this.Et) && (!_revealUsed || read(this.St)))) return;
3749
+ if (!e || (read(this.St) && (!_revealUsed || read(this.Tt)))) return;
3744
3750
  return super.run(e);
3745
3751
  }
3746
3752
  notify(e, t, n, i) {
3747
- if (!(t & this.Pt)) return super.notify(e, t, n, i);
3748
- if (this.Ot && this.Dt) {
3753
+ if (!(t & this.gt)) return super.notify(e, t, n, i);
3754
+ if (this._t && this.yt) {
3749
3755
  const e = untrack(() => {
3750
3756
  try {
3751
- return this.Dt();
3757
+ return this.yt();
3752
3758
  } catch {
3753
3759
  return ON_INIT;
3754
3760
  }
3755
3761
  });
3756
- if (e !== this.yt) {
3757
- this.yt = e;
3758
- this.Ot = false;
3759
- this.ct.clear();
3762
+ if (e !== this.vt) {
3763
+ this.vt = e;
3764
+ this._t = false;
3765
+ this.ft.clear();
3760
3766
  }
3761
3767
  }
3762
- if (this.Pt & STATUS_PENDING && this.Ot) return super.notify(e, t, n, i);
3763
- if (this.Pt & STATUS_PENDING && n & STATUS_ERROR) {
3768
+ if (this.gt & STATUS_PENDING && this._t) return super.notify(e, t, n, i);
3769
+ if (this.gt & STATUS_PENDING && n & STATUS_ERROR) {
3764
3770
  return super.notify(e, STATUS_ERROR, n, i);
3765
3771
  }
3766
- if (n & this.Pt) {
3767
- this.ft = true;
3772
+ if (n & this.gt) {
3773
+ this.Et = true;
3768
3774
  const t = i?.source || e.Re?.source;
3769
3775
  if (t) {
3770
- const e = this.ct.size === 0;
3771
- this.ct.add(t);
3772
- if (e) setSignal(this.Et, true);
3776
+ const e = this.ft.size === 0;
3777
+ this.ft.add(t);
3778
+ if (e) setSignal(this.St, true);
3773
3779
  }
3774
3780
  }
3775
- t &= ~this.Pt;
3781
+ t &= ~this.gt;
3776
3782
  return t ? super.notify(e, t, n, i) : true;
3777
3783
  }
3778
3784
  checkSources() {
3779
- for (const e of this.ct) {
3785
+ for (const e of this.ft) {
3780
3786
  if (
3781
3787
  e._ & REACTIVE_DISPOSED ||
3782
- (!(e.he & this.Pt) && !(this.Pt & STATUS_ERROR && e.he & STATUS_PENDING))
3788
+ (!(e.he & this.gt) && !(this.gt & STATUS_ERROR && e.he & STATUS_PENDING))
3783
3789
  )
3784
- this.ct.delete(e);
3790
+ this.ft.delete(e);
3785
3791
  }
3786
- if (!this.ct.size) {
3787
- if (this.Pt & STATUS_PENDING && this.ft && !this.Ot && this.gt) {
3788
- this.ft = !!(this.gt.he & this.Pt);
3792
+ if (!this.ft.size) {
3793
+ if (this.gt & STATUS_PENDING && this.Et && !this._t && this.Dt) {
3794
+ this.Et = !!(this.Dt.he & this.gt);
3789
3795
  } else {
3790
- this.ft = false;
3796
+ this.Et = false;
3791
3797
  }
3792
- if (!this.ft) {
3793
- setSignal(this.Et, false);
3794
- if (this.Dt) {
3798
+ if (!this.Et) {
3799
+ setSignal(this.St, false);
3800
+ if (this.yt) {
3795
3801
  try {
3796
- this.yt = untrack(() => this.Dt());
3802
+ this.vt = untrack(() => this.yt());
3797
3803
  } catch {}
3798
3804
  }
3799
3805
  }
3800
3806
  }
3801
- if (_revealUsed) this.dt?.evaluate();
3807
+ if (_revealUsed) this.Ot?.evaluate();
3802
3808
  }
3803
3809
  }
3804
3810
  function createCollectionBoundary(e, t, n, i) {
3805
3811
  const r = createOwner();
3806
3812
  if (_revealUsed) setContext(RevealControllerContext, null, r);
3807
3813
  const s = new CollectionQueue(e);
3808
- if (i) s.Dt = i;
3809
- const o = (s.gt = createBoundChildren(r, t, s, e));
3814
+ if (i) s.yt = i;
3815
+ const o = (s.Dt = createBoundChildren(r, t, s, e));
3810
3816
  untrack(() => {
3811
3817
  let t = false;
3812
3818
  try {
@@ -3815,21 +3821,21 @@ function createCollectionBoundary(e, t, n, i) {
3815
3821
  if (e instanceof NotReadyError) t = true;
3816
3822
  else throw e;
3817
3823
  }
3818
- s.ft = t || !!(o.he & e) || o.Re instanceof NotReadyError;
3824
+ s.Et = t || !!(o.he & e) || o.Re instanceof NotReadyError;
3819
3825
  });
3820
3826
  const u = _revealUsed && e === STATUS_PENDING ? getContext(RevealControllerContext) : null;
3821
3827
  if (u) {
3822
- s.dt = u;
3828
+ s.Ot = u;
3823
3829
  u.register(s);
3824
3830
  cleanup(() => u.unregister(s));
3825
3831
  }
3826
3832
  return accessor(
3827
3833
  computed(() => {
3828
- if (!read(s.Et)) {
3834
+ if (!read(s.St)) {
3829
3835
  const e = read(o);
3830
- if (!untrack(() => read(s.Et))) return ((s.Ot = true), e);
3836
+ if (!untrack(() => read(s.St))) return ((s._t = true), e);
3831
3837
  }
3832
- if (_revealUsed && read(s.St)) return undefined;
3838
+ if (_revealUsed && read(s.Tt)) return undefined;
3833
3839
  return n(s);
3834
3840
  })
3835
3841
  );
@@ -3839,10 +3845,10 @@ function createLoadingBoundary(e, t, n) {
3839
3845
  }
3840
3846
  function createErrorBoundary(e, t) {
3841
3847
  return createCollectionBoundary(STATUS_ERROR, e, e => {
3842
- let n = e.ct.values().next().value;
3848
+ let n = e.ft.values().next().value;
3843
3849
  const i = n.Re?.cause ?? n.Re;
3844
3850
  return t(i, () => {
3845
- for (const t of e.ct) recompute(t);
3851
+ for (const t of e.ft) recompute(t);
3846
3852
  schedule();
3847
3853
  });
3848
3854
  });
@@ -3863,7 +3869,7 @@ function createRevealOrder(e, t) {
3863
3869
  o.evaluate();
3864
3870
  });
3865
3871
  if (i) {
3866
- o.Tt = i;
3872
+ o.dt = i;
3867
3873
  i.register(o);
3868
3874
  cleanup(() => i.unregister(o));
3869
3875
  }
@@ -2,8 +2,14 @@ import { type Accessor } from "./signals.js";
2
2
  export type Maybe<T> = T | void | null | undefined | false;
3
3
  /**
4
4
  * Reactively maps an array, reusing the previously-mapped value for unchanged
5
- * items. The callback receives `(value, index)` as accessors so individual
6
- * items and indexes can be subscribed to without re-running the mapper.
5
+ * items.
6
+ *
7
+ * The callback shape follows the keying mode:
8
+ * - default / `keyed: true` receives `(item, index)` where `item` is the raw
9
+ * row value and `index` is an accessor.
10
+ * - `keyed: false` receives `(item, index)` where `item` is an accessor and
11
+ * `index` is a stable number.
12
+ * - `keyed: item => key` receives accessors for both arguments.
7
13
  *
8
14
  * This is the underlying helper that powers `<For>`. App code should use
9
15
  * `<For>` directly; reach for `mapArray` when implementing custom list
@@ -19,15 +25,25 @@ export type Maybe<T> = T | void | null | undefined | false;
19
25
  * ```ts
20
26
  * const view = mapArray(
21
27
  * items,
22
- * (item, index) => `${index()}: ${item().label}`,
28
+ * (item, index) => `${index()}: ${item.label}`,
23
29
  * { fallback: () => "no items" }
24
30
  * );
25
31
  * ```
26
32
  *
27
33
  * @description https://docs.solidjs.com/reference/reactive-utilities/map-array
28
34
  */
29
- export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: Accessor<number>) => MappedItem, options?: {
30
- keyed?: boolean | ((item: Item) => any);
35
+ export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Item, index: Accessor<number>) => MappedItem, options?: {
36
+ keyed?: true;
37
+ fallback?: Accessor<any>;
38
+ name?: string;
39
+ }): Accessor<MappedItem[]>;
40
+ export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: number) => MappedItem, options: {
41
+ keyed: false;
42
+ fallback?: Accessor<any>;
43
+ name?: string;
44
+ }): Accessor<MappedItem[]>;
45
+ export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: Accessor<number>) => MappedItem, options: {
46
+ keyed: (item: Item) => any;
31
47
  fallback?: Accessor<any>;
32
48
  name?: string;
33
49
  }): Accessor<MappedItem[]>;
@@ -2,8 +2,14 @@ import { type Accessor } from "./signals.cjs";
2
2
  export type Maybe<T> = T | void | null | undefined | false;
3
3
  /**
4
4
  * Reactively maps an array, reusing the previously-mapped value for unchanged
5
- * items. The callback receives `(value, index)` as accessors so individual
6
- * items and indexes can be subscribed to without re-running the mapper.
5
+ * items.
6
+ *
7
+ * The callback shape follows the keying mode:
8
+ * - default / `keyed: true` receives `(item, index)` where `item` is the raw
9
+ * row value and `index` is an accessor.
10
+ * - `keyed: false` receives `(item, index)` where `item` is an accessor and
11
+ * `index` is a stable number.
12
+ * - `keyed: item => key` receives accessors for both arguments.
7
13
  *
8
14
  * This is the underlying helper that powers `<For>`. App code should use
9
15
  * `<For>` directly; reach for `mapArray` when implementing custom list
@@ -19,15 +25,25 @@ export type Maybe<T> = T | void | null | undefined | false;
19
25
  * ```ts
20
26
  * const view = mapArray(
21
27
  * items,
22
- * (item, index) => `${index()}: ${item().label}`,
28
+ * (item, index) => `${index()}: ${item.label}`,
23
29
  * { fallback: () => "no items" }
24
30
  * );
25
31
  * ```
26
32
  *
27
33
  * @description https://docs.solidjs.com/reference/reactive-utilities/map-array
28
34
  */
29
- export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: Accessor<number>) => MappedItem, options?: {
30
- keyed?: boolean | ((item: Item) => any);
35
+ export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Item, index: Accessor<number>) => MappedItem, options?: {
36
+ keyed?: true;
37
+ fallback?: Accessor<any>;
38
+ name?: string;
39
+ }): Accessor<MappedItem[]>;
40
+ export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: number) => MappedItem, options: {
41
+ keyed: false;
42
+ fallback?: Accessor<any>;
43
+ name?: string;
44
+ }): Accessor<MappedItem[]>;
45
+ export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: Accessor<number>) => MappedItem, options: {
46
+ keyed: (item: Item) => any;
31
47
  fallback?: Accessor<any>;
32
48
  name?: string;
33
49
  }): Accessor<MappedItem[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidjs/signals",
3
- "version": "2.0.0-beta.11",
3
+ "version": "2.0.0-beta.12",
4
4
  "description": "Solid's reactive primitives: signals, memos, effects, stores, and async-aware computations.",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",