@solidjs/signals 0.10.8 → 0.11.1
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 +98 -27
- package/dist/node.cjs +630 -562
- package/dist/prod.js +257 -189
- package/dist/types/core/constants.d.ts +1 -0
- package/dist/types/core/core.d.ts +2 -2
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/core/types.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/store/index.d.ts +2 -0
- package/dist/types/store/storePath.d.ts +30 -0
- package/package.json +1 -1
package/dist/dev.js
CHANGED
|
@@ -34,6 +34,7 @@ const REACTIVE_ZOMBIE = 1 << 5;
|
|
|
34
34
|
const REACTIVE_DISPOSED = 1 << 6;
|
|
35
35
|
const REACTIVE_OPTIMISTIC_DIRTY = 1 << 7;
|
|
36
36
|
const REACTIVE_SNAPSHOT_STALE = 1 << 8;
|
|
37
|
+
const REACTIVE_LAZY = 1 << 9;
|
|
37
38
|
const STATUS_PENDING = 1 << 0;
|
|
38
39
|
const STATUS_ERROR = 1 << 1;
|
|
39
40
|
const STATUS_UNINITIALIZED = 1 << 2;
|
|
@@ -601,8 +602,8 @@ function handleAsync(el, result, setter) {
|
|
|
601
602
|
if (!equals || !equals(value, prevValue)) {
|
|
602
603
|
el._value = value;
|
|
603
604
|
el._time = clock;
|
|
604
|
-
if (el.
|
|
605
|
-
setSignal(el.
|
|
605
|
+
if (el._latestValueComputed) {
|
|
606
|
+
setSignal(el._latestValueComputed, value);
|
|
606
607
|
}
|
|
607
608
|
insertSubs(el, true);
|
|
608
609
|
}
|
|
@@ -869,7 +870,7 @@ function formatId(prefix, id) {
|
|
|
869
870
|
return prefix + (len ? String.fromCharCode(64 + len) : "") + num;
|
|
870
871
|
}
|
|
871
872
|
function getObserver() {
|
|
872
|
-
if (pendingCheckActive ||
|
|
873
|
+
if (pendingCheckActive || latestReadActive) return PENDING_OWNER;
|
|
873
874
|
return tracking ? context : null;
|
|
874
875
|
}
|
|
875
876
|
function getOwner() {
|
|
@@ -1010,7 +1011,7 @@ function trackedEffect(fn, options) {
|
|
|
1010
1011
|
}
|
|
1011
1012
|
},
|
|
1012
1013
|
undefined,
|
|
1013
|
-
{ ...options, lazy: true
|
|
1014
|
+
{ ...options, lazy: true }
|
|
1014
1015
|
);
|
|
1015
1016
|
node._cleanup = undefined;
|
|
1016
1017
|
node._modified = true;
|
|
@@ -1028,7 +1029,7 @@ let stale = false;
|
|
|
1028
1029
|
let refreshing = false;
|
|
1029
1030
|
let pendingCheckActive = false;
|
|
1030
1031
|
let foundPending = false;
|
|
1031
|
-
let
|
|
1032
|
+
let latestReadActive = false;
|
|
1032
1033
|
let context = null;
|
|
1033
1034
|
let currentOptimisticLane = null;
|
|
1034
1035
|
let snapshotCaptureActive = false;
|
|
@@ -1237,7 +1238,7 @@ function computed(fn, initialValue, options) {
|
|
|
1237
1238
|
_parent: context,
|
|
1238
1239
|
_nextSibling: null,
|
|
1239
1240
|
_firstChild: null,
|
|
1240
|
-
_flags: REACTIVE_NONE,
|
|
1241
|
+
_flags: options?.lazy ? REACTIVE_LAZY : REACTIVE_NONE,
|
|
1241
1242
|
_statusFlags: STATUS_UNINITIALIZED,
|
|
1242
1243
|
_time: clock,
|
|
1243
1244
|
_pendingValue: NOT_PENDING,
|
|
@@ -1332,10 +1333,10 @@ function untrack(fn) {
|
|
|
1332
1333
|
}
|
|
1333
1334
|
}
|
|
1334
1335
|
function read(el) {
|
|
1335
|
-
if (
|
|
1336
|
-
const pendingComputed =
|
|
1337
|
-
const prevPending =
|
|
1338
|
-
|
|
1336
|
+
if (latestReadActive) {
|
|
1337
|
+
const pendingComputed = getLatestValueComputed(el);
|
|
1338
|
+
const prevPending = latestReadActive;
|
|
1339
|
+
latestReadActive = false;
|
|
1339
1340
|
let value;
|
|
1340
1341
|
try {
|
|
1341
1342
|
value = read(pendingComputed);
|
|
@@ -1343,7 +1344,7 @@ function read(el) {
|
|
|
1343
1344
|
if (!context && e instanceof NotReadyError) return el._value;
|
|
1344
1345
|
throw e;
|
|
1345
1346
|
} finally {
|
|
1346
|
-
|
|
1347
|
+
latestReadActive = prevPending;
|
|
1347
1348
|
}
|
|
1348
1349
|
if (pendingComputed._statusFlags & STATUS_PENDING) return el._value;
|
|
1349
1350
|
if (stale && currentOptimisticLane && pendingComputed._optimisticLane) {
|
|
@@ -1369,6 +1370,10 @@ function read(el) {
|
|
|
1369
1370
|
let c = context;
|
|
1370
1371
|
if (c?._root) c = c._parentComputed;
|
|
1371
1372
|
if (refreshing && el._fn) recompute(el);
|
|
1373
|
+
if (el._flags & REACTIVE_LAZY) {
|
|
1374
|
+
el._flags &= ~REACTIVE_LAZY;
|
|
1375
|
+
recompute(el, true);
|
|
1376
|
+
}
|
|
1372
1377
|
if (c && tracking) {
|
|
1373
1378
|
if (el._fn && el._flags & REACTIVE_DISPOSED) recompute(el);
|
|
1374
1379
|
link(el, c);
|
|
@@ -1434,7 +1439,7 @@ function read(el) {
|
|
|
1434
1439
|
: el._pendingValue;
|
|
1435
1440
|
}
|
|
1436
1441
|
function setSignal(el, v) {
|
|
1437
|
-
if (!el._pureWrite && context && el._firewall !== context)
|
|
1442
|
+
if (!el._pureWrite && !leafEffectActive && context && el._firewall !== context)
|
|
1438
1443
|
console.warn("A Signal was written to in an owned scope.");
|
|
1439
1444
|
if (el._transition && activeTransition !== el._transition)
|
|
1440
1445
|
globalQueue.initTransition(el._transition);
|
|
@@ -1473,8 +1478,8 @@ function setSignal(el, v) {
|
|
|
1473
1478
|
el._pendingValue = v;
|
|
1474
1479
|
}
|
|
1475
1480
|
updatePendingSignal(el);
|
|
1476
|
-
if (el.
|
|
1477
|
-
setSignal(el.
|
|
1481
|
+
if (el._latestValueComputed) {
|
|
1482
|
+
setSignal(el._latestValueComputed, v);
|
|
1478
1483
|
}
|
|
1479
1484
|
el._time = clock;
|
|
1480
1485
|
insertSubs(el, isOptimistic);
|
|
@@ -1535,21 +1540,21 @@ function updatePendingSignal(el) {
|
|
|
1535
1540
|
}
|
|
1536
1541
|
}
|
|
1537
1542
|
}
|
|
1538
|
-
function
|
|
1539
|
-
if (!el.
|
|
1540
|
-
const prevPending =
|
|
1541
|
-
|
|
1543
|
+
function getLatestValueComputed(el) {
|
|
1544
|
+
if (!el._latestValueComputed) {
|
|
1545
|
+
const prevPending = latestReadActive;
|
|
1546
|
+
latestReadActive = false;
|
|
1542
1547
|
const prevCheck = pendingCheckActive;
|
|
1543
1548
|
pendingCheckActive = false;
|
|
1544
1549
|
const prevContext = context;
|
|
1545
1550
|
context = null;
|
|
1546
|
-
el.
|
|
1547
|
-
el.
|
|
1551
|
+
el._latestValueComputed = optimisticComputed(() => read(el));
|
|
1552
|
+
el._latestValueComputed._parentSource = el;
|
|
1548
1553
|
context = prevContext;
|
|
1549
1554
|
pendingCheckActive = prevCheck;
|
|
1550
|
-
|
|
1555
|
+
latestReadActive = prevPending;
|
|
1551
1556
|
}
|
|
1552
|
-
return el.
|
|
1557
|
+
return el._latestValueComputed;
|
|
1553
1558
|
}
|
|
1554
1559
|
function staleValues(fn, set = true) {
|
|
1555
1560
|
const prevStale = stale;
|
|
@@ -1560,13 +1565,13 @@ function staleValues(fn, set = true) {
|
|
|
1560
1565
|
stale = prevStale;
|
|
1561
1566
|
}
|
|
1562
1567
|
}
|
|
1563
|
-
function
|
|
1564
|
-
const
|
|
1565
|
-
|
|
1568
|
+
function latest(fn) {
|
|
1569
|
+
const prevLatest = latestReadActive;
|
|
1570
|
+
latestReadActive = true;
|
|
1566
1571
|
try {
|
|
1567
1572
|
return fn();
|
|
1568
1573
|
} finally {
|
|
1569
|
-
|
|
1574
|
+
latestReadActive = prevLatest;
|
|
1570
1575
|
}
|
|
1571
1576
|
}
|
|
1572
1577
|
function isPending(fn) {
|
|
@@ -2465,6 +2470,71 @@ function createOptimisticProjectionInternal(fn, initialValue = {}, options) {
|
|
|
2465
2470
|
}
|
|
2466
2471
|
return { store: wrappedStore, node: node };
|
|
2467
2472
|
}
|
|
2473
|
+
const DELETE = Symbol("STORE_PATH_DELETE");
|
|
2474
|
+
function updatePath(current, args, i = 0) {
|
|
2475
|
+
let part,
|
|
2476
|
+
prev = current;
|
|
2477
|
+
if (i < args.length - 1) {
|
|
2478
|
+
part = args[i];
|
|
2479
|
+
const partType = typeof part;
|
|
2480
|
+
const isArray = Array.isArray(current);
|
|
2481
|
+
if (Array.isArray(part)) {
|
|
2482
|
+
for (let j = 0; j < part.length; j++) {
|
|
2483
|
+
args[i] = part[j];
|
|
2484
|
+
updatePath(current, args, i);
|
|
2485
|
+
}
|
|
2486
|
+
args[i] = part;
|
|
2487
|
+
return;
|
|
2488
|
+
} else if (isArray && partType === "function") {
|
|
2489
|
+
for (let j = 0; j < current.length; j++) {
|
|
2490
|
+
if (part(current[j], j)) {
|
|
2491
|
+
args[i] = j;
|
|
2492
|
+
updatePath(current, args, i);
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
args[i] = part;
|
|
2496
|
+
return;
|
|
2497
|
+
} else if (isArray && partType === "object") {
|
|
2498
|
+
const { from: from = 0, to: to = current.length - 1, by: by = 1 } = part;
|
|
2499
|
+
for (let j = from; j <= to; j += by) {
|
|
2500
|
+
args[i] = j;
|
|
2501
|
+
updatePath(current, args, i);
|
|
2502
|
+
}
|
|
2503
|
+
args[i] = part;
|
|
2504
|
+
return;
|
|
2505
|
+
} else if (i < args.length - 2) {
|
|
2506
|
+
updatePath(current[part], args, i + 1);
|
|
2507
|
+
return;
|
|
2508
|
+
}
|
|
2509
|
+
prev = current[part];
|
|
2510
|
+
}
|
|
2511
|
+
let value = args[args.length - 1];
|
|
2512
|
+
if (typeof value === "function") {
|
|
2513
|
+
value = value(prev);
|
|
2514
|
+
if (value === prev) return;
|
|
2515
|
+
}
|
|
2516
|
+
if (part === undefined && value == undefined) return;
|
|
2517
|
+
if (value === DELETE) {
|
|
2518
|
+
delete current[part];
|
|
2519
|
+
} else if (
|
|
2520
|
+
part === undefined ||
|
|
2521
|
+
(isWrappable(prev) && isWrappable(value) && !Array.isArray(value))
|
|
2522
|
+
) {
|
|
2523
|
+
const target = part !== undefined ? current[part] : current;
|
|
2524
|
+
const keys = Object.keys(value);
|
|
2525
|
+
for (let i = 0; i < keys.length; i++) target[keys[i]] = value[keys[i]];
|
|
2526
|
+
} else {
|
|
2527
|
+
current[part] = value;
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
const storePath = Object.assign(
|
|
2531
|
+
function storePath(...args) {
|
|
2532
|
+
return state => {
|
|
2533
|
+
updatePath(state, args);
|
|
2534
|
+
};
|
|
2535
|
+
},
|
|
2536
|
+
{ DELETE: DELETE }
|
|
2537
|
+
);
|
|
2468
2538
|
function snapshot(item, map, lookup) {
|
|
2469
2539
|
let target, isArray, override, result, unwrapped, v;
|
|
2470
2540
|
if (!isWrappable(item)) return item;
|
|
@@ -3059,6 +3129,7 @@ export {
|
|
|
3059
3129
|
isPending,
|
|
3060
3130
|
isRefreshing,
|
|
3061
3131
|
isWrappable,
|
|
3132
|
+
latest,
|
|
3062
3133
|
mapArray,
|
|
3063
3134
|
markSnapshotScope,
|
|
3064
3135
|
merge,
|
|
@@ -3066,7 +3137,6 @@ export {
|
|
|
3066
3137
|
onCleanup,
|
|
3067
3138
|
onSettled,
|
|
3068
3139
|
peekNextChildId,
|
|
3069
|
-
pending,
|
|
3070
3140
|
reconcile,
|
|
3071
3141
|
refresh,
|
|
3072
3142
|
releaseSnapshotScope,
|
|
@@ -3077,5 +3147,6 @@ export {
|
|
|
3077
3147
|
setSnapshotCapture,
|
|
3078
3148
|
setStrictRead,
|
|
3079
3149
|
snapshot,
|
|
3150
|
+
storePath,
|
|
3080
3151
|
untrack
|
|
3081
3152
|
};
|