@solidjs/router 0.10.0-beta.2 → 0.10.0-beta.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/data/action.d.ts +2 -1
- package/dist/data/cache.js +30 -31
- package/dist/data/index.d.ts +1 -1
- package/dist/data/index.js +1 -1
- package/dist/index.js +30 -25
- package/package.json +4 -4
package/dist/data/action.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { JSX } from "solid-js";
|
|
1
2
|
import { Submission } from "../types";
|
|
2
|
-
export type Action<T, U> = (vars: T) => Promise<U
|
|
3
|
+
export type Action<T, U> = ((vars: T) => Promise<U>) & JSX.SerializableAttributeValue;
|
|
3
4
|
export declare function useSubmissions<T, U>(fn: Action<T, U>, filter?: (arg: T) => boolean): Submission<T, U>[] & {
|
|
4
5
|
pending: boolean;
|
|
5
6
|
};
|
package/dist/data/cache.js
CHANGED
|
@@ -50,13 +50,11 @@ export function cache(fn, name, options) {
|
|
|
50
50
|
version && cached[3].add(version);
|
|
51
51
|
if (cached[2] === "preload" && intent !== "preload") {
|
|
52
52
|
cached[0] = now;
|
|
53
|
-
cached[1] =
|
|
54
|
-
"then" in cached[1]
|
|
55
|
-
? cached[1].then(handleResponse, handleResponse)
|
|
56
|
-
: handleResponse(cached[1]);
|
|
57
|
-
cached[2] = intent;
|
|
58
53
|
}
|
|
59
54
|
if (!isServer && intent === "navigate") {
|
|
55
|
+
"then" in cached[1]
|
|
56
|
+
? cached[1].then(handleResponse(false), handleResponse(true))
|
|
57
|
+
: handleResponse(false)(cached[1]);
|
|
60
58
|
startTransition(() => revalidateSignals(cached[3], cached[0])); // update version
|
|
61
59
|
}
|
|
62
60
|
return cached[1];
|
|
@@ -69,10 +67,9 @@ export function cache(fn, name, options) {
|
|
|
69
67
|
sharedConfig.context && sharedConfig.context.serialize(key, res);
|
|
70
68
|
}
|
|
71
69
|
if (intent !== "preload") {
|
|
72
|
-
res
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
: handleResponse(res);
|
|
70
|
+
"then" in res
|
|
71
|
+
? res.then(handleResponse(false), handleResponse(true))
|
|
72
|
+
: handleResponse(false)(res);
|
|
76
73
|
}
|
|
77
74
|
if (cached) {
|
|
78
75
|
cached[0] = now;
|
|
@@ -86,29 +83,31 @@ export function cache(fn, name, options) {
|
|
|
86
83
|
else
|
|
87
84
|
cache.set(key, (cached = [now, res, intent, new Set(version ? [version] : [])]));
|
|
88
85
|
return res;
|
|
89
|
-
function handleResponse(
|
|
90
|
-
|
|
91
|
-
if (
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
86
|
+
function handleResponse(error) {
|
|
87
|
+
return (v) => {
|
|
88
|
+
if (v instanceof Response && redirectStatusCodes.has(v.status)) {
|
|
89
|
+
if (navigate) {
|
|
90
|
+
startTransition(() => {
|
|
91
|
+
let url = v.headers.get(LocationHeader);
|
|
92
|
+
if (url && url.startsWith("/")) {
|
|
93
|
+
navigate(url, {
|
|
94
|
+
replace: true
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
else if (!isServer && url) {
|
|
98
|
+
window.location.href = url;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return;
|
|
103
103
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return
|
|
110
|
-
|
|
111
|
-
return store[key];
|
|
104
|
+
if (error)
|
|
105
|
+
throw error;
|
|
106
|
+
if (isServer)
|
|
107
|
+
return v;
|
|
108
|
+
setStore(key, reconcile(v, options));
|
|
109
|
+
return store[key];
|
|
110
|
+
};
|
|
112
111
|
}
|
|
113
112
|
});
|
|
114
113
|
}
|
package/dist/data/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { createAsync } from "./createAsync";
|
|
2
|
-
export { action, useSubmission, useSubmissions } from "./action";
|
|
2
|
+
export { action, useSubmission, useSubmissions, useAction } from "./action";
|
|
3
3
|
export { cache, revalidate } from "./cache";
|
|
4
4
|
export { redirect } from "./response";
|
package/dist/data/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { createAsync } from "./createAsync";
|
|
2
|
-
export { action, useSubmission, useSubmissions } from "./action";
|
|
2
|
+
export { action, useSubmission, useSubmissions, useAction } from "./action";
|
|
3
3
|
export { cache, revalidate } from "./cache";
|
|
4
4
|
export { redirect } from "./response";
|
package/dist/index.js
CHANGED
|
@@ -847,7 +847,7 @@ function createRouteContext(router, parent, outlet, match, params) {
|
|
|
847
847
|
return route;
|
|
848
848
|
}
|
|
849
849
|
|
|
850
|
-
const _tmpl$ = /*#__PURE__*/template(`<a
|
|
850
|
+
const _tmpl$ = /*#__PURE__*/template(`<a>`);
|
|
851
851
|
const Router = props => {
|
|
852
852
|
let e;
|
|
853
853
|
const {
|
|
@@ -970,7 +970,7 @@ function A(props) {
|
|
|
970
970
|
return props.end ? path === loc : loc.startsWith(path);
|
|
971
971
|
});
|
|
972
972
|
return (() => {
|
|
973
|
-
const _el$ = _tmpl
|
|
973
|
+
const _el$ = _tmpl$();
|
|
974
974
|
spread(_el$, mergeProps$1(rest, {
|
|
975
975
|
get href() {
|
|
976
976
|
return href() || props.href;
|
|
@@ -1112,10 +1112,9 @@ function cache(fn, name, options) {
|
|
|
1112
1112
|
version && cached[3].add(version);
|
|
1113
1113
|
if (cached[2] === "preload" && intent !== "preload") {
|
|
1114
1114
|
cached[0] = now;
|
|
1115
|
-
cached[1] = "then" in cached[1] ? cached[1].then(handleResponse, handleResponse) : handleResponse(cached[1]);
|
|
1116
|
-
cached[2] = intent;
|
|
1117
1115
|
}
|
|
1118
1116
|
if (!isServer && intent === "navigate") {
|
|
1117
|
+
"then" in cached[1] ? cached[1].then(handleResponse(false), handleResponse(true)) : handleResponse(false)(cached[1]);
|
|
1119
1118
|
startTransition(() => revalidateSignals(cached[3], cached[0])); // update version
|
|
1120
1119
|
}
|
|
1121
1120
|
|
|
@@ -1129,7 +1128,7 @@ function cache(fn, name, options) {
|
|
|
1129
1128
|
sharedConfig.context && sharedConfig.context.serialize(key, res);
|
|
1130
1129
|
}
|
|
1131
1130
|
if (intent !== "preload") {
|
|
1132
|
-
|
|
1131
|
+
"then" in res ? res.then(handleResponse(false), handleResponse(true)) : handleResponse(false)(res);
|
|
1133
1132
|
}
|
|
1134
1133
|
if (cached) {
|
|
1135
1134
|
cached[0] = now;
|
|
@@ -1141,26 +1140,28 @@ function cache(fn, name, options) {
|
|
|
1141
1140
|
}
|
|
1142
1141
|
} else cache.set(key, cached = [now, res, intent, new Set(version ? [version] : [])]);
|
|
1143
1142
|
return res;
|
|
1144
|
-
function handleResponse(
|
|
1145
|
-
|
|
1146
|
-
if (
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1143
|
+
function handleResponse(error) {
|
|
1144
|
+
return v => {
|
|
1145
|
+
if (v instanceof Response && redirectStatusCodes.has(v.status)) {
|
|
1146
|
+
if (navigate) {
|
|
1147
|
+
startTransition(() => {
|
|
1148
|
+
let url = v.headers.get(LocationHeader);
|
|
1149
|
+
if (url && url.startsWith("/")) {
|
|
1150
|
+
navigate(url, {
|
|
1151
|
+
replace: true
|
|
1152
|
+
});
|
|
1153
|
+
} else if (!isServer && url) {
|
|
1154
|
+
window.location.href = url;
|
|
1155
|
+
}
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
return;
|
|
1157
1159
|
}
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
return store[key];
|
|
1160
|
+
if (error) throw error;
|
|
1161
|
+
if (isServer) return v;
|
|
1162
|
+
setStore(key, reconcile(v, options));
|
|
1163
|
+
return store[key];
|
|
1164
|
+
};
|
|
1164
1165
|
}
|
|
1165
1166
|
};
|
|
1166
1167
|
}
|
|
@@ -1199,6 +1200,10 @@ function useSubmission(fn, filter) {
|
|
|
1199
1200
|
}
|
|
1200
1201
|
};
|
|
1201
1202
|
}
|
|
1203
|
+
function useAction(action) {
|
|
1204
|
+
const router = useRouter();
|
|
1205
|
+
return action.bind(router);
|
|
1206
|
+
}
|
|
1202
1207
|
function action(fn, name) {
|
|
1203
1208
|
function mutate(variables) {
|
|
1204
1209
|
const p = fn(variables);
|
|
@@ -1275,4 +1280,4 @@ function redirect(url, init = 302) {
|
|
|
1275
1280
|
return response;
|
|
1276
1281
|
}
|
|
1277
1282
|
|
|
1278
|
-
export { A, A as Link, A as NavLink, Navigate, Route, Router, mergeSearchString as _mergeSearchString, action, cache, createAsync, createBeforeLeave, createIntegration, createMemoryHistory, hashIntegration, memoryIntegration, normalizeIntegration, pathIntegration, redirect, revalidate, staticIntegration, useBeforeLeave, useHref, useIsRouting, useLocation, useMatch, useNavigate, useParams, useResolvedPath, useSearchParams, useSubmission, useSubmissions };
|
|
1283
|
+
export { A, A as Link, A as NavLink, Navigate, Route, Router, mergeSearchString as _mergeSearchString, action, cache, createAsync, createBeforeLeave, createIntegration, createMemoryHistory, hashIntegration, memoryIntegration, normalizeIntegration, pathIntegration, redirect, revalidate, staticIntegration, useAction, useBeforeLeave, useHref, useIsRouting, useLocation, useMatch, useNavigate, useParams, useResolvedPath, useSearchParams, useSubmission, useSubmissions };
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"Ryan Turnquist"
|
|
7
7
|
],
|
|
8
8
|
"license": "MIT",
|
|
9
|
-
"version": "0.10.0-beta.
|
|
9
|
+
"version": "0.10.0-beta.3",
|
|
10
10
|
"homepage": "https://github.com/solidjs/solid-router#readme",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
@@ -37,17 +37,17 @@
|
|
|
37
37
|
"@types/jest": "^29.0.0",
|
|
38
38
|
"@types/node": "^20.9.0",
|
|
39
39
|
"babel-jest": "^29.0.1",
|
|
40
|
-
"babel-preset-solid": "^1.
|
|
40
|
+
"babel-preset-solid": "^1.8.6",
|
|
41
41
|
"jest": "^29.0.1",
|
|
42
42
|
"jest-environment-jsdom": "^29.2.1",
|
|
43
43
|
"prettier": "^2.7.1",
|
|
44
44
|
"rollup": "^3.7.5",
|
|
45
45
|
"solid-jest": "^0.2.0",
|
|
46
|
-
"solid-js": "^1.8.
|
|
46
|
+
"solid-js": "^1.8.6",
|
|
47
47
|
"typescript": "^5.2.2"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"solid-js": "^1.8.
|
|
50
|
+
"solid-js": "^1.8.6"
|
|
51
51
|
},
|
|
52
52
|
"jest": {
|
|
53
53
|
"preset": "solid-jest/preset/browser"
|