@solidjs/signals 0.8.2 → 0.8.3
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 +88 -42
- package/dist/node.cjs +339 -289
- package/dist/prod.js +334 -288
- package/dist/types/core/core.d.ts +2 -1
- package/dist/types/core/effect.d.ts +0 -1
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/core/scheduler.d.ts +0 -1
- package/dist/types/signals.d.ts +1 -1
- package/dist/types/store/store.d.ts +3 -2
- package/package.json +1 -1
package/dist/dev.js
CHANGED
|
@@ -129,8 +129,8 @@ function adjustHeight(el, heap) {
|
|
|
129
129
|
let newHeight = el._height;
|
|
130
130
|
for (let d = el._deps; d; d = d._nextDep) {
|
|
131
131
|
const dep1 = d._dep;
|
|
132
|
-
const dep =
|
|
133
|
-
if (
|
|
132
|
+
const dep = dep1._firewall || dep1;
|
|
133
|
+
if (dep._fn) {
|
|
134
134
|
if (dep._height >= newHeight) {
|
|
135
135
|
newHeight = dep._height + 1;
|
|
136
136
|
}
|
|
@@ -147,7 +147,6 @@ function adjustHeight(el, heap) {
|
|
|
147
147
|
// src/core/scheduler.ts
|
|
148
148
|
var clock = 0;
|
|
149
149
|
var activeTransition = null;
|
|
150
|
-
var unobserved = [];
|
|
151
150
|
var transitions = /* @__PURE__ */ new Set();
|
|
152
151
|
var scheduled = false;
|
|
153
152
|
function schedule() {
|
|
@@ -276,7 +275,6 @@ var GlobalQueue = class _GlobalQueue extends Queue {
|
|
|
276
275
|
this.run(2 /* User */);
|
|
277
276
|
} finally {
|
|
278
277
|
this._running = false;
|
|
279
|
-
unobserved.length && notifyUnobserved();
|
|
280
278
|
}
|
|
281
279
|
}
|
|
282
280
|
notify(node, mask, flags) {
|
|
@@ -346,14 +344,6 @@ function transitionComplete(transition) {
|
|
|
346
344
|
}
|
|
347
345
|
return done;
|
|
348
346
|
}
|
|
349
|
-
function notifyUnobserved() {
|
|
350
|
-
for (let i = 0; i < unobserved.length; i++) {
|
|
351
|
-
const source = unobserved[i];
|
|
352
|
-
if (!source._subs)
|
|
353
|
-
unobserved[i]._unobserved?.();
|
|
354
|
-
}
|
|
355
|
-
unobserved = [];
|
|
356
|
-
}
|
|
357
347
|
|
|
358
348
|
// src/core/core.ts
|
|
359
349
|
GlobalQueue._update = recompute;
|
|
@@ -454,8 +444,8 @@ function updateIfNecessary(el) {
|
|
|
454
444
|
if (el._flags & 1 /* Check */) {
|
|
455
445
|
for (let d = el._deps; d; d = d._nextDep) {
|
|
456
446
|
const dep1 = d._dep;
|
|
457
|
-
const dep =
|
|
458
|
-
if (
|
|
447
|
+
const dep = dep1._firewall || dep1;
|
|
448
|
+
if (dep._fn) {
|
|
459
449
|
updateIfNecessary(dep);
|
|
460
450
|
}
|
|
461
451
|
if (el._flags & 2 /* Dirty */) {
|
|
@@ -482,9 +472,22 @@ function unlinkSubs(link2) {
|
|
|
482
472
|
prevSub._nextSub = nextSub;
|
|
483
473
|
} else {
|
|
484
474
|
dep._subs = nextSub;
|
|
475
|
+
if (nextSub === null) {
|
|
476
|
+
dep._unobserved?.();
|
|
477
|
+
dep._fn && unobserved(dep);
|
|
478
|
+
}
|
|
485
479
|
}
|
|
486
480
|
return nextDep;
|
|
487
481
|
}
|
|
482
|
+
function unobserved(el) {
|
|
483
|
+
deleteFromHeap(el, el._flags & 32 /* Zombie */ ? zombieQueue : dirtyQueue);
|
|
484
|
+
let dep = el._deps;
|
|
485
|
+
while (dep !== null) {
|
|
486
|
+
dep = unlinkSubs(dep);
|
|
487
|
+
}
|
|
488
|
+
el._deps = null;
|
|
489
|
+
runDisposal(el);
|
|
490
|
+
}
|
|
488
491
|
function link(dep, sub) {
|
|
489
492
|
const prevDep = sub._depsTail;
|
|
490
493
|
if (prevDep !== null && prevDep._dep === dep) {
|
|
@@ -560,6 +563,15 @@ function markDisposal(el) {
|
|
|
560
563
|
child = child._nextSibling;
|
|
561
564
|
}
|
|
562
565
|
}
|
|
566
|
+
function dispose(node) {
|
|
567
|
+
let toRemove = node._deps || null;
|
|
568
|
+
do {
|
|
569
|
+
toRemove = unlinkSubs(toRemove);
|
|
570
|
+
} while (toRemove !== null);
|
|
571
|
+
node._deps = null;
|
|
572
|
+
node._depsTail = null;
|
|
573
|
+
disposeChildren(node, true);
|
|
574
|
+
}
|
|
563
575
|
function disposeChildren(node, self = false, zombie) {
|
|
564
576
|
if (node._flags & 64 /* Disposed */)
|
|
565
577
|
return;
|
|
@@ -738,7 +750,7 @@ function signal(v, options, firewall = null) {
|
|
|
738
750
|
_value: v,
|
|
739
751
|
_subs: null,
|
|
740
752
|
_subsTail: null,
|
|
741
|
-
|
|
753
|
+
_firewall: firewall,
|
|
742
754
|
_nextChild: firewall._child,
|
|
743
755
|
_statusFlags: 0 /* None */,
|
|
744
756
|
_time: clock,
|
|
@@ -779,8 +791,8 @@ function read(el) {
|
|
|
779
791
|
c = c._parentComputed;
|
|
780
792
|
if (c && tracking) {
|
|
781
793
|
link(el, c);
|
|
782
|
-
const owner =
|
|
783
|
-
if (
|
|
794
|
+
const owner = el._firewall || el;
|
|
795
|
+
if (owner._fn) {
|
|
784
796
|
const isZombie = el._flags & 32 /* Zombie */;
|
|
785
797
|
if (owner._height >= (isZombie ? zombieQueue._min : dirtyQueue._min)) {
|
|
786
798
|
markNode(c);
|
|
@@ -843,7 +855,7 @@ function read(el) {
|
|
|
843
855
|
return !c || el._pendingValue === NOT_PENDING || stale && !pendingCheck && el._transition && activeTransition !== el._transition ? el._value : el._pendingValue;
|
|
844
856
|
}
|
|
845
857
|
function setSignal(el, v) {
|
|
846
|
-
if (!el._pureWrite && context &&
|
|
858
|
+
if (!el._pureWrite && context && el._firewall !== context)
|
|
847
859
|
console.warn("A Signal was written to in an owned scope.");
|
|
848
860
|
if (typeof v === "function") {
|
|
849
861
|
v = v(
|
|
@@ -1113,11 +1125,29 @@ function createRenderEffect(compute, effectFn, value, options) {
|
|
|
1113
1125
|
}
|
|
1114
1126
|
function createTrackedEffect(compute, options) {
|
|
1115
1127
|
}
|
|
1116
|
-
function createReaction(
|
|
1128
|
+
function createReaction(effectFn, options) {
|
|
1129
|
+
let cleanup = void 0;
|
|
1130
|
+
onCleanup(() => cleanup?.());
|
|
1131
|
+
return (tracking2) => {
|
|
1132
|
+
effect(
|
|
1133
|
+
() => (tracking2(), getOwner()),
|
|
1134
|
+
(node) => {
|
|
1135
|
+
cleanup?.();
|
|
1136
|
+
cleanup = (effectFn.effect || effectFn)?.();
|
|
1137
|
+
dispose(node);
|
|
1138
|
+
},
|
|
1139
|
+
effectFn.error,
|
|
1140
|
+
void 0,
|
|
1141
|
+
{
|
|
1142
|
+
defer: true,
|
|
1143
|
+
...{ ...options, name: options?.name ?? "effect" }
|
|
1144
|
+
}
|
|
1145
|
+
);
|
|
1146
|
+
};
|
|
1117
1147
|
}
|
|
1118
1148
|
function resolve(fn) {
|
|
1119
1149
|
return new Promise((res, rej) => {
|
|
1120
|
-
createRoot((
|
|
1150
|
+
createRoot((dispose2) => {
|
|
1121
1151
|
computed(() => {
|
|
1122
1152
|
try {
|
|
1123
1153
|
res(fn());
|
|
@@ -1126,7 +1156,7 @@ function resolve(fn) {
|
|
|
1126
1156
|
throw err;
|
|
1127
1157
|
rej(err);
|
|
1128
1158
|
}
|
|
1129
|
-
|
|
1159
|
+
dispose2();
|
|
1130
1160
|
});
|
|
1131
1161
|
});
|
|
1132
1162
|
});
|
|
@@ -1135,6 +1165,14 @@ function createOptimistic(first, second, third) {
|
|
|
1135
1165
|
return {};
|
|
1136
1166
|
}
|
|
1137
1167
|
function onSettled(callback) {
|
|
1168
|
+
let cleanup;
|
|
1169
|
+
const o = getOwner();
|
|
1170
|
+
if (o)
|
|
1171
|
+
onCleanup(() => cleanup?.());
|
|
1172
|
+
globalQueue.enqueue(2 /* User */, () => {
|
|
1173
|
+
cleanup = callback();
|
|
1174
|
+
!o && cleanup?.();
|
|
1175
|
+
});
|
|
1138
1176
|
}
|
|
1139
1177
|
|
|
1140
1178
|
// src/store/reconcile.ts
|
|
@@ -1270,23 +1308,17 @@ function reconcile(value, key, all = false) {
|
|
|
1270
1308
|
function createProjectionInternal(fn, initialValue = {}, options) {
|
|
1271
1309
|
let node;
|
|
1272
1310
|
const wrappedMap = /* @__PURE__ */ new WeakMap();
|
|
1273
|
-
const traps = {
|
|
1274
|
-
...storeTraps,
|
|
1275
|
-
get(target, property, receiver) {
|
|
1276
|
-
const o = getOwner();
|
|
1277
|
-
const n = node;
|
|
1278
|
-
(!o || o !== n) && n && read(n);
|
|
1279
|
-
return storeTraps.get(target, property, receiver);
|
|
1280
|
-
}
|
|
1281
|
-
};
|
|
1282
1311
|
const wrapProjection = (source) => {
|
|
1283
1312
|
if (wrappedMap.has(source))
|
|
1284
1313
|
return wrappedMap.get(source);
|
|
1285
1314
|
if (source[$TARGET]?.[STORE_WRAP] === wrapProjection)
|
|
1286
1315
|
return source;
|
|
1287
|
-
const wrapped = createStoreProxy(source,
|
|
1316
|
+
const wrapped = createStoreProxy(source, storeTraps, {
|
|
1288
1317
|
[STORE_WRAP]: wrapProjection,
|
|
1289
|
-
[STORE_LOOKUP]: wrappedMap
|
|
1318
|
+
[STORE_LOOKUP]: wrappedMap,
|
|
1319
|
+
[STORE_FIREWALL]() {
|
|
1320
|
+
return node;
|
|
1321
|
+
}
|
|
1290
1322
|
});
|
|
1291
1323
|
wrappedMap.set(source, wrapped);
|
|
1292
1324
|
return wrapped;
|
|
@@ -1319,6 +1351,7 @@ var STORE_NODE = "n";
|
|
|
1319
1351
|
var STORE_HAS = "h";
|
|
1320
1352
|
var STORE_WRAP = "w";
|
|
1321
1353
|
var STORE_LOOKUP = "l";
|
|
1354
|
+
var STORE_FIREWALL = "f";
|
|
1322
1355
|
function createStoreProxy(value, traps = storeTraps, extend) {
|
|
1323
1356
|
let newTarget;
|
|
1324
1357
|
if (Array.isArray(value)) {
|
|
@@ -1347,18 +1380,24 @@ function getNodes(target, type) {
|
|
|
1347
1380
|
target[type] = nodes = /* @__PURE__ */ Object.create(null);
|
|
1348
1381
|
return nodes;
|
|
1349
1382
|
}
|
|
1350
|
-
function getNode(nodes, property, value, equals = isEqual) {
|
|
1383
|
+
function getNode(nodes, property, value, firewall, equals = isEqual) {
|
|
1351
1384
|
if (nodes[property])
|
|
1352
1385
|
return nodes[property];
|
|
1353
|
-
return nodes[property] = signal(
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1386
|
+
return nodes[property] = signal(
|
|
1387
|
+
value,
|
|
1388
|
+
{
|
|
1389
|
+
equals,
|
|
1390
|
+
unobserved() {
|
|
1391
|
+
delete nodes[property];
|
|
1392
|
+
}
|
|
1393
|
+
},
|
|
1394
|
+
firewall
|
|
1395
|
+
);
|
|
1359
1396
|
}
|
|
1360
1397
|
function trackSelf(target, symbol = $TRACK) {
|
|
1361
|
-
getObserver() && read(
|
|
1398
|
+
getObserver() && read(
|
|
1399
|
+
getNode(getNodes(target, STORE_NODE), symbol, void 0, target[STORE_FIREWALL]?.(), false)
|
|
1400
|
+
);
|
|
1362
1401
|
}
|
|
1363
1402
|
function getKeys(source, override, enumerable = true) {
|
|
1364
1403
|
const baseKeys = untrack(() => enumerable ? Object.keys(source) : Reflect.ownKeys(source));
|
|
@@ -1421,7 +1460,14 @@ var storeTraps = {
|
|
|
1421
1460
|
let proto;
|
|
1422
1461
|
return !Array.isArray(target[STORE_VALUE]) && (proto = Object.getPrototypeOf(target[STORE_VALUE])) && proto !== Object.prototype ? value.bind(storeValue) : value;
|
|
1423
1462
|
} else if (getObserver()) {
|
|
1424
|
-
return read(
|
|
1463
|
+
return read(
|
|
1464
|
+
getNode(
|
|
1465
|
+
nodes,
|
|
1466
|
+
property,
|
|
1467
|
+
isWrappable(value) ? wrap(value, target) : value,
|
|
1468
|
+
target[STORE_FIREWALL]?.()
|
|
1469
|
+
)
|
|
1470
|
+
);
|
|
1425
1471
|
}
|
|
1426
1472
|
}
|
|
1427
1473
|
return isWrappable(value) ? wrap(value, target) : value;
|
|
@@ -1430,7 +1476,7 @@ var storeTraps = {
|
|
|
1430
1476
|
if (property === $PROXY || property === $TRACK || property === "__proto__")
|
|
1431
1477
|
return true;
|
|
1432
1478
|
const has = target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE] ? target[STORE_OVERRIDE][property] !== $DELETED : property in target[STORE_VALUE];
|
|
1433
|
-
getObserver() && read(getNode(getNodes(target, STORE_HAS), property, has));
|
|
1479
|
+
getObserver() && read(getNode(getNodes(target, STORE_HAS), property, has, target[STORE_FIREWALL]?.()));
|
|
1434
1480
|
return has;
|
|
1435
1481
|
},
|
|
1436
1482
|
set(target, property, rawValue) {
|