@solidjs/router 0.16.0 → 0.17.0-next.0
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/README.md +85 -79
- package/dist/components.jsx +22 -16
- package/dist/data/action.d.ts +12 -10
- package/dist/data/action.js +98 -78
- package/dist/data/events.d.ts +8 -1
- package/dist/data/events.js +3 -3
- package/dist/data/index.d.ts +2 -3
- package/dist/data/index.js +2 -3
- package/dist/data/query.d.ts +1 -3
- package/dist/data/query.js +10 -16
- package/dist/index.d.ts +2 -2
- package/dist/index.js +212 -261
- package/dist/index.jsx +1 -1
- package/dist/lifecycle.js +1 -1
- package/dist/routers/HashRouter.js +1 -1
- package/dist/routers/MemoryRouter.js +1 -1
- package/dist/routers/Router.js +2 -2
- package/dist/routers/StaticRouter.js +1 -1
- package/dist/routers/components.d.ts +0 -4
- package/dist/routers/components.jsx +30 -19
- package/dist/routing.d.ts +4 -3
- package/dist/routing.js +71 -49
- package/dist/types.d.ts +3 -18
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +8 -0
- package/package.json +8 -6
- package/dist/data/createAsync.d.ts +0 -32
- package/dist/data/createAsync.js +0 -93
- package/dist/src/components.d.ts +0 -31
- package/dist/src/components.jsx +0 -39
- package/dist/src/data/action.d.ts +0 -17
- package/dist/src/data/action.js +0 -163
- package/dist/src/data/action.spec.d.ts +0 -1
- package/dist/src/data/action.spec.js +0 -297
- package/dist/src/data/createAsync.d.ts +0 -32
- package/dist/src/data/createAsync.js +0 -96
- package/dist/src/data/createAsync.spec.d.ts +0 -1
- package/dist/src/data/createAsync.spec.js +0 -196
- package/dist/src/data/events.d.ts +0 -9
- package/dist/src/data/events.js +0 -123
- package/dist/src/data/events.spec.d.ts +0 -1
- package/dist/src/data/events.spec.js +0 -567
- package/dist/src/data/index.d.ts +0 -4
- package/dist/src/data/index.js +0 -4
- package/dist/src/data/query.d.ts +0 -23
- package/dist/src/data/query.js +0 -232
- package/dist/src/data/query.spec.d.ts +0 -1
- package/dist/src/data/query.spec.js +0 -354
- package/dist/src/data/response.d.ts +0 -4
- package/dist/src/data/response.js +0 -42
- package/dist/src/data/response.spec.d.ts +0 -1
- package/dist/src/data/response.spec.js +0 -165
- package/dist/src/index.d.ts +0 -7
- package/dist/src/index.jsx +0 -6
- package/dist/src/lifecycle.d.ts +0 -5
- package/dist/src/lifecycle.js +0 -69
- package/dist/src/routers/HashRouter.d.ts +0 -9
- package/dist/src/routers/HashRouter.js +0 -41
- package/dist/src/routers/MemoryRouter.d.ts +0 -24
- package/dist/src/routers/MemoryRouter.js +0 -57
- package/dist/src/routers/Router.d.ts +0 -9
- package/dist/src/routers/Router.js +0 -45
- package/dist/src/routers/StaticRouter.d.ts +0 -6
- package/dist/src/routers/StaticRouter.js +0 -15
- package/dist/src/routers/components.d.ts +0 -27
- package/dist/src/routers/components.jsx +0 -118
- package/dist/src/routers/createRouter.d.ts +0 -10
- package/dist/src/routers/createRouter.js +0 -41
- package/dist/src/routers/index.d.ts +0 -11
- package/dist/src/routers/index.js +0 -6
- package/dist/src/routing.d.ts +0 -175
- package/dist/src/routing.js +0 -560
- package/dist/src/types.d.ts +0 -200
- package/dist/src/types.js +0 -1
- package/dist/src/utils.d.ts +0 -13
- package/dist/src/utils.js +0 -185
- package/dist/test/helpers.d.ts +0 -6
- package/dist/test/helpers.js +0 -50
package/dist/data/events.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { delegateEvents } from "
|
|
1
|
+
import { delegateEvents } from "@solidjs/web";
|
|
2
2
|
import { onCleanup } from "solid-js";
|
|
3
3
|
import { actions } from "./action.js";
|
|
4
4
|
import { mockBase } from "../utils.js";
|
|
5
|
-
export function setupNativeEvents(preload = true, explicitLinks = false, actionBase = "/_server", transformUrl) {
|
|
5
|
+
export function setupNativeEvents({ preload = true, explicitLinks = false, actionBase = "/_server", transformUrl } = {}) {
|
|
6
6
|
return (router) => {
|
|
7
7
|
const basePath = router.base.path();
|
|
8
8
|
const navigateFromRoute = router.navigatorFactory(router.base);
|
|
@@ -65,7 +65,7 @@ export function setupNativeEvents(preload = true, explicitLinks = false, actionB
|
|
|
65
65
|
clearTimeout(preloadTimeout);
|
|
66
66
|
const res = handleAnchor(evt);
|
|
67
67
|
if (!res)
|
|
68
|
-
return lastElement = null;
|
|
68
|
+
return (lastElement = null);
|
|
69
69
|
const [a, url] = res;
|
|
70
70
|
if (lastElement === a)
|
|
71
71
|
return;
|
package/dist/data/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export { query, revalidate, cache, type CachedFunction } from "./query.js";
|
|
1
|
+
export { action, useSubmissions, useAction, type Action } from "./action.js";
|
|
2
|
+
export { query, revalidate, type CachedFunction } from "./query.js";
|
|
4
3
|
export { redirect, reload, json } from "./response.js";
|
package/dist/data/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export { query, revalidate, cache } from "./query.js";
|
|
1
|
+
export { action, useSubmissions, useAction } from "./action.js";
|
|
2
|
+
export { query, revalidate } from "./query.js";
|
|
4
3
|
export { redirect, reload, json } from "./response.js";
|
package/dist/data/query.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { CacheEntry, NarrowResponse } from "../types.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Revalidates the given cache entry/entries.
|
|
4
4
|
*/
|
|
5
|
-
export declare function revalidate(key?: string | string[] | void, force?: boolean):
|
|
5
|
+
export declare function revalidate(key?: string | string[] | void, force?: boolean): void;
|
|
6
6
|
export declare function cacheKeyOp(key: string | string[] | void, fn: (cacheEntry: CacheEntry) => void): void;
|
|
7
7
|
export type CachedFunction<T extends (...args: any) => any> = T extends (...args: infer A) => infer R ? ([] extends {
|
|
8
8
|
[K in keyof A]-?: A[K];
|
|
@@ -18,6 +18,4 @@ export declare namespace query {
|
|
|
18
18
|
export var clear: () => void;
|
|
19
19
|
export { _a as delete };
|
|
20
20
|
}
|
|
21
|
-
/** @deprecated use query instead */
|
|
22
|
-
export declare const cache: typeof query;
|
|
23
21
|
export declare function hashKey<T extends Array<any>>(args: T): string;
|
package/dist/data/query.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createSignal,
|
|
2
|
-
import { getRequestEvent, isServer } from "
|
|
1
|
+
import { createSignal, getObserver, getOwner, onCleanup, sharedConfig } from "solid-js";
|
|
2
|
+
import { getRequestEvent, isServer } from "@solidjs/web";
|
|
3
3
|
import { useNavigate, getIntent, getInPreloadFn } from "../routing.js";
|
|
4
4
|
const LocationHeader = "Location";
|
|
5
5
|
const PRELOAD_TIMEOUT = 5000;
|
|
@@ -28,12 +28,10 @@ function getCache() {
|
|
|
28
28
|
* Revalidates the given cache entry/entries.
|
|
29
29
|
*/
|
|
30
30
|
export function revalidate(key, force = true) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
entry[4][1](now); // retrigger live signals
|
|
36
|
-
});
|
|
31
|
+
const now = Date.now();
|
|
32
|
+
cacheKeyOp(key, entry => {
|
|
33
|
+
force && (entry[0] = 0); //force cache miss
|
|
34
|
+
entry[4][1](now); // retrigger live signals
|
|
37
35
|
});
|
|
38
36
|
}
|
|
39
37
|
export function cacheKeyOp(key, fn) {
|
|
@@ -72,7 +70,7 @@ export function query(fn, name) {
|
|
|
72
70
|
}
|
|
73
71
|
}
|
|
74
72
|
}
|
|
75
|
-
if (
|
|
73
|
+
if (getObserver() && !isServer) {
|
|
76
74
|
tracking = true;
|
|
77
75
|
onCleanup(() => cached[4].count--);
|
|
78
76
|
}
|
|
@@ -95,7 +93,7 @@ export function query(fn, name) {
|
|
|
95
93
|
"then" in cached[1]
|
|
96
94
|
? cached[1].then(handleResponse(false), handleResponse(true))
|
|
97
95
|
: handleResponse(false)(cached[1]);
|
|
98
|
-
!isServer && intent === "navigate" &&
|
|
96
|
+
!isServer && intent === "navigate" && cached[4][1](cached[0]); // update version
|
|
99
97
|
}
|
|
100
98
|
inPreloadFn && "then" in res && res.catch(() => { });
|
|
101
99
|
return res;
|
|
@@ -112,7 +110,7 @@ export function query(fn, name) {
|
|
|
112
110
|
cached[0] = now;
|
|
113
111
|
cached[1] = res;
|
|
114
112
|
cached[3] = intent;
|
|
115
|
-
!isServer && intent === "navigate" &&
|
|
113
|
+
!isServer && intent === "navigate" && cached[4][1](cached[0]); // update version
|
|
116
114
|
}
|
|
117
115
|
else {
|
|
118
116
|
cache.set(key, (cached = [now, res, , intent, createSignal(now)]));
|
|
@@ -159,9 +157,7 @@ export function query(fn, name) {
|
|
|
159
157
|
if (url !== null) {
|
|
160
158
|
// client + server relative redirect
|
|
161
159
|
if (navigate && url.startsWith("/"))
|
|
162
|
-
|
|
163
|
-
navigate(url, { replace: true });
|
|
164
|
-
});
|
|
160
|
+
navigate(url, { replace: true });
|
|
165
161
|
else if (!isServer)
|
|
166
162
|
window.location.href = url;
|
|
167
163
|
else if (e)
|
|
@@ -203,8 +199,6 @@ query.set = (key, value) => {
|
|
|
203
199
|
};
|
|
204
200
|
query.delete = (key) => getCache().delete(key);
|
|
205
201
|
query.clear = () => getCache().clear();
|
|
206
|
-
/** @deprecated use query instead */
|
|
207
|
-
export const cache = query;
|
|
208
202
|
function matchKey(key, keys) {
|
|
209
203
|
for (let k of keys) {
|
|
210
204
|
if (k && key.startsWith(k))
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from "./routers/index.js";
|
|
2
2
|
export * from "./components.jsx";
|
|
3
3
|
export * from "./lifecycle.js";
|
|
4
|
-
export { useHref, useIsRouting, useLocation, useMatch, useCurrentMatches, useNavigate, useParams, useResolvedPath, useSearchParams, useBeforeLeave, usePreloadRoute } from "./routing.js";
|
|
4
|
+
export { useHref, useIsRouting, useLocation, useMatch, useCurrentMatches, useNavigate, useParams, useResolvedPath, useSearchParams, useBeforeLeave, usePreloadRoute, RouterContextObj as RouterContext } from "./routing.js";
|
|
5
5
|
export { mergeSearchString as _mergeSearchString } from "./utils.js";
|
|
6
6
|
export * from "./data/index.js";
|
|
7
|
-
export type { Location, LocationChange, SearchParams, MatchFilter, MatchFilters, NavigateOptions, Navigator, OutputMatch, Params, PathMatch, RouteSectionProps, RoutePreloadFunc, RoutePreloadFuncArgs, RouteDefinition, RouteDescription, RouteMatch, RouterIntegration, RouterUtils, SetParams, Submission, BeforeLeaveEventArgs,
|
|
7
|
+
export type { Location, LocationChange, SearchParams, MatchFilter, MatchFilters, NavigateOptions, Navigator, OutputMatch, Params, PathMatch, RouteSectionProps, RoutePreloadFunc, RoutePreloadFuncArgs, RouteDefinition, RouteDescription, RouteMatch, RouterIntegration, RouterUtils, SetParams, Submission, BeforeLeaveEventArgs, RouterResponseInit, CustomResponse } from "./types.js";
|