solid-js 1.4.2 → 1.4.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.cjs +7 -6
- package/dist/dev.js +7 -6
- package/dist/server.cjs +9 -6
- package/dist/server.js +9 -6
- package/dist/solid.cjs +7 -6
- package/dist/solid.js +7 -6
- package/package.json +2 -2
- package/store/README.md +2 -2
- package/store/dist/dev.cjs +20 -10
- package/store/dist/dev.js +20 -10
- package/store/dist/store.cjs +20 -10
- package/store/dist/store.js +20 -10
- package/store/types/modifiers.d.ts +1 -2
- package/store/types/server.d.ts +3 -3
- package/store/types/store.d.ts +12 -5
- package/types/reactive/signal.d.ts +9 -6
- package/types/render/hydration.d.ts +1 -1
package/dist/dev.cjs
CHANGED
|
@@ -1415,24 +1415,25 @@ function Match(props) {
|
|
|
1415
1415
|
return props;
|
|
1416
1416
|
}
|
|
1417
1417
|
let Errors;
|
|
1418
|
+
const NoErrors = {};
|
|
1418
1419
|
function resetErrorBoundaries() {
|
|
1419
|
-
Errors && [...Errors].forEach(fn => fn());
|
|
1420
|
+
Errors && [...Errors].forEach(fn => fn(NoErrors));
|
|
1420
1421
|
}
|
|
1421
1422
|
function ErrorBoundary(props) {
|
|
1422
|
-
let err =
|
|
1423
|
+
let err = NoErrors;
|
|
1423
1424
|
if (sharedConfig.context && sharedConfig.load) {
|
|
1424
|
-
err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count);
|
|
1425
|
+
err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count) || NoErrors;
|
|
1425
1426
|
}
|
|
1426
1427
|
const [errored, setErrored] = createSignal(err);
|
|
1427
1428
|
Errors || (Errors = new Set());
|
|
1428
1429
|
Errors.add(setErrored);
|
|
1429
1430
|
onCleanup(() => Errors.delete(setErrored));
|
|
1430
|
-
let e;
|
|
1431
1431
|
return createMemo(() => {
|
|
1432
|
-
|
|
1432
|
+
let e;
|
|
1433
|
+
if ((e = errored()) !== NoErrors) {
|
|
1433
1434
|
const f = props.fallback;
|
|
1434
1435
|
if ((typeof f !== "function" || f.length == 0)) console.error(e);
|
|
1435
|
-
return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored(
|
|
1436
|
+
return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored(NoErrors))) : f;
|
|
1436
1437
|
}
|
|
1437
1438
|
onError(setErrored);
|
|
1438
1439
|
return props.children;
|
package/dist/dev.js
CHANGED
|
@@ -1411,24 +1411,25 @@ function Match(props) {
|
|
|
1411
1411
|
return props;
|
|
1412
1412
|
}
|
|
1413
1413
|
let Errors;
|
|
1414
|
+
const NoErrors = {};
|
|
1414
1415
|
function resetErrorBoundaries() {
|
|
1415
|
-
Errors && [...Errors].forEach(fn => fn());
|
|
1416
|
+
Errors && [...Errors].forEach(fn => fn(NoErrors));
|
|
1416
1417
|
}
|
|
1417
1418
|
function ErrorBoundary(props) {
|
|
1418
|
-
let err =
|
|
1419
|
+
let err = NoErrors;
|
|
1419
1420
|
if (sharedConfig.context && sharedConfig.load) {
|
|
1420
|
-
err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count);
|
|
1421
|
+
err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count) || NoErrors;
|
|
1421
1422
|
}
|
|
1422
1423
|
const [errored, setErrored] = createSignal(err);
|
|
1423
1424
|
Errors || (Errors = new Set());
|
|
1424
1425
|
Errors.add(setErrored);
|
|
1425
1426
|
onCleanup(() => Errors.delete(setErrored));
|
|
1426
|
-
let e;
|
|
1427
1427
|
return createMemo(() => {
|
|
1428
|
-
|
|
1428
|
+
let e;
|
|
1429
|
+
if ((e = errored()) !== NoErrors) {
|
|
1429
1430
|
const f = props.fallback;
|
|
1430
1431
|
if ((typeof f !== "function" || f.length == 0)) console.error(e);
|
|
1431
|
-
return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored(
|
|
1432
|
+
return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored(NoErrors))) : f;
|
|
1432
1433
|
}
|
|
1433
1434
|
onError(setErrored);
|
|
1434
1435
|
return props.children;
|
package/dist/server.cjs
CHANGED
|
@@ -258,8 +258,9 @@ function createComponent(Comp, props) {
|
|
|
258
258
|
function mergeProps(...sources) {
|
|
259
259
|
const target = {};
|
|
260
260
|
for (let i = 0; i < sources.length; i++) {
|
|
261
|
-
|
|
262
|
-
|
|
261
|
+
let source = sources[i];
|
|
262
|
+
if (typeof source === "function") source = source();
|
|
263
|
+
if (source) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
263
264
|
}
|
|
264
265
|
return target;
|
|
265
266
|
}
|
|
@@ -314,14 +315,16 @@ function Switch(props) {
|
|
|
314
315
|
function Match(props) {
|
|
315
316
|
return props;
|
|
316
317
|
}
|
|
318
|
+
const NoErrors = {};
|
|
317
319
|
function resetErrorBoundaries() {}
|
|
318
320
|
function ErrorBoundary(props) {
|
|
319
|
-
let error,
|
|
321
|
+
let error = NoErrors,
|
|
322
|
+
res;
|
|
320
323
|
const ctx = sharedConfig.context;
|
|
321
324
|
const id = ctx.id + ctx.count;
|
|
322
325
|
onError(err => error = err);
|
|
323
326
|
createMemo(() => res = props.children);
|
|
324
|
-
if (error) {
|
|
327
|
+
if (error !== NoErrors) {
|
|
325
328
|
ctx.writeResource(id, error, true);
|
|
326
329
|
setHydrateContext({ ...ctx,
|
|
327
330
|
count: 0
|
|
@@ -360,7 +363,7 @@ function createResource(source, fetcher, options = {}) {
|
|
|
360
363
|
const read = () => {
|
|
361
364
|
if (error) throw error;
|
|
362
365
|
if (resourceContext && p) resourceContext.push(p);
|
|
363
|
-
const resolved = sharedConfig.context.async && sharedConfig.context.resources[id]
|
|
366
|
+
const resolved = sharedConfig.context.async && "data" in sharedConfig.context.resources[id];
|
|
364
367
|
if (!resolved && read.loading) {
|
|
365
368
|
const ctx = useContext(SuspenseContext);
|
|
366
369
|
if (ctx) {
|
|
@@ -380,7 +383,7 @@ function createResource(source, fetcher, options = {}) {
|
|
|
380
383
|
function load() {
|
|
381
384
|
const ctx = sharedConfig.context;
|
|
382
385
|
if (!ctx.async) return read.loading = !!(typeof source === "function" ? source() : source);
|
|
383
|
-
if (ctx.resources && id in ctx.resources && ctx.resources[id]
|
|
386
|
+
if (ctx.resources && id in ctx.resources && "data" in ctx.resources[id]) {
|
|
384
387
|
value = ctx.resources[id].data;
|
|
385
388
|
return;
|
|
386
389
|
}
|
package/dist/server.js
CHANGED
|
@@ -254,8 +254,9 @@ function createComponent(Comp, props) {
|
|
|
254
254
|
function mergeProps(...sources) {
|
|
255
255
|
const target = {};
|
|
256
256
|
for (let i = 0; i < sources.length; i++) {
|
|
257
|
-
|
|
258
|
-
|
|
257
|
+
let source = sources[i];
|
|
258
|
+
if (typeof source === "function") source = source();
|
|
259
|
+
if (source) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
259
260
|
}
|
|
260
261
|
return target;
|
|
261
262
|
}
|
|
@@ -310,14 +311,16 @@ function Switch(props) {
|
|
|
310
311
|
function Match(props) {
|
|
311
312
|
return props;
|
|
312
313
|
}
|
|
314
|
+
const NoErrors = {};
|
|
313
315
|
function resetErrorBoundaries() {}
|
|
314
316
|
function ErrorBoundary(props) {
|
|
315
|
-
let error,
|
|
317
|
+
let error = NoErrors,
|
|
318
|
+
res;
|
|
316
319
|
const ctx = sharedConfig.context;
|
|
317
320
|
const id = ctx.id + ctx.count;
|
|
318
321
|
onError(err => error = err);
|
|
319
322
|
createMemo(() => res = props.children);
|
|
320
|
-
if (error) {
|
|
323
|
+
if (error !== NoErrors) {
|
|
321
324
|
ctx.writeResource(id, error, true);
|
|
322
325
|
setHydrateContext({ ...ctx,
|
|
323
326
|
count: 0
|
|
@@ -356,7 +359,7 @@ function createResource(source, fetcher, options = {}) {
|
|
|
356
359
|
const read = () => {
|
|
357
360
|
if (error) throw error;
|
|
358
361
|
if (resourceContext && p) resourceContext.push(p);
|
|
359
|
-
const resolved = sharedConfig.context.async && sharedConfig.context.resources[id]
|
|
362
|
+
const resolved = sharedConfig.context.async && "data" in sharedConfig.context.resources[id];
|
|
360
363
|
if (!resolved && read.loading) {
|
|
361
364
|
const ctx = useContext(SuspenseContext);
|
|
362
365
|
if (ctx) {
|
|
@@ -376,7 +379,7 @@ function createResource(source, fetcher, options = {}) {
|
|
|
376
379
|
function load() {
|
|
377
380
|
const ctx = sharedConfig.context;
|
|
378
381
|
if (!ctx.async) return read.loading = !!(typeof source === "function" ? source() : source);
|
|
379
|
-
if (ctx.resources && id in ctx.resources && ctx.resources[id]
|
|
382
|
+
if (ctx.resources && id in ctx.resources && "data" in ctx.resources[id]) {
|
|
380
383
|
value = ctx.resources[id].data;
|
|
381
384
|
return;
|
|
382
385
|
}
|
package/dist/solid.cjs
CHANGED
|
@@ -1331,23 +1331,24 @@ function Match(props) {
|
|
|
1331
1331
|
return props;
|
|
1332
1332
|
}
|
|
1333
1333
|
let Errors;
|
|
1334
|
+
const NoErrors = {};
|
|
1334
1335
|
function resetErrorBoundaries() {
|
|
1335
|
-
Errors && [...Errors].forEach(fn => fn());
|
|
1336
|
+
Errors && [...Errors].forEach(fn => fn(NoErrors));
|
|
1336
1337
|
}
|
|
1337
1338
|
function ErrorBoundary(props) {
|
|
1338
|
-
let err =
|
|
1339
|
+
let err = NoErrors;
|
|
1339
1340
|
if (sharedConfig.context && sharedConfig.load) {
|
|
1340
|
-
err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count);
|
|
1341
|
+
err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count) || NoErrors;
|
|
1341
1342
|
}
|
|
1342
1343
|
const [errored, setErrored] = createSignal(err);
|
|
1343
1344
|
Errors || (Errors = new Set());
|
|
1344
1345
|
Errors.add(setErrored);
|
|
1345
1346
|
onCleanup(() => Errors.delete(setErrored));
|
|
1346
|
-
let e;
|
|
1347
1347
|
return createMemo(() => {
|
|
1348
|
-
|
|
1348
|
+
let e;
|
|
1349
|
+
if ((e = errored()) !== NoErrors) {
|
|
1349
1350
|
const f = props.fallback;
|
|
1350
|
-
return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored(
|
|
1351
|
+
return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored(NoErrors))) : f;
|
|
1351
1352
|
}
|
|
1352
1353
|
onError(setErrored);
|
|
1353
1354
|
return props.children;
|
package/dist/solid.js
CHANGED
|
@@ -1327,23 +1327,24 @@ function Match(props) {
|
|
|
1327
1327
|
return props;
|
|
1328
1328
|
}
|
|
1329
1329
|
let Errors;
|
|
1330
|
+
const NoErrors = {};
|
|
1330
1331
|
function resetErrorBoundaries() {
|
|
1331
|
-
Errors && [...Errors].forEach(fn => fn());
|
|
1332
|
+
Errors && [...Errors].forEach(fn => fn(NoErrors));
|
|
1332
1333
|
}
|
|
1333
1334
|
function ErrorBoundary(props) {
|
|
1334
|
-
let err =
|
|
1335
|
+
let err = NoErrors;
|
|
1335
1336
|
if (sharedConfig.context && sharedConfig.load) {
|
|
1336
|
-
err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count);
|
|
1337
|
+
err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count) || NoErrors;
|
|
1337
1338
|
}
|
|
1338
1339
|
const [errored, setErrored] = createSignal(err);
|
|
1339
1340
|
Errors || (Errors = new Set());
|
|
1340
1341
|
Errors.add(setErrored);
|
|
1341
1342
|
onCleanup(() => Errors.delete(setErrored));
|
|
1342
|
-
let e;
|
|
1343
1343
|
return createMemo(() => {
|
|
1344
|
-
|
|
1344
|
+
let e;
|
|
1345
|
+
if ((e = errored()) !== NoErrors) {
|
|
1345
1346
|
const f = props.fallback;
|
|
1346
|
-
return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored(
|
|
1347
|
+
return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored(NoErrors))) : f;
|
|
1347
1348
|
}
|
|
1348
1349
|
onError(setErrored);
|
|
1349
1350
|
return props.children;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solid-js",
|
|
3
3
|
"description": "A declarative JavaScript library for building user interfaces.",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.3",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://solidjs.com",
|
|
@@ -151,5 +151,5 @@
|
|
|
151
151
|
"compiler",
|
|
152
152
|
"performance"
|
|
153
153
|
],
|
|
154
|
-
"gitHead": "
|
|
154
|
+
"gitHead": "44197a3f304400b055baef40da9ac661c0585b85"
|
|
155
155
|
}
|
package/store/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
This submodules contains the means for handling deeps nested reactivity. It provides 2 main primitives `createStore` and `createMutable` which leverage proxies to create dynamic nested reactive structures.
|
|
4
4
|
|
|
5
|
-
This also contains helper methods `produce` and `reconcile` which augment the behavior of the store setter method to allow for localized
|
|
5
|
+
This also contains helper methods `produce` and `reconcile` which augment the behavior of the store setter method to allow for localized mutation and data diffing.
|
|
6
6
|
|
|
7
7
|
For full documentation, check out the [website](https://www.solidjs.com/docs/latest/api).
|
|
8
8
|
|
|
@@ -20,4 +20,4 @@ const [store, setStore] = createStore({
|
|
|
20
20
|
|
|
21
21
|
// update store.user.firstName
|
|
22
22
|
setStore("user", "firstName", "Will");
|
|
23
|
-
```
|
|
23
|
+
```
|
package/store/dist/dev.cjs
CHANGED
|
@@ -143,14 +143,16 @@ function mergeStoreNode(state, value) {
|
|
|
143
143
|
function updateArray(current, next) {
|
|
144
144
|
if (typeof next === "function") next = next(current);
|
|
145
145
|
next = unwrap(next);
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
146
|
+
if (Array.isArray(next)) {
|
|
147
|
+
if (current === next) return;
|
|
148
|
+
let i = 0,
|
|
149
|
+
len = next.length;
|
|
150
|
+
for (; i < len; i++) {
|
|
151
|
+
const value = next[i];
|
|
152
|
+
if (current[i] !== value) setProperty(current, i, value);
|
|
153
|
+
}
|
|
154
|
+
setProperty(current, "length", len);
|
|
155
|
+
} else mergeStoreNode(current, next);
|
|
154
156
|
}
|
|
155
157
|
function updatePath(current, path, traversed = []) {
|
|
156
158
|
let part,
|
|
@@ -373,11 +375,13 @@ function reconcile(value, options = {}) {
|
|
|
373
375
|
return state;
|
|
374
376
|
};
|
|
375
377
|
}
|
|
378
|
+
const producers = new WeakMap();
|
|
376
379
|
const setterTraps = {
|
|
377
380
|
get(target, property) {
|
|
378
381
|
if (property === $RAW) return target;
|
|
379
382
|
const value = target[property];
|
|
380
|
-
|
|
383
|
+
let proxy;
|
|
384
|
+
return isWrappable(value) ? producers.get(value) || (producers.set(value, proxy = new Proxy(value, setterTraps)), proxy) : value;
|
|
381
385
|
},
|
|
382
386
|
set(target, property, value) {
|
|
383
387
|
setProperty(target, property, unwrap(value));
|
|
@@ -390,7 +394,13 @@ const setterTraps = {
|
|
|
390
394
|
};
|
|
391
395
|
function produce(fn) {
|
|
392
396
|
return state => {
|
|
393
|
-
if (isWrappable(state))
|
|
397
|
+
if (isWrappable(state)) {
|
|
398
|
+
let proxy;
|
|
399
|
+
if (!(proxy = producers.get(state))) {
|
|
400
|
+
producers.set(state, proxy = new Proxy(state, setterTraps));
|
|
401
|
+
}
|
|
402
|
+
fn(proxy);
|
|
403
|
+
}
|
|
394
404
|
return state;
|
|
395
405
|
};
|
|
396
406
|
}
|
package/store/dist/dev.js
CHANGED
|
@@ -139,14 +139,16 @@ function mergeStoreNode(state, value) {
|
|
|
139
139
|
function updateArray(current, next) {
|
|
140
140
|
if (typeof next === "function") next = next(current);
|
|
141
141
|
next = unwrap(next);
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
142
|
+
if (Array.isArray(next)) {
|
|
143
|
+
if (current === next) return;
|
|
144
|
+
let i = 0,
|
|
145
|
+
len = next.length;
|
|
146
|
+
for (; i < len; i++) {
|
|
147
|
+
const value = next[i];
|
|
148
|
+
if (current[i] !== value) setProperty(current, i, value);
|
|
149
|
+
}
|
|
150
|
+
setProperty(current, "length", len);
|
|
151
|
+
} else mergeStoreNode(current, next);
|
|
150
152
|
}
|
|
151
153
|
function updatePath(current, path, traversed = []) {
|
|
152
154
|
let part,
|
|
@@ -369,11 +371,13 @@ function reconcile(value, options = {}) {
|
|
|
369
371
|
return state;
|
|
370
372
|
};
|
|
371
373
|
}
|
|
374
|
+
const producers = new WeakMap();
|
|
372
375
|
const setterTraps = {
|
|
373
376
|
get(target, property) {
|
|
374
377
|
if (property === $RAW) return target;
|
|
375
378
|
const value = target[property];
|
|
376
|
-
|
|
379
|
+
let proxy;
|
|
380
|
+
return isWrappable(value) ? producers.get(value) || (producers.set(value, proxy = new Proxy(value, setterTraps)), proxy) : value;
|
|
377
381
|
},
|
|
378
382
|
set(target, property, value) {
|
|
379
383
|
setProperty(target, property, unwrap(value));
|
|
@@ -386,7 +390,13 @@ const setterTraps = {
|
|
|
386
390
|
};
|
|
387
391
|
function produce(fn) {
|
|
388
392
|
return state => {
|
|
389
|
-
if (isWrappable(state))
|
|
393
|
+
if (isWrappable(state)) {
|
|
394
|
+
let proxy;
|
|
395
|
+
if (!(proxy = producers.get(state))) {
|
|
396
|
+
producers.set(state, proxy = new Proxy(state, setterTraps));
|
|
397
|
+
}
|
|
398
|
+
fn(proxy);
|
|
399
|
+
}
|
|
390
400
|
return state;
|
|
391
401
|
};
|
|
392
402
|
}
|
package/store/dist/store.cjs
CHANGED
|
@@ -138,14 +138,16 @@ function mergeStoreNode(state, value) {
|
|
|
138
138
|
function updateArray(current, next) {
|
|
139
139
|
if (typeof next === "function") next = next(current);
|
|
140
140
|
next = unwrap(next);
|
|
141
|
-
if (
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
141
|
+
if (Array.isArray(next)) {
|
|
142
|
+
if (current === next) return;
|
|
143
|
+
let i = 0,
|
|
144
|
+
len = next.length;
|
|
145
|
+
for (; i < len; i++) {
|
|
146
|
+
const value = next[i];
|
|
147
|
+
if (current[i] !== value) setProperty(current, i, value);
|
|
148
|
+
}
|
|
149
|
+
setProperty(current, "length", len);
|
|
150
|
+
} else mergeStoreNode(current, next);
|
|
149
151
|
}
|
|
150
152
|
function updatePath(current, path, traversed = []) {
|
|
151
153
|
let part,
|
|
@@ -351,11 +353,13 @@ function reconcile(value, options = {}) {
|
|
|
351
353
|
return state;
|
|
352
354
|
};
|
|
353
355
|
}
|
|
356
|
+
const producers = new WeakMap();
|
|
354
357
|
const setterTraps = {
|
|
355
358
|
get(target, property) {
|
|
356
359
|
if (property === $RAW) return target;
|
|
357
360
|
const value = target[property];
|
|
358
|
-
|
|
361
|
+
let proxy;
|
|
362
|
+
return isWrappable(value) ? producers.get(value) || (producers.set(value, proxy = new Proxy(value, setterTraps)), proxy) : value;
|
|
359
363
|
},
|
|
360
364
|
set(target, property, value) {
|
|
361
365
|
setProperty(target, property, unwrap(value));
|
|
@@ -368,7 +372,13 @@ const setterTraps = {
|
|
|
368
372
|
};
|
|
369
373
|
function produce(fn) {
|
|
370
374
|
return state => {
|
|
371
|
-
if (isWrappable(state))
|
|
375
|
+
if (isWrappable(state)) {
|
|
376
|
+
let proxy;
|
|
377
|
+
if (!(proxy = producers.get(state))) {
|
|
378
|
+
producers.set(state, proxy = new Proxy(state, setterTraps));
|
|
379
|
+
}
|
|
380
|
+
fn(proxy);
|
|
381
|
+
}
|
|
372
382
|
return state;
|
|
373
383
|
};
|
|
374
384
|
}
|
package/store/dist/store.js
CHANGED
|
@@ -134,14 +134,16 @@ function mergeStoreNode(state, value) {
|
|
|
134
134
|
function updateArray(current, next) {
|
|
135
135
|
if (typeof next === "function") next = next(current);
|
|
136
136
|
next = unwrap(next);
|
|
137
|
-
if (
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
137
|
+
if (Array.isArray(next)) {
|
|
138
|
+
if (current === next) return;
|
|
139
|
+
let i = 0,
|
|
140
|
+
len = next.length;
|
|
141
|
+
for (; i < len; i++) {
|
|
142
|
+
const value = next[i];
|
|
143
|
+
if (current[i] !== value) setProperty(current, i, value);
|
|
144
|
+
}
|
|
145
|
+
setProperty(current, "length", len);
|
|
146
|
+
} else mergeStoreNode(current, next);
|
|
145
147
|
}
|
|
146
148
|
function updatePath(current, path, traversed = []) {
|
|
147
149
|
let part,
|
|
@@ -347,11 +349,13 @@ function reconcile(value, options = {}) {
|
|
|
347
349
|
return state;
|
|
348
350
|
};
|
|
349
351
|
}
|
|
352
|
+
const producers = new WeakMap();
|
|
350
353
|
const setterTraps = {
|
|
351
354
|
get(target, property) {
|
|
352
355
|
if (property === $RAW) return target;
|
|
353
356
|
const value = target[property];
|
|
354
|
-
|
|
357
|
+
let proxy;
|
|
358
|
+
return isWrappable(value) ? producers.get(value) || (producers.set(value, proxy = new Proxy(value, setterTraps)), proxy) : value;
|
|
355
359
|
},
|
|
356
360
|
set(target, property, value) {
|
|
357
361
|
setProperty(target, property, unwrap(value));
|
|
@@ -364,7 +368,13 @@ const setterTraps = {
|
|
|
364
368
|
};
|
|
365
369
|
function produce(fn) {
|
|
366
370
|
return state => {
|
|
367
|
-
if (isWrappable(state))
|
|
371
|
+
if (isWrappable(state)) {
|
|
372
|
+
let proxy;
|
|
373
|
+
if (!(proxy = producers.get(state))) {
|
|
374
|
+
producers.set(state, proxy = new Proxy(state, setterTraps));
|
|
375
|
+
}
|
|
376
|
+
fn(proxy);
|
|
377
|
+
}
|
|
368
378
|
return state;
|
|
369
379
|
};
|
|
370
380
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { DeepMutable } from "./store";
|
|
2
1
|
export declare type ReconcileOptions = {
|
|
3
2
|
key?: string | null;
|
|
4
3
|
merge?: boolean;
|
|
5
4
|
};
|
|
6
5
|
export declare function reconcile<T extends U, U>(value: T, options?: ReconcileOptions): (state: U) => T;
|
|
7
|
-
export declare function produce<T>(fn: (state:
|
|
6
|
+
export declare function produce<T>(fn: (state: T) => void): (state: T) => T;
|
package/store/types/server.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SetStoreFunction, Store } from "store";
|
|
2
2
|
export declare const $RAW: unique symbol;
|
|
3
3
|
export declare function isWrappable(obj: any): boolean;
|
|
4
|
-
export declare function unwrap<T>(item:
|
|
4
|
+
export declare function unwrap<T>(item: T): T;
|
|
5
5
|
export declare function setProperty(state: any, property: PropertyKey, value: any, force?: boolean): void;
|
|
6
6
|
export declare function updatePath(current: any, path: any[], traversed?: PropertyKey[]): void;
|
|
7
7
|
export declare function createStore<T>(state: T | Store<T>): [Store<T>, SetStoreFunction<T>];
|
|
@@ -11,5 +11,5 @@ declare type ReconcileOptions = {
|
|
|
11
11
|
merge?: boolean;
|
|
12
12
|
};
|
|
13
13
|
export declare function reconcile<T extends U, U>(value: T, options?: ReconcileOptions): (state: U) => T;
|
|
14
|
-
export declare function produce<T>(fn: (state:
|
|
14
|
+
export declare function produce<T>(fn: (state: T) => void): (state: T) => T;
|
|
15
15
|
export {};
|
package/store/types/store.d.ts
CHANGED
|
@@ -5,9 +5,9 @@ export declare namespace SolidStore {
|
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
7
|
export declare type NotWrappable = string | number | bigint | symbol | boolean | Function | null | undefined | SolidStore.Unwrappable[keyof SolidStore.Unwrappable];
|
|
8
|
-
export declare type Store<T> =
|
|
9
|
-
export declare function isWrappable(obj:
|
|
10
|
-
export declare function unwrap<T
|
|
8
|
+
export declare type Store<T> = T;
|
|
9
|
+
export declare function isWrappable<T>(obj: T | NotWrappable): obj is T;
|
|
10
|
+
export declare function unwrap<T>(item: T, set?: Set<unknown>): T;
|
|
11
11
|
export declare function getDataNodes(target: StoreNode): any;
|
|
12
12
|
export declare function getDataNode(nodes: Record<string, any>, property: string | symbol, value: any): any;
|
|
13
13
|
export declare function proxyDescriptor(target: StoreNode, property: PropertyKey): PropertyDescriptor | undefined;
|
|
@@ -15,19 +15,26 @@ export declare function trackSelf(target: StoreNode): void;
|
|
|
15
15
|
export declare function ownKeys(target: StoreNode): (string | symbol)[];
|
|
16
16
|
export declare function setProperty(state: StoreNode, property: PropertyKey, value: any): void;
|
|
17
17
|
export declare function updatePath(current: StoreNode, path: any[], traversed?: PropertyKey[]): void;
|
|
18
|
+
/** @deprecated */
|
|
18
19
|
export declare type DeepReadonly<T> = 0 extends 1 & T ? T : T extends NotWrappable ? T : {
|
|
19
20
|
readonly [K in keyof T]: DeepReadonly<T[K]>;
|
|
20
21
|
};
|
|
22
|
+
/** @deprecated */
|
|
21
23
|
export declare type DeepMutable<T> = 0 extends 1 & T ? T : T extends NotWrappable ? T : {
|
|
22
24
|
-readonly [K in keyof T]: DeepMutable<T[K]>;
|
|
23
25
|
};
|
|
26
|
+
export declare type CustomPartial<T> = T extends readonly unknown[] ? "0" extends keyof T ? {
|
|
27
|
+
[K in Extract<keyof T, `${number}`>]?: T[K];
|
|
28
|
+
} : {
|
|
29
|
+
[x: number]: T[number];
|
|
30
|
+
} : Partial<T>;
|
|
24
31
|
export declare type StorePathRange = {
|
|
25
32
|
from?: number;
|
|
26
33
|
to?: number;
|
|
27
34
|
by?: number;
|
|
28
35
|
};
|
|
29
|
-
export declare type ArrayFilterFn<T> = (item:
|
|
30
|
-
export declare type StoreSetter<T, U extends PropertyKey[] = []> = ((prevState:
|
|
36
|
+
export declare type ArrayFilterFn<T> = (item: T, index: number) => boolean;
|
|
37
|
+
export declare type StoreSetter<T, U extends PropertyKey[] = []> = ((prevState: T, traversed: U) => T | CustomPartial<T> | void) | T | CustomPartial<T>;
|
|
31
38
|
export declare type Part<T, K extends KeyOf<T> = KeyOf<T>> = [K] extends [never] ? never : K | readonly K[] | ([T] extends [readonly unknown[]] ? ArrayFilterFn<T[number]> | StorePathRange : never);
|
|
32
39
|
declare type W<T> = Exclude<T, NotWrappable>;
|
|
33
40
|
declare type KeyOf<T> = number extends keyof T ? 0 extends 1 & T ? keyof T : [T] extends [readonly unknown[]] ? number : [T] extends [never] ? never : keyof T : keyof T;
|
|
@@ -200,13 +200,12 @@ export declare function createMemo<Next extends Prev, Init = Next, Prev = Next>(
|
|
|
200
200
|
export interface Resource<T> extends Accessor<T> {
|
|
201
201
|
loading: boolean;
|
|
202
202
|
error: any;
|
|
203
|
-
latest: T
|
|
203
|
+
latest: T;
|
|
204
204
|
}
|
|
205
205
|
export declare type ResourceActions<T> = {
|
|
206
206
|
mutate: Setter<T>;
|
|
207
207
|
refetch: (info?: unknown) => T | Promise<T> | undefined | null;
|
|
208
208
|
};
|
|
209
|
-
export declare type ResourceReturn<T> = [Resource<T>, ResourceActions<T>];
|
|
210
209
|
export declare type ResourceSource<S> = S | false | null | undefined | (() => S | false | null | undefined);
|
|
211
210
|
export declare type ResourceFetcher<S, T> = (k: S, info: ResourceFetcherInfo<T>) => T | Promise<T>;
|
|
212
211
|
export declare type ResourceFetcherInfo<T> = {
|
|
@@ -224,6 +223,10 @@ export declare type ResourceOptions<T> = undefined extends T ? {
|
|
|
224
223
|
deferStream?: boolean;
|
|
225
224
|
onHydrated?: <S, T>(k: S, info: ResourceFetcherInfo<T>) => void;
|
|
226
225
|
};
|
|
226
|
+
export declare type ResourceReturn<T, O extends ResourceOptions<T | undefined> | undefined, K = T> = [
|
|
227
|
+
Resource<O extends undefined | null ? T | undefined : NonNullable<O>["initialValue"] extends undefined ? T | undefined : T>,
|
|
228
|
+
ResourceActions<K>
|
|
229
|
+
];
|
|
227
230
|
/**
|
|
228
231
|
* Creates a resource that wraps a repeated promise in a reactive pattern:
|
|
229
232
|
* ```typescript
|
|
@@ -249,10 +252,10 @@ export declare type ResourceOptions<T> = undefined extends T ? {
|
|
|
249
252
|
*
|
|
250
253
|
* @description https://www.solidjs.com/docs/latest/api#createresource
|
|
251
254
|
*/
|
|
252
|
-
export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): ResourceReturn<T | undefined>;
|
|
253
|
-
export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T>;
|
|
254
|
-
export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): ResourceReturn<T | undefined>;
|
|
255
|
-
export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T>;
|
|
255
|
+
export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): ResourceReturn<T | undefined, typeof options>;
|
|
256
|
+
export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T, typeof options>;
|
|
257
|
+
export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): ResourceReturn<T | undefined, typeof options>;
|
|
258
|
+
export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T, typeof options>;
|
|
256
259
|
export interface DeferredOptions<T> {
|
|
257
260
|
equals?: false | ((prev: T, next: T) => boolean);
|
|
258
261
|
name?: string;
|
|
@@ -7,7 +7,7 @@ declare type SharedConfig = {
|
|
|
7
7
|
resources?: {
|
|
8
8
|
[key: string]: any;
|
|
9
9
|
};
|
|
10
|
-
load?: (id: string) => Promise<any> | undefined;
|
|
10
|
+
load?: (id: string) => Promise<any> | any | undefined;
|
|
11
11
|
gather?: (key: string) => void;
|
|
12
12
|
registry?: Map<string, Element>;
|
|
13
13
|
done?: boolean;
|