@solidjs/signals 0.2.4 → 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 +70 -18
- package/dist/node.cjs +72 -18
- package/dist/prod.js +70 -18
- package/dist/types/store/index.d.ts +1 -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()) {
|
|
@@ -1150,8 +1150,10 @@ function wrap(source, node, wrapped) {
|
|
|
1150
1150
|
// src/store/store.ts
|
|
1151
1151
|
var $RAW = Symbol("STORE_RAW" );
|
|
1152
1152
|
var $TRACK = Symbol("STORE_TRACK" );
|
|
1153
|
+
var $DEEP = Symbol("STORE_DEEP" );
|
|
1153
1154
|
var $TARGET = Symbol("STORE_TARGET" );
|
|
1154
1155
|
var $PROXY = Symbol("STORE_PROXY" );
|
|
1156
|
+
var PARENTS = /* @__PURE__ */ new WeakMap();
|
|
1155
1157
|
var STORE_VALUE = "v";
|
|
1156
1158
|
var STORE_NODE = "n";
|
|
1157
1159
|
var STORE_HAS = "h";
|
|
@@ -1174,11 +1176,11 @@ function wrap2(value) {
|
|
|
1174
1176
|
function isWrappable(obj) {
|
|
1175
1177
|
return obj != null && typeof obj === "object" && !Object.isFrozen(obj);
|
|
1176
1178
|
}
|
|
1177
|
-
function unwrap(item,
|
|
1179
|
+
function unwrap(item, deep2 = true, set) {
|
|
1178
1180
|
let result, unwrapped, v, prop;
|
|
1179
1181
|
if (result = item != null && item[$RAW])
|
|
1180
1182
|
return result;
|
|
1181
|
-
if (!
|
|
1183
|
+
if (!deep2)
|
|
1182
1184
|
return item;
|
|
1183
1185
|
if (!isWrappable(item) || set?.has(item))
|
|
1184
1186
|
return item;
|
|
@@ -1188,11 +1190,11 @@ function unwrap(item, deep = true, set) {
|
|
|
1188
1190
|
if (Array.isArray(item)) {
|
|
1189
1191
|
for (let i = 0, l = item.length; i < l; i++) {
|
|
1190
1192
|
v = item[i];
|
|
1191
|
-
if ((unwrapped = unwrap(v,
|
|
1193
|
+
if ((unwrapped = unwrap(v, deep2, set)) !== v)
|
|
1192
1194
|
item[i] = unwrapped;
|
|
1193
1195
|
}
|
|
1194
1196
|
} else {
|
|
1195
|
-
if (!
|
|
1197
|
+
if (!deep2)
|
|
1196
1198
|
return item;
|
|
1197
1199
|
const keys = Object.keys(item);
|
|
1198
1200
|
for (let i = 0, l = keys.length; i < l; i++) {
|
|
@@ -1201,7 +1203,7 @@ function unwrap(item, deep = true, set) {
|
|
|
1201
1203
|
if (desc.get)
|
|
1202
1204
|
continue;
|
|
1203
1205
|
v = item[prop];
|
|
1204
|
-
if ((unwrapped = unwrap(v,
|
|
1206
|
+
if ((unwrapped = unwrap(v, deep2, set)) !== v)
|
|
1205
1207
|
item[prop] = unwrapped;
|
|
1206
1208
|
}
|
|
1207
1209
|
}
|
|
@@ -1234,8 +1236,8 @@ function proxyDescriptor(target, property) {
|
|
|
1234
1236
|
desc.get = () => target[STORE_VALUE][$PROXY][property];
|
|
1235
1237
|
return desc;
|
|
1236
1238
|
}
|
|
1237
|
-
function trackSelf(target) {
|
|
1238
|
-
getObserver() && getNode(getNodes(target, STORE_NODE),
|
|
1239
|
+
function trackSelf(target, symbol = $TRACK) {
|
|
1240
|
+
getObserver() && getNode(getNodes(target, STORE_NODE), symbol, void 0, false).read();
|
|
1239
1241
|
}
|
|
1240
1242
|
function ownKeys(target) {
|
|
1241
1243
|
trackSelf(target);
|
|
@@ -1250,8 +1252,8 @@ var proxyTraps = {
|
|
|
1250
1252
|
return target[STORE_VALUE];
|
|
1251
1253
|
if (property === $PROXY)
|
|
1252
1254
|
return receiver;
|
|
1253
|
-
if (property === $TRACK) {
|
|
1254
|
-
trackSelf(target);
|
|
1255
|
+
if (property === $TRACK || property === $DEEP) {
|
|
1256
|
+
trackSelf(target, property);
|
|
1255
1257
|
return receiver;
|
|
1256
1258
|
}
|
|
1257
1259
|
const nodes = getNodes(target, STORE_NODE);
|
|
@@ -1272,7 +1274,7 @@ var proxyTraps = {
|
|
|
1272
1274
|
let proto;
|
|
1273
1275
|
return !Array.isArray(storeValue) && (proto = Object.getPrototypeOf(storeValue)) && proto !== Object.prototype ? value.bind(storeValue) : value;
|
|
1274
1276
|
} else if (getObserver()) {
|
|
1275
|
-
|
|
1277
|
+
return getNode(nodes, property, isWrappable(value) ? wrap2(value) : value).read();
|
|
1276
1278
|
}
|
|
1277
1279
|
}
|
|
1278
1280
|
return isWrappable(value) ? wrap2(value) : value;
|
|
@@ -1307,6 +1309,13 @@ function setProperty(state, property, value, deleting = false) {
|
|
|
1307
1309
|
delete state[property];
|
|
1308
1310
|
else
|
|
1309
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);
|
|
1310
1319
|
const target = state[$PROXY]?.[$TARGET];
|
|
1311
1320
|
if (!target)
|
|
1312
1321
|
return;
|
|
@@ -1315,15 +1324,54 @@ function setProperty(state, property, value, deleting = false) {
|
|
|
1315
1324
|
else
|
|
1316
1325
|
target[STORE_HAS]?.[property]?.write(true);
|
|
1317
1326
|
const nodes = getNodes(target, STORE_NODE);
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
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
|
+
}
|
|
1323
1371
|
}
|
|
1324
1372
|
function createStore(first, second) {
|
|
1325
1373
|
const derived = typeof first === "function", store = derived ? second : first;
|
|
1326
|
-
const unwrappedStore = unwrap(store
|
|
1374
|
+
const unwrappedStore = unwrap(store);
|
|
1327
1375
|
let wrappedStore = wrap2(unwrappedStore);
|
|
1328
1376
|
const setStore = (fn) => {
|
|
1329
1377
|
try {
|
|
@@ -1337,6 +1385,10 @@ function createStore(first, second) {
|
|
|
1337
1385
|
return wrapProjection(first, wrappedStore, setStore);
|
|
1338
1386
|
return [wrappedStore, setStore];
|
|
1339
1387
|
}
|
|
1388
|
+
function deep(store) {
|
|
1389
|
+
recursivelyAddParent(store[$RAW] || store);
|
|
1390
|
+
return store[$DEEP];
|
|
1391
|
+
}
|
|
1340
1392
|
|
|
1341
1393
|
// src/store/reconcile.ts
|
|
1342
1394
|
function applyState(next, state, keyFn) {
|
|
@@ -1796,4 +1848,4 @@ function compare(key, a, b) {
|
|
|
1796
1848
|
return key ? key(a) === key(b) : true;
|
|
1797
1849
|
}
|
|
1798
1850
|
|
|
1799
|
-
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 };
|
package/dist/node.cjs
CHANGED
|
@@ -983,7 +983,7 @@ function createAsync(compute2, value, options) {
|
|
|
983
983
|
g: source
|
|
984
984
|
};
|
|
985
985
|
}
|
|
986
|
-
const signal = new Computation(value2, null, options);
|
|
986
|
+
const signal = new Computation(value2, null, iterator ? { ...options, equals: false } : options);
|
|
987
987
|
const w = signal.wait;
|
|
988
988
|
signal.wait = function() {
|
|
989
989
|
if (signal.f & ERROR_BIT && signal.y <= getClock()) {
|
|
@@ -1148,8 +1148,10 @@ function wrap(source, node, wrapped) {
|
|
|
1148
1148
|
// src/store/store.ts
|
|
1149
1149
|
var $RAW = Symbol(0);
|
|
1150
1150
|
var $TRACK = Symbol(0);
|
|
1151
|
+
var $DEEP = Symbol(0);
|
|
1151
1152
|
var $TARGET = Symbol(0);
|
|
1152
1153
|
var $PROXY = Symbol(0);
|
|
1154
|
+
var PARENTS = /* @__PURE__ */ new WeakMap();
|
|
1153
1155
|
var STORE_VALUE = "v";
|
|
1154
1156
|
var STORE_NODE = "n";
|
|
1155
1157
|
var STORE_HAS = "h";
|
|
@@ -1172,11 +1174,11 @@ function wrap2(value) {
|
|
|
1172
1174
|
function isWrappable(obj) {
|
|
1173
1175
|
return obj != null && typeof obj === "object" && !Object.isFrozen(obj);
|
|
1174
1176
|
}
|
|
1175
|
-
function unwrap(item,
|
|
1177
|
+
function unwrap(item, deep2 = true, set) {
|
|
1176
1178
|
let result, unwrapped, v, prop;
|
|
1177
1179
|
if (result = item != null && item[$RAW])
|
|
1178
1180
|
return result;
|
|
1179
|
-
if (!
|
|
1181
|
+
if (!deep2)
|
|
1180
1182
|
return item;
|
|
1181
1183
|
if (!isWrappable(item) || (set == null ? void 0 : set.has(item)))
|
|
1182
1184
|
return item;
|
|
@@ -1186,11 +1188,11 @@ function unwrap(item, deep = true, set) {
|
|
|
1186
1188
|
if (Array.isArray(item)) {
|
|
1187
1189
|
for (let i = 0, l = item.length; i < l; i++) {
|
|
1188
1190
|
v = item[i];
|
|
1189
|
-
if ((unwrapped = unwrap(v,
|
|
1191
|
+
if ((unwrapped = unwrap(v, deep2, set)) !== v)
|
|
1190
1192
|
item[i] = unwrapped;
|
|
1191
1193
|
}
|
|
1192
1194
|
} else {
|
|
1193
|
-
if (!
|
|
1195
|
+
if (!deep2)
|
|
1194
1196
|
return item;
|
|
1195
1197
|
const keys = Object.keys(item);
|
|
1196
1198
|
for (let i = 0, l = keys.length; i < l; i++) {
|
|
@@ -1199,7 +1201,7 @@ function unwrap(item, deep = true, set) {
|
|
|
1199
1201
|
if (desc.get)
|
|
1200
1202
|
continue;
|
|
1201
1203
|
v = item[prop];
|
|
1202
|
-
if ((unwrapped = unwrap(v,
|
|
1204
|
+
if ((unwrapped = unwrap(v, deep2, set)) !== v)
|
|
1203
1205
|
item[prop] = unwrapped;
|
|
1204
1206
|
}
|
|
1205
1207
|
}
|
|
@@ -1232,8 +1234,8 @@ function proxyDescriptor(target, property) {
|
|
|
1232
1234
|
desc.get = () => target[STORE_VALUE][$PROXY][property];
|
|
1233
1235
|
return desc;
|
|
1234
1236
|
}
|
|
1235
|
-
function trackSelf(target) {
|
|
1236
|
-
getObserver() && getNode(getNodes(target, STORE_NODE),
|
|
1237
|
+
function trackSelf(target, symbol = $TRACK) {
|
|
1238
|
+
getObserver() && getNode(getNodes(target, STORE_NODE), symbol, void 0, false).read();
|
|
1237
1239
|
}
|
|
1238
1240
|
function ownKeys(target) {
|
|
1239
1241
|
trackSelf(target);
|
|
@@ -1248,8 +1250,8 @@ var proxyTraps = {
|
|
|
1248
1250
|
return target[STORE_VALUE];
|
|
1249
1251
|
if (property === $PROXY)
|
|
1250
1252
|
return receiver;
|
|
1251
|
-
if (property === $TRACK) {
|
|
1252
|
-
trackSelf(target);
|
|
1253
|
+
if (property === $TRACK || property === $DEEP) {
|
|
1254
|
+
trackSelf(target, property);
|
|
1253
1255
|
return receiver;
|
|
1254
1256
|
}
|
|
1255
1257
|
const nodes = getNodes(target, STORE_NODE);
|
|
@@ -1270,7 +1272,7 @@ var proxyTraps = {
|
|
|
1270
1272
|
let proto;
|
|
1271
1273
|
return !Array.isArray(storeValue) && (proto = Object.getPrototypeOf(storeValue)) && proto !== Object.prototype ? value.bind(storeValue) : value;
|
|
1272
1274
|
} else if (getObserver()) {
|
|
1273
|
-
|
|
1275
|
+
return getNode(nodes, property, isWrappable(value) ? wrap2(value) : value).read();
|
|
1274
1276
|
}
|
|
1275
1277
|
}
|
|
1276
1278
|
return isWrappable(value) ? wrap2(value) : value;
|
|
@@ -1297,7 +1299,7 @@ var proxyTraps = {
|
|
|
1297
1299
|
}
|
|
1298
1300
|
};
|
|
1299
1301
|
function setProperty(state, property, value, deleting = false) {
|
|
1300
|
-
var _a, _b, _c, _d, _e;
|
|
1302
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1301
1303
|
const prev = state[property];
|
|
1302
1304
|
if (!deleting && prev === value)
|
|
1303
1305
|
return;
|
|
@@ -1306,6 +1308,13 @@ function setProperty(state, property, value, deleting = false) {
|
|
|
1306
1308
|
delete state[property];
|
|
1307
1309
|
else
|
|
1308
1310
|
state[property] = value;
|
|
1311
|
+
const wrappable = isWrappable(value);
|
|
1312
|
+
if (isWrappable(prev)) {
|
|
1313
|
+
const parents = PARENTS.get(prev);
|
|
1314
|
+
parents && (parents instanceof Set ? parents.delete(state) : PARENTS.delete(prev));
|
|
1315
|
+
}
|
|
1316
|
+
if (recursivelyNotify(state) && wrappable)
|
|
1317
|
+
recursivelyAddParent(value[$RAW] || value, state);
|
|
1309
1318
|
const target = (_a = state[$PROXY]) == null ? void 0 : _a[$TARGET];
|
|
1310
1319
|
if (!target)
|
|
1311
1320
|
return;
|
|
@@ -1314,15 +1323,55 @@ function setProperty(state, property, value, deleting = false) {
|
|
|
1314
1323
|
else
|
|
1315
1324
|
(_e = (_d = target[STORE_HAS]) == null ? void 0 : _d[property]) == null ? void 0 : _e.write(true);
|
|
1316
1325
|
const nodes = getNodes(target, STORE_NODE);
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1326
|
+
(_f = nodes[property]) == null ? void 0 : _f.write(wrappable ? wrap2(value) : value);
|
|
1327
|
+
Array.isArray(state) && state.length !== len && ((_g = nodes.length) == null ? void 0 : _g.write(state.length));
|
|
1328
|
+
(_h = nodes[$TRACK]) == null ? void 0 : _h.write(void 0);
|
|
1329
|
+
}
|
|
1330
|
+
function recursivelyNotify(state) {
|
|
1331
|
+
var _a, _b;
|
|
1332
|
+
let target = (_a = state[$PROXY]) == null ? void 0 : _a[$TARGET];
|
|
1333
|
+
let notified = false;
|
|
1334
|
+
target && ((_b = getNodes(target, STORE_NODE)[$DEEP]) == null ? void 0 : _b.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
|
+
}
|
|
1322
1371
|
}
|
|
1323
1372
|
function createStore(first, second) {
|
|
1324
1373
|
const derived = typeof first === "function", store = derived ? second : first;
|
|
1325
|
-
const unwrappedStore = unwrap(store
|
|
1374
|
+
const unwrappedStore = unwrap(store);
|
|
1326
1375
|
let wrappedStore = wrap2(unwrappedStore);
|
|
1327
1376
|
const setStore = (fn) => {
|
|
1328
1377
|
try {
|
|
@@ -1336,6 +1385,10 @@ function createStore(first, second) {
|
|
|
1336
1385
|
return wrapProjection(first, wrappedStore, setStore);
|
|
1337
1386
|
return [wrappedStore, setStore];
|
|
1338
1387
|
}
|
|
1388
|
+
function deep(store) {
|
|
1389
|
+
recursivelyAddParent(store[$RAW] || store);
|
|
1390
|
+
return store[$DEEP];
|
|
1391
|
+
}
|
|
1339
1392
|
|
|
1340
1393
|
// src/store/reconcile.ts
|
|
1341
1394
|
function applyState(next, state, keyFn) {
|
|
@@ -1821,6 +1874,7 @@ exports.createRoot = createRoot;
|
|
|
1821
1874
|
exports.createSignal = createSignal;
|
|
1822
1875
|
exports.createStore = createStore;
|
|
1823
1876
|
exports.createSuspense = createSuspense;
|
|
1877
|
+
exports.deep = deep;
|
|
1824
1878
|
exports.flatten = flatten;
|
|
1825
1879
|
exports.flushSync = flushSync;
|
|
1826
1880
|
exports.getContext = getContext;
|
package/dist/prod.js
CHANGED
|
@@ -973,7 +973,7 @@ function createAsync(compute2, value, options) {
|
|
|
973
973
|
g: source
|
|
974
974
|
};
|
|
975
975
|
}
|
|
976
|
-
const signal = new Computation(value2, null, options);
|
|
976
|
+
const signal = new Computation(value2, null, iterator ? { ...options, equals: false } : options);
|
|
977
977
|
const w = signal.wait;
|
|
978
978
|
signal.wait = function() {
|
|
979
979
|
if (signal.f & ERROR_BIT && signal.y <= getClock()) {
|
|
@@ -1137,8 +1137,10 @@ function wrap(source, node, wrapped) {
|
|
|
1137
1137
|
// src/store/store.ts
|
|
1138
1138
|
var $RAW = Symbol(0);
|
|
1139
1139
|
var $TRACK = Symbol(0);
|
|
1140
|
+
var $DEEP = Symbol(0);
|
|
1140
1141
|
var $TARGET = Symbol(0);
|
|
1141
1142
|
var $PROXY = Symbol(0);
|
|
1143
|
+
var PARENTS = /* @__PURE__ */ new WeakMap();
|
|
1142
1144
|
var STORE_VALUE = "v";
|
|
1143
1145
|
var STORE_NODE = "n";
|
|
1144
1146
|
var STORE_HAS = "h";
|
|
@@ -1161,11 +1163,11 @@ function wrap2(value) {
|
|
|
1161
1163
|
function isWrappable(obj) {
|
|
1162
1164
|
return obj != null && typeof obj === "object" && !Object.isFrozen(obj);
|
|
1163
1165
|
}
|
|
1164
|
-
function unwrap(item,
|
|
1166
|
+
function unwrap(item, deep2 = true, set) {
|
|
1165
1167
|
let result, unwrapped, v, prop;
|
|
1166
1168
|
if (result = item != null && item[$RAW])
|
|
1167
1169
|
return result;
|
|
1168
|
-
if (!
|
|
1170
|
+
if (!deep2)
|
|
1169
1171
|
return item;
|
|
1170
1172
|
if (!isWrappable(item) || set?.has(item))
|
|
1171
1173
|
return item;
|
|
@@ -1175,11 +1177,11 @@ function unwrap(item, deep = true, set) {
|
|
|
1175
1177
|
if (Array.isArray(item)) {
|
|
1176
1178
|
for (let i = 0, l = item.length; i < l; i++) {
|
|
1177
1179
|
v = item[i];
|
|
1178
|
-
if ((unwrapped = unwrap(v,
|
|
1180
|
+
if ((unwrapped = unwrap(v, deep2, set)) !== v)
|
|
1179
1181
|
item[i] = unwrapped;
|
|
1180
1182
|
}
|
|
1181
1183
|
} else {
|
|
1182
|
-
if (!
|
|
1184
|
+
if (!deep2)
|
|
1183
1185
|
return item;
|
|
1184
1186
|
const keys = Object.keys(item);
|
|
1185
1187
|
for (let i = 0, l = keys.length; i < l; i++) {
|
|
@@ -1188,7 +1190,7 @@ function unwrap(item, deep = true, set) {
|
|
|
1188
1190
|
if (desc.get)
|
|
1189
1191
|
continue;
|
|
1190
1192
|
v = item[prop];
|
|
1191
|
-
if ((unwrapped = unwrap(v,
|
|
1193
|
+
if ((unwrapped = unwrap(v, deep2, set)) !== v)
|
|
1192
1194
|
item[prop] = unwrapped;
|
|
1193
1195
|
}
|
|
1194
1196
|
}
|
|
@@ -1221,8 +1223,8 @@ function proxyDescriptor(target, property) {
|
|
|
1221
1223
|
desc.get = () => target[STORE_VALUE][$PROXY][property];
|
|
1222
1224
|
return desc;
|
|
1223
1225
|
}
|
|
1224
|
-
function trackSelf(target) {
|
|
1225
|
-
getObserver() && getNode(getNodes(target, STORE_NODE),
|
|
1226
|
+
function trackSelf(target, symbol = $TRACK) {
|
|
1227
|
+
getObserver() && getNode(getNodes(target, STORE_NODE), symbol, void 0, false).read();
|
|
1226
1228
|
}
|
|
1227
1229
|
function ownKeys(target) {
|
|
1228
1230
|
trackSelf(target);
|
|
@@ -1237,8 +1239,8 @@ var proxyTraps = {
|
|
|
1237
1239
|
return target[STORE_VALUE];
|
|
1238
1240
|
if (property === $PROXY)
|
|
1239
1241
|
return receiver;
|
|
1240
|
-
if (property === $TRACK) {
|
|
1241
|
-
trackSelf(target);
|
|
1242
|
+
if (property === $TRACK || property === $DEEP) {
|
|
1243
|
+
trackSelf(target, property);
|
|
1242
1244
|
return receiver;
|
|
1243
1245
|
}
|
|
1244
1246
|
const nodes = getNodes(target, STORE_NODE);
|
|
@@ -1259,7 +1261,7 @@ var proxyTraps = {
|
|
|
1259
1261
|
let proto;
|
|
1260
1262
|
return !Array.isArray(storeValue) && (proto = Object.getPrototypeOf(storeValue)) && proto !== Object.prototype ? value.bind(storeValue) : value;
|
|
1261
1263
|
} else if (getObserver()) {
|
|
1262
|
-
|
|
1264
|
+
return getNode(nodes, property, isWrappable(value) ? wrap2(value) : value).read();
|
|
1263
1265
|
}
|
|
1264
1266
|
}
|
|
1265
1267
|
return isWrappable(value) ? wrap2(value) : value;
|
|
@@ -1294,6 +1296,13 @@ function setProperty(state, property, value, deleting = false) {
|
|
|
1294
1296
|
delete state[property];
|
|
1295
1297
|
else
|
|
1296
1298
|
state[property] = value;
|
|
1299
|
+
const wrappable = isWrappable(value);
|
|
1300
|
+
if (isWrappable(prev)) {
|
|
1301
|
+
const parents = PARENTS.get(prev);
|
|
1302
|
+
parents && (parents instanceof Set ? parents.delete(state) : PARENTS.delete(prev));
|
|
1303
|
+
}
|
|
1304
|
+
if (recursivelyNotify(state) && wrappable)
|
|
1305
|
+
recursivelyAddParent(value[$RAW] || value, state);
|
|
1297
1306
|
const target = state[$PROXY]?.[$TARGET];
|
|
1298
1307
|
if (!target)
|
|
1299
1308
|
return;
|
|
@@ -1302,15 +1311,54 @@ function setProperty(state, property, value, deleting = false) {
|
|
|
1302
1311
|
else
|
|
1303
1312
|
target[STORE_HAS]?.[property]?.write(true);
|
|
1304
1313
|
const nodes = getNodes(target, STORE_NODE);
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1314
|
+
nodes[property]?.write(wrappable ? wrap2(value) : value);
|
|
1315
|
+
Array.isArray(state) && state.length !== len && nodes.length?.write(state.length);
|
|
1316
|
+
nodes[$TRACK]?.write(void 0);
|
|
1317
|
+
}
|
|
1318
|
+
function recursivelyNotify(state) {
|
|
1319
|
+
let target = state[$PROXY]?.[$TARGET];
|
|
1320
|
+
let notified = false;
|
|
1321
|
+
target && (getNodes(target, STORE_NODE)[$DEEP]?.write(void 0), notified = true);
|
|
1322
|
+
const parents = PARENTS.get(state);
|
|
1323
|
+
if (!parents)
|
|
1324
|
+
return notified;
|
|
1325
|
+
if (parents instanceof Set) {
|
|
1326
|
+
for (let parent of parents)
|
|
1327
|
+
notified = recursivelyNotify(parent) || notified;
|
|
1328
|
+
} else
|
|
1329
|
+
notified = recursivelyNotify(parents) || notified;
|
|
1330
|
+
return notified;
|
|
1331
|
+
}
|
|
1332
|
+
function recursivelyAddParent(state, parent) {
|
|
1333
|
+
if (parent) {
|
|
1334
|
+
let parents = PARENTS.get(state);
|
|
1335
|
+
if (!parents)
|
|
1336
|
+
PARENTS.set(state, parent);
|
|
1337
|
+
else if (parents !== parent) {
|
|
1338
|
+
if (!(parents instanceof Set))
|
|
1339
|
+
PARENTS.set(state, parents = /* @__PURE__ */ new Set([parents]));
|
|
1340
|
+
else if (parents.has(parent))
|
|
1341
|
+
return;
|
|
1342
|
+
parents.add(parent);
|
|
1343
|
+
} else
|
|
1344
|
+
return;
|
|
1345
|
+
}
|
|
1346
|
+
if (Array.isArray(state)) {
|
|
1347
|
+
for (let i = 0; i < state.length; i++) {
|
|
1348
|
+
const item = state[i];
|
|
1349
|
+
isWrappable(item) && recursivelyAddParent(item[$RAW] || item, state);
|
|
1350
|
+
}
|
|
1351
|
+
} else {
|
|
1352
|
+
const keys = Object.keys(state);
|
|
1353
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1354
|
+
const item = state[keys[i]];
|
|
1355
|
+
isWrappable(item) && recursivelyAddParent(item[$RAW] || item, state);
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1310
1358
|
}
|
|
1311
1359
|
function createStore(first, second) {
|
|
1312
1360
|
const derived = typeof first === "function", store = derived ? second : first;
|
|
1313
|
-
const unwrappedStore = unwrap(store
|
|
1361
|
+
const unwrappedStore = unwrap(store);
|
|
1314
1362
|
let wrappedStore = wrap2(unwrappedStore);
|
|
1315
1363
|
const setStore = (fn) => {
|
|
1316
1364
|
try {
|
|
@@ -1324,6 +1372,10 @@ function createStore(first, second) {
|
|
|
1324
1372
|
return wrapProjection(first, wrappedStore, setStore);
|
|
1325
1373
|
return [wrappedStore, setStore];
|
|
1326
1374
|
}
|
|
1375
|
+
function deep(store) {
|
|
1376
|
+
recursivelyAddParent(store[$RAW] || store);
|
|
1377
|
+
return store[$DEEP];
|
|
1378
|
+
}
|
|
1327
1379
|
|
|
1328
1380
|
// src/store/reconcile.ts
|
|
1329
1381
|
function applyState(next, state, keyFn) {
|
|
@@ -1783,4 +1835,4 @@ function compare(key, a, b) {
|
|
|
1783
1835
|
return key ? key(a) === key(b) : true;
|
|
1784
1836
|
}
|
|
1785
1837
|
|
|
1786
|
-
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 };
|
|
1838
|
+
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 };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type { Store, StoreSetter, StoreNode, NotWrappable, SolidStore } from "./store.js";
|
|
2
2
|
export type { Merge, Omit } from "./utils.js";
|
|
3
|
-
export { unwrap, isWrappable, createStore, $RAW, $TRACK, $PROXY, $TARGET } from "./store.js";
|
|
3
|
+
export { unwrap, isWrappable, createStore, deep, $RAW, $TRACK, $PROXY, $TARGET } from "./store.js";
|
|
4
4
|
export { createProjection } from "./projection.js";
|
|
5
5
|
export { reconcile } from "./reconcile.js";
|
|
6
6
|
export { merge, omit } from "./utils.js";
|
|
@@ -32,3 +32,4 @@ export declare function isWrappable<T>(obj: T | NotWrappable): obj is T;
|
|
|
32
32
|
export declare function unwrap<T>(item: T, deep?: boolean, set?: Set<unknown>): T;
|
|
33
33
|
export declare function createStore<T extends object = {}>(store: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
|
|
34
34
|
export declare function createStore<T extends object = {}>(fn: (store: T) => void, store: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
|
|
35
|
+
export declare function deep<T extends object>(store: Store<T>): Store<any>;
|