@solidjs/signals 0.10.6 → 0.10.8

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/dev.js CHANGED
@@ -1287,7 +1287,7 @@ function signal(v, options, firewall = null) {
1287
1287
  };
1288
1288
  s._name = options?.name ?? "signal";
1289
1289
  firewall && (firewall._child = s);
1290
- if (snapshotCaptureActive) {
1290
+ if (snapshotCaptureActive && !s._pureWrite) {
1291
1291
  s._snapshotValue = v === undefined ? NO_SNAPSHOT : v;
1292
1292
  snapshotSources.add(s);
1293
1293
  }
@@ -1306,9 +1306,25 @@ function optimisticComputed(fn, initialValue, options) {
1306
1306
  function isEqual(a, b) {
1307
1307
  return a === b;
1308
1308
  }
1309
+ let strictRead = false;
1310
+ function setStrictRead(v) {
1311
+ const prev = strictRead;
1312
+ strictRead = v;
1313
+ return prev;
1314
+ }
1309
1315
  function untrack(fn) {
1310
- if (!tracking) return fn();
1316
+ if (!tracking && !strictRead) return fn();
1311
1317
  tracking = false;
1318
+ if (strictRead) {
1319
+ const prev = strictRead;
1320
+ strictRead = false;
1321
+ try {
1322
+ return fn();
1323
+ } finally {
1324
+ tracking = true;
1325
+ strictRead = prev;
1326
+ }
1327
+ }
1312
1328
  try {
1313
1329
  return fn();
1314
1330
  } finally {
@@ -1406,6 +1422,10 @@ function read(el) {
1406
1422
  return snapshot;
1407
1423
  }
1408
1424
  }
1425
+ if (strictRead && !tracking)
1426
+ console.warn(
1427
+ `Untracked reactive read in ${strictRead}. This value won't update — use untrack() if intentional.`
1428
+ );
1409
1429
  return !c ||
1410
1430
  currentOptimisticLane !== null ||
1411
1431
  el._pendingValue === NOT_PENDING ||
@@ -2121,6 +2141,10 @@ const storeTraps = {
2121
2141
  );
2122
2142
  }
2123
2143
  }
2144
+ if (strictRead && !tracking && typeof property === "string")
2145
+ console.warn(
2146
+ `Untracked reactive read in ${strictRead}. This value won't update — use untrack() if intentional.`
2147
+ );
2124
2148
  return isWrappable(value) ? wrap(value, target) : value;
2125
2149
  },
2126
2150
  has(target, property) {
@@ -2624,18 +2648,29 @@ function omit(props, ...keys) {
2624
2648
  }
2625
2649
  function mapArray(list, map, options) {
2626
2650
  const keyFn = typeof options?.keyed === "function" ? options.keyed : undefined;
2651
+ const indexes = map.length > 1;
2652
+ const wrappedMap = options?.name
2653
+ ? (...args) => {
2654
+ setStrictRead(options.name);
2655
+ try {
2656
+ return map(...args);
2657
+ } finally {
2658
+ setStrictRead(false);
2659
+ }
2660
+ }
2661
+ : map;
2627
2662
  return createMemo(
2628
2663
  updateKeyedMap.bind({
2629
2664
  _owner: createOwner(),
2630
2665
  _len: 0,
2631
2666
  _list: list,
2632
2667
  _items: [],
2633
- _map: map,
2668
+ _map: wrappedMap,
2634
2669
  _mappings: [],
2635
2670
  _nodes: [],
2636
2671
  _key: keyFn,
2637
2672
  _rows: keyFn || options?.keyed === false ? [] : undefined,
2638
- _indexes: map.length > 1 ? [] : undefined,
2673
+ _indexes: indexes ? [] : undefined,
2639
2674
  _fallback: options?.fallback
2640
2675
  })
2641
2676
  );
@@ -2767,12 +2802,22 @@ function updateKeyedMap() {
2767
2802
  return this._mappings;
2768
2803
  }
2769
2804
  function repeat(count, map, options) {
2805
+ const wrappedMap = options?.name
2806
+ ? i => {
2807
+ setStrictRead(options.name);
2808
+ try {
2809
+ return map(i);
2810
+ } finally {
2811
+ setStrictRead(false);
2812
+ }
2813
+ }
2814
+ : map;
2770
2815
  return updateRepeat.bind({
2771
2816
  _owner: createOwner(),
2772
2817
  _len: 0,
2773
2818
  _offset: 0,
2774
2819
  _count: count,
2775
- _map: map,
2820
+ _map: wrappedMap,
2776
2821
  _nodes: [],
2777
2822
  _mappings: [],
2778
2823
  _from: options?.from,
@@ -3030,6 +3075,7 @@ export {
3030
3075
  runWithOwner,
3031
3076
  setContext,
3032
3077
  setSnapshotCapture,
3078
+ setStrictRead,
3033
3079
  snapshot,
3034
3080
  untrack
3035
3081
  };