@solidjs/signals 0.10.8 → 0.11.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/dev.js CHANGED
@@ -601,8 +601,8 @@ function handleAsync(el, result, setter) {
601
601
  if (!equals || !equals(value, prevValue)) {
602
602
  el._value = value;
603
603
  el._time = clock;
604
- if (el._pendingValueComputed) {
605
- setSignal(el._pendingValueComputed, value);
604
+ if (el._latestValueComputed) {
605
+ setSignal(el._latestValueComputed, value);
606
606
  }
607
607
  insertSubs(el, true);
608
608
  }
@@ -869,7 +869,7 @@ function formatId(prefix, id) {
869
869
  return prefix + (len ? String.fromCharCode(64 + len) : "") + num;
870
870
  }
871
871
  function getObserver() {
872
- if (pendingCheckActive || pendingReadActive) return PENDING_OWNER;
872
+ if (pendingCheckActive || latestReadActive) return PENDING_OWNER;
873
873
  return tracking ? context : null;
874
874
  }
875
875
  function getOwner() {
@@ -1010,7 +1010,7 @@ function trackedEffect(fn, options) {
1010
1010
  }
1011
1011
  },
1012
1012
  undefined,
1013
- { ...options, lazy: true, pureWrite: true }
1013
+ { ...options, lazy: true }
1014
1014
  );
1015
1015
  node._cleanup = undefined;
1016
1016
  node._modified = true;
@@ -1028,7 +1028,7 @@ let stale = false;
1028
1028
  let refreshing = false;
1029
1029
  let pendingCheckActive = false;
1030
1030
  let foundPending = false;
1031
- let pendingReadActive = false;
1031
+ let latestReadActive = false;
1032
1032
  let context = null;
1033
1033
  let currentOptimisticLane = null;
1034
1034
  let snapshotCaptureActive = false;
@@ -1332,10 +1332,10 @@ function untrack(fn) {
1332
1332
  }
1333
1333
  }
1334
1334
  function read(el) {
1335
- if (pendingReadActive) {
1336
- const pendingComputed = getPendingValueComputed(el);
1337
- const prevPending = pendingReadActive;
1338
- pendingReadActive = false;
1335
+ if (latestReadActive) {
1336
+ const pendingComputed = getLatestValueComputed(el);
1337
+ const prevPending = latestReadActive;
1338
+ latestReadActive = false;
1339
1339
  let value;
1340
1340
  try {
1341
1341
  value = read(pendingComputed);
@@ -1343,7 +1343,7 @@ function read(el) {
1343
1343
  if (!context && e instanceof NotReadyError) return el._value;
1344
1344
  throw e;
1345
1345
  } finally {
1346
- pendingReadActive = prevPending;
1346
+ latestReadActive = prevPending;
1347
1347
  }
1348
1348
  if (pendingComputed._statusFlags & STATUS_PENDING) return el._value;
1349
1349
  if (stale && currentOptimisticLane && pendingComputed._optimisticLane) {
@@ -1434,7 +1434,7 @@ function read(el) {
1434
1434
  : el._pendingValue;
1435
1435
  }
1436
1436
  function setSignal(el, v) {
1437
- if (!el._pureWrite && context && el._firewall !== context)
1437
+ if (!el._pureWrite && !leafEffectActive && context && el._firewall !== context)
1438
1438
  console.warn("A Signal was written to in an owned scope.");
1439
1439
  if (el._transition && activeTransition !== el._transition)
1440
1440
  globalQueue.initTransition(el._transition);
@@ -1473,8 +1473,8 @@ function setSignal(el, v) {
1473
1473
  el._pendingValue = v;
1474
1474
  }
1475
1475
  updatePendingSignal(el);
1476
- if (el._pendingValueComputed) {
1477
- setSignal(el._pendingValueComputed, v);
1476
+ if (el._latestValueComputed) {
1477
+ setSignal(el._latestValueComputed, v);
1478
1478
  }
1479
1479
  el._time = clock;
1480
1480
  insertSubs(el, isOptimistic);
@@ -1535,21 +1535,21 @@ function updatePendingSignal(el) {
1535
1535
  }
1536
1536
  }
1537
1537
  }
1538
- function getPendingValueComputed(el) {
1539
- if (!el._pendingValueComputed) {
1540
- const prevPending = pendingReadActive;
1541
- pendingReadActive = false;
1538
+ function getLatestValueComputed(el) {
1539
+ if (!el._latestValueComputed) {
1540
+ const prevPending = latestReadActive;
1541
+ latestReadActive = false;
1542
1542
  const prevCheck = pendingCheckActive;
1543
1543
  pendingCheckActive = false;
1544
1544
  const prevContext = context;
1545
1545
  context = null;
1546
- el._pendingValueComputed = optimisticComputed(() => read(el));
1547
- el._pendingValueComputed._parentSource = el;
1546
+ el._latestValueComputed = optimisticComputed(() => read(el));
1547
+ el._latestValueComputed._parentSource = el;
1548
1548
  context = prevContext;
1549
1549
  pendingCheckActive = prevCheck;
1550
- pendingReadActive = prevPending;
1550
+ latestReadActive = prevPending;
1551
1551
  }
1552
- return el._pendingValueComputed;
1552
+ return el._latestValueComputed;
1553
1553
  }
1554
1554
  function staleValues(fn, set = true) {
1555
1555
  const prevStale = stale;
@@ -1560,13 +1560,13 @@ function staleValues(fn, set = true) {
1560
1560
  stale = prevStale;
1561
1561
  }
1562
1562
  }
1563
- function pending(fn) {
1564
- const prevPending = pendingReadActive;
1565
- pendingReadActive = true;
1563
+ function latest(fn) {
1564
+ const prevLatest = latestReadActive;
1565
+ latestReadActive = true;
1566
1566
  try {
1567
1567
  return fn();
1568
1568
  } finally {
1569
- pendingReadActive = prevPending;
1569
+ latestReadActive = prevLatest;
1570
1570
  }
1571
1571
  }
1572
1572
  function isPending(fn) {
@@ -2465,6 +2465,71 @@ function createOptimisticProjectionInternal(fn, initialValue = {}, options) {
2465
2465
  }
2466
2466
  return { store: wrappedStore, node: node };
2467
2467
  }
2468
+ const DELETE = Symbol("STORE_PATH_DELETE");
2469
+ function updatePath(current, args, i = 0) {
2470
+ let part,
2471
+ prev = current;
2472
+ if (i < args.length - 1) {
2473
+ part = args[i];
2474
+ const partType = typeof part;
2475
+ const isArray = Array.isArray(current);
2476
+ if (Array.isArray(part)) {
2477
+ for (let j = 0; j < part.length; j++) {
2478
+ args[i] = part[j];
2479
+ updatePath(current, args, i);
2480
+ }
2481
+ args[i] = part;
2482
+ return;
2483
+ } else if (isArray && partType === "function") {
2484
+ for (let j = 0; j < current.length; j++) {
2485
+ if (part(current[j], j)) {
2486
+ args[i] = j;
2487
+ updatePath(current, args, i);
2488
+ }
2489
+ }
2490
+ args[i] = part;
2491
+ return;
2492
+ } else if (isArray && partType === "object") {
2493
+ const { from: from = 0, to: to = current.length - 1, by: by = 1 } = part;
2494
+ for (let j = from; j <= to; j += by) {
2495
+ args[i] = j;
2496
+ updatePath(current, args, i);
2497
+ }
2498
+ args[i] = part;
2499
+ return;
2500
+ } else if (i < args.length - 2) {
2501
+ updatePath(current[part], args, i + 1);
2502
+ return;
2503
+ }
2504
+ prev = current[part];
2505
+ }
2506
+ let value = args[args.length - 1];
2507
+ if (typeof value === "function") {
2508
+ value = value(prev);
2509
+ if (value === prev) return;
2510
+ }
2511
+ if (part === undefined && value == undefined) return;
2512
+ if (value === DELETE) {
2513
+ delete current[part];
2514
+ } else if (
2515
+ part === undefined ||
2516
+ (isWrappable(prev) && isWrappable(value) && !Array.isArray(value))
2517
+ ) {
2518
+ const target = part !== undefined ? current[part] : current;
2519
+ const keys = Object.keys(value);
2520
+ for (let i = 0; i < keys.length; i++) target[keys[i]] = value[keys[i]];
2521
+ } else {
2522
+ current[part] = value;
2523
+ }
2524
+ }
2525
+ const storePath = Object.assign(
2526
+ function storePath(...args) {
2527
+ return state => {
2528
+ updatePath(state, args);
2529
+ };
2530
+ },
2531
+ { DELETE: DELETE }
2532
+ );
2468
2533
  function snapshot(item, map, lookup) {
2469
2534
  let target, isArray, override, result, unwrapped, v;
2470
2535
  if (!isWrappable(item)) return item;
@@ -3059,6 +3124,7 @@ export {
3059
3124
  isPending,
3060
3125
  isRefreshing,
3061
3126
  isWrappable,
3127
+ latest,
3062
3128
  mapArray,
3063
3129
  markSnapshotScope,
3064
3130
  merge,
@@ -3066,7 +3132,6 @@ export {
3066
3132
  onCleanup,
3067
3133
  onSettled,
3068
3134
  peekNextChildId,
3069
- pending,
3070
3135
  reconcile,
3071
3136
  refresh,
3072
3137
  releaseSnapshotScope,
@@ -3077,5 +3142,6 @@ export {
3077
3142
  setSnapshotCapture,
3078
3143
  setStrictRead,
3079
3144
  snapshot,
3145
+ storePath,
3080
3146
  untrack
3081
3147
  };