@solidjs/signals 0.2.3 → 0.2.5
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 +118 -34
- package/dist/node.cjs +374 -287
- package/dist/prod.js +371 -287
- package/dist/types/map.d.ts +1 -0
- package/dist/types/store/index.d.ts +1 -1
- package/dist/types/store/projection.d.ts +3 -1
- package/dist/types/store/store.d.ts +1 -0
- package/package.json +1 -1
package/dist/dev.js
CHANGED
|
@@ -986,7 +986,7 @@ function createAsync(compute2, value, options) {
|
|
|
986
986
|
_value: source
|
|
987
987
|
};
|
|
988
988
|
}
|
|
989
|
-
const signal = new Computation(value2, null, options);
|
|
989
|
+
const signal = new Computation(value2, null, iterator ? { ...options, equals: false } : options);
|
|
990
990
|
const w = signal.wait;
|
|
991
991
|
signal.wait = function() {
|
|
992
992
|
if (signal._stateFlags & ERROR_BIT && signal._time <= getClock()) {
|
|
@@ -1117,12 +1117,15 @@ function resolve(fn) {
|
|
|
1117
1117
|
|
|
1118
1118
|
// src/store/projection.ts
|
|
1119
1119
|
function createProjection(fn, initialValue = {}) {
|
|
1120
|
-
const [store
|
|
1120
|
+
const [store] = createStore(fn, initialValue);
|
|
1121
|
+
return store;
|
|
1122
|
+
}
|
|
1123
|
+
function wrapProjection(fn, store, setStore) {
|
|
1121
1124
|
const node = new ProjectionComputation(() => {
|
|
1122
1125
|
setStore(fn);
|
|
1123
1126
|
});
|
|
1124
1127
|
const wrapped = /* @__PURE__ */ new WeakMap();
|
|
1125
|
-
return wrap(store, node, wrapped);
|
|
1128
|
+
return [wrap(store, node, wrapped), setStore];
|
|
1126
1129
|
}
|
|
1127
1130
|
function wrap(source, node, wrapped) {
|
|
1128
1131
|
if (wrapped.has(source))
|
|
@@ -1147,8 +1150,10 @@ function wrap(source, node, wrapped) {
|
|
|
1147
1150
|
// src/store/store.ts
|
|
1148
1151
|
var $RAW = Symbol("STORE_RAW" );
|
|
1149
1152
|
var $TRACK = Symbol("STORE_TRACK" );
|
|
1153
|
+
var $DEEP = Symbol("STORE_DEEP" );
|
|
1150
1154
|
var $TARGET = Symbol("STORE_TARGET" );
|
|
1151
1155
|
var $PROXY = Symbol("STORE_PROXY" );
|
|
1156
|
+
var PARENTS = /* @__PURE__ */ new WeakMap();
|
|
1152
1157
|
var STORE_VALUE = "v";
|
|
1153
1158
|
var STORE_NODE = "n";
|
|
1154
1159
|
var STORE_HAS = "h";
|
|
@@ -1171,11 +1176,11 @@ function wrap2(value) {
|
|
|
1171
1176
|
function isWrappable(obj) {
|
|
1172
1177
|
return obj != null && typeof obj === "object" && !Object.isFrozen(obj);
|
|
1173
1178
|
}
|
|
1174
|
-
function unwrap(item,
|
|
1179
|
+
function unwrap(item, deep2 = true, set) {
|
|
1175
1180
|
let result, unwrapped, v, prop;
|
|
1176
1181
|
if (result = item != null && item[$RAW])
|
|
1177
1182
|
return result;
|
|
1178
|
-
if (!
|
|
1183
|
+
if (!deep2)
|
|
1179
1184
|
return item;
|
|
1180
1185
|
if (!isWrappable(item) || set?.has(item))
|
|
1181
1186
|
return item;
|
|
@@ -1185,11 +1190,11 @@ function unwrap(item, deep = true, set) {
|
|
|
1185
1190
|
if (Array.isArray(item)) {
|
|
1186
1191
|
for (let i = 0, l = item.length; i < l; i++) {
|
|
1187
1192
|
v = item[i];
|
|
1188
|
-
if ((unwrapped = unwrap(v,
|
|
1193
|
+
if ((unwrapped = unwrap(v, deep2, set)) !== v)
|
|
1189
1194
|
item[i] = unwrapped;
|
|
1190
1195
|
}
|
|
1191
1196
|
} else {
|
|
1192
|
-
if (!
|
|
1197
|
+
if (!deep2)
|
|
1193
1198
|
return item;
|
|
1194
1199
|
const keys = Object.keys(item);
|
|
1195
1200
|
for (let i = 0, l = keys.length; i < l; i++) {
|
|
@@ -1198,7 +1203,7 @@ function unwrap(item, deep = true, set) {
|
|
|
1198
1203
|
if (desc.get)
|
|
1199
1204
|
continue;
|
|
1200
1205
|
v = item[prop];
|
|
1201
|
-
if ((unwrapped = unwrap(v,
|
|
1206
|
+
if ((unwrapped = unwrap(v, deep2, set)) !== v)
|
|
1202
1207
|
item[prop] = unwrapped;
|
|
1203
1208
|
}
|
|
1204
1209
|
}
|
|
@@ -1231,8 +1236,8 @@ function proxyDescriptor(target, property) {
|
|
|
1231
1236
|
desc.get = () => target[STORE_VALUE][$PROXY][property];
|
|
1232
1237
|
return desc;
|
|
1233
1238
|
}
|
|
1234
|
-
function trackSelf(target) {
|
|
1235
|
-
getObserver() && getNode(getNodes(target, STORE_NODE),
|
|
1239
|
+
function trackSelf(target, symbol = $TRACK) {
|
|
1240
|
+
getObserver() && getNode(getNodes(target, STORE_NODE), symbol, void 0, false).read();
|
|
1236
1241
|
}
|
|
1237
1242
|
function ownKeys(target) {
|
|
1238
1243
|
trackSelf(target);
|
|
@@ -1247,8 +1252,8 @@ var proxyTraps = {
|
|
|
1247
1252
|
return target[STORE_VALUE];
|
|
1248
1253
|
if (property === $PROXY)
|
|
1249
1254
|
return receiver;
|
|
1250
|
-
if (property === $TRACK) {
|
|
1251
|
-
trackSelf(target);
|
|
1255
|
+
if (property === $TRACK || property === $DEEP) {
|
|
1256
|
+
trackSelf(target, property);
|
|
1252
1257
|
return receiver;
|
|
1253
1258
|
}
|
|
1254
1259
|
const nodes = getNodes(target, STORE_NODE);
|
|
@@ -1269,7 +1274,7 @@ var proxyTraps = {
|
|
|
1269
1274
|
let proto;
|
|
1270
1275
|
return !Array.isArray(storeValue) && (proto = Object.getPrototypeOf(storeValue)) && proto !== Object.prototype ? value.bind(storeValue) : value;
|
|
1271
1276
|
} else if (getObserver()) {
|
|
1272
|
-
|
|
1277
|
+
return getNode(nodes, property, isWrappable(value) ? wrap2(value) : value).read();
|
|
1273
1278
|
}
|
|
1274
1279
|
}
|
|
1275
1280
|
return isWrappable(value) ? wrap2(value) : value;
|
|
@@ -1304,6 +1309,13 @@ function setProperty(state, property, value, deleting = false) {
|
|
|
1304
1309
|
delete state[property];
|
|
1305
1310
|
else
|
|
1306
1311
|
state[property] = value;
|
|
1312
|
+
const wrappable = isWrappable(value);
|
|
1313
|
+
if (isWrappable(prev)) {
|
|
1314
|
+
const parents = PARENTS.get(prev);
|
|
1315
|
+
parents && (parents instanceof Set ? parents.delete(state) : PARENTS.delete(prev));
|
|
1316
|
+
}
|
|
1317
|
+
if (recursivelyNotify(state) && wrappable)
|
|
1318
|
+
recursivelyAddParent(value[$RAW] || value, state);
|
|
1307
1319
|
const target = state[$PROXY]?.[$TARGET];
|
|
1308
1320
|
if (!target)
|
|
1309
1321
|
return;
|
|
@@ -1312,18 +1324,55 @@ function setProperty(state, property, value, deleting = false) {
|
|
|
1312
1324
|
else
|
|
1313
1325
|
target[STORE_HAS]?.[property]?.write(true);
|
|
1314
1326
|
const nodes = getNodes(target, STORE_NODE);
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1327
|
+
nodes[property]?.write(wrappable ? wrap2(value) : value);
|
|
1328
|
+
Array.isArray(state) && state.length !== len && nodes.length?.write(state.length);
|
|
1329
|
+
nodes[$TRACK]?.write(void 0);
|
|
1330
|
+
}
|
|
1331
|
+
function recursivelyNotify(state) {
|
|
1332
|
+
let target = state[$PROXY]?.[$TARGET];
|
|
1333
|
+
let notified = false;
|
|
1334
|
+
target && (getNodes(target, STORE_NODE)[$DEEP]?.write(void 0), notified = true);
|
|
1335
|
+
const parents = PARENTS.get(state);
|
|
1336
|
+
if (!parents)
|
|
1337
|
+
return notified;
|
|
1338
|
+
if (parents instanceof Set) {
|
|
1339
|
+
for (let parent of parents)
|
|
1340
|
+
notified = recursivelyNotify(parent) || notified;
|
|
1341
|
+
} else
|
|
1342
|
+
notified = recursivelyNotify(parents) || notified;
|
|
1343
|
+
return notified;
|
|
1344
|
+
}
|
|
1345
|
+
function recursivelyAddParent(state, parent) {
|
|
1346
|
+
if (parent) {
|
|
1347
|
+
let parents = PARENTS.get(state);
|
|
1348
|
+
if (!parents)
|
|
1349
|
+
PARENTS.set(state, parent);
|
|
1350
|
+
else if (parents !== parent) {
|
|
1351
|
+
if (!(parents instanceof Set))
|
|
1352
|
+
PARENTS.set(state, parents = /* @__PURE__ */ new Set([parents]));
|
|
1353
|
+
else if (parents.has(parent))
|
|
1354
|
+
return;
|
|
1355
|
+
parents.add(parent);
|
|
1356
|
+
} else
|
|
1357
|
+
return;
|
|
1358
|
+
}
|
|
1359
|
+
if (Array.isArray(state)) {
|
|
1360
|
+
for (let i = 0; i < state.length; i++) {
|
|
1361
|
+
const item = state[i];
|
|
1362
|
+
isWrappable(item) && recursivelyAddParent(item[$RAW] || item, state);
|
|
1363
|
+
}
|
|
1364
|
+
} else {
|
|
1365
|
+
const keys = Object.keys(state);
|
|
1366
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1367
|
+
const item = state[keys[i]];
|
|
1368
|
+
isWrappable(item) && recursivelyAddParent(item[$RAW] || item, state);
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1320
1371
|
}
|
|
1321
1372
|
function createStore(first, second) {
|
|
1322
1373
|
const derived = typeof first === "function", store = derived ? second : first;
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
const unwrappedStore = unwrap(store, false);
|
|
1326
|
-
const wrappedStore = wrap2(unwrappedStore);
|
|
1374
|
+
const unwrappedStore = unwrap(store);
|
|
1375
|
+
let wrappedStore = wrap2(unwrappedStore);
|
|
1327
1376
|
const setStore = (fn) => {
|
|
1328
1377
|
try {
|
|
1329
1378
|
Writing.add(unwrappedStore);
|
|
@@ -1332,8 +1381,14 @@ function createStore(first, second) {
|
|
|
1332
1381
|
Writing.clear();
|
|
1333
1382
|
}
|
|
1334
1383
|
};
|
|
1384
|
+
if (derived)
|
|
1385
|
+
return wrapProjection(first, wrappedStore, setStore);
|
|
1335
1386
|
return [wrappedStore, setStore];
|
|
1336
1387
|
}
|
|
1388
|
+
function deep(store) {
|
|
1389
|
+
recursivelyAddParent(store[$RAW] || store);
|
|
1390
|
+
return store[$DEEP];
|
|
1391
|
+
}
|
|
1337
1392
|
|
|
1338
1393
|
// src/store/reconcile.ts
|
|
1339
1394
|
function applyState(next, state, keyFn) {
|
|
@@ -1718,15 +1773,18 @@ function repeat(count, map, options) {
|
|
|
1718
1773
|
return updateRepeat.bind({
|
|
1719
1774
|
_owner: new Owner(),
|
|
1720
1775
|
_len: 0,
|
|
1776
|
+
_offset: 0,
|
|
1721
1777
|
_count: count,
|
|
1722
1778
|
_map: map,
|
|
1723
1779
|
_nodes: [],
|
|
1724
1780
|
_mappings: [],
|
|
1781
|
+
_from: options?.from,
|
|
1725
1782
|
_fallback: options?.fallback
|
|
1726
1783
|
});
|
|
1727
1784
|
}
|
|
1728
1785
|
function updateRepeat() {
|
|
1729
1786
|
const newLen = this._count();
|
|
1787
|
+
const from = this._from?.() || 0;
|
|
1730
1788
|
runWithOwner(this._owner, () => {
|
|
1731
1789
|
if (newLen === 0) {
|
|
1732
1790
|
if (this._len !== 0) {
|
|
@@ -1742,21 +1800,47 @@ function updateRepeat() {
|
|
|
1742
1800
|
null
|
|
1743
1801
|
);
|
|
1744
1802
|
}
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1803
|
+
return;
|
|
1804
|
+
}
|
|
1805
|
+
const to = from + newLen;
|
|
1806
|
+
const prevTo = this._offset + this._len;
|
|
1807
|
+
if (this._len === 0 && this._nodes[0])
|
|
1808
|
+
this._nodes[0].dispose();
|
|
1809
|
+
for (let i = to; i < prevTo; i++)
|
|
1810
|
+
this._nodes[i - this._offset].dispose();
|
|
1811
|
+
if (this._offset < from) {
|
|
1812
|
+
let i = this._offset;
|
|
1813
|
+
while (i < from && i < this._len)
|
|
1814
|
+
this._nodes[i++].dispose();
|
|
1815
|
+
this._nodes.splice(0, from - this._offset);
|
|
1816
|
+
this._mappings.splice(0, from - this._offset);
|
|
1817
|
+
} else if (this._offset > from) {
|
|
1818
|
+
let i = prevTo - this._offset - 1;
|
|
1819
|
+
let difference = this._offset - from;
|
|
1820
|
+
this._nodes.length = this._mappings.length = newLen;
|
|
1821
|
+
while (i >= difference) {
|
|
1822
|
+
this._nodes[i] = this._nodes[i - difference];
|
|
1823
|
+
this._mappings[i] = this._mappings[i - difference];
|
|
1824
|
+
i--;
|
|
1825
|
+
}
|
|
1826
|
+
for (let i2 = 0; i2 < difference; i2++) {
|
|
1827
|
+
this._mappings[i2] = compute(
|
|
1828
|
+
this._nodes[i2] = new Owner(),
|
|
1829
|
+
() => this._map(i2 + from),
|
|
1752
1830
|
null
|
|
1753
1831
|
);
|
|
1754
1832
|
}
|
|
1755
|
-
for (let i = newLen; i < this._len; i++)
|
|
1756
|
-
this._nodes[i].dispose();
|
|
1757
|
-
this._mappings = this._mappings.slice(0, newLen);
|
|
1758
|
-
this._len = newLen;
|
|
1759
1833
|
}
|
|
1834
|
+
for (let i = prevTo; i < to; i++) {
|
|
1835
|
+
this._mappings[i - from] = compute(
|
|
1836
|
+
this._nodes[i - from] = new Owner(),
|
|
1837
|
+
() => this._map(i),
|
|
1838
|
+
null
|
|
1839
|
+
);
|
|
1840
|
+
}
|
|
1841
|
+
this._mappings = this._mappings.slice(0, newLen);
|
|
1842
|
+
this._offset = from;
|
|
1843
|
+
this._len = newLen;
|
|
1760
1844
|
});
|
|
1761
1845
|
return this._mappings;
|
|
1762
1846
|
}
|
|
@@ -1764,4 +1848,4 @@ function compare(key, a, b) {
|
|
|
1764
1848
|
return key ? key(a) === key(b) : true;
|
|
1765
1849
|
}
|
|
1766
1850
|
|
|
1767
|
-
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, runWithObserver, runWithOwner, setContext, untrack, unwrap };
|
|
1851
|
+
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, deep, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, runWithObserver, runWithOwner, setContext, untrack, unwrap };
|