@typed/router 0.4.0 → 0.4.1
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/RouteMatcher.js +1 -1
- package/dist/RouteMatcher.js.map +1 -1
- package/dist/cjs/RouteMatcher.js +1 -1
- package/dist/cjs/RouteMatcher.js.map +1 -1
- package/dist/cjs/router.d.ts +3 -1
- package/dist/cjs/router.d.ts.map +1 -1
- package/dist/cjs/router.js +25 -23
- package/dist/cjs/router.js.map +1 -1
- package/dist/router.d.ts +3 -1
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +25 -23
- package/dist/router.js.map +1 -1
- package/dist/tsconfig.cjs.build.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/src/RouteMatcher.ts +1 -0
- package/src/router.ts +51 -51
- package/tsconfig.build.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typed/router",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@effect/data": "^0.7.4",
|
|
23
23
|
"@effect/io": "^0.15.1",
|
|
24
|
-
"@typed/context": "0.4.
|
|
25
|
-
"@typed/dom": "8.4.
|
|
26
|
-
"@typed/fx": "1.4.
|
|
27
|
-
"@typed/html": "3.4.
|
|
24
|
+
"@typed/context": "0.4.1",
|
|
25
|
+
"@typed/dom": "8.4.1",
|
|
26
|
+
"@typed/fx": "1.4.1",
|
|
27
|
+
"@typed/html": "3.4.1",
|
|
28
28
|
"@typed/path": "0.1.0",
|
|
29
29
|
"@typed/route": "0.3.0"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "045d1a1cbd6ebed153f24f946b14fd2c638fdb4c",
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
package/src/RouteMatcher.ts
CHANGED
|
@@ -250,6 +250,7 @@ function runRouteMatch<R, E, P extends string>(
|
|
|
250
250
|
const params = pipe(nestedRouter.params, Fx.provideContext(env))
|
|
251
251
|
const render = pipe(
|
|
252
252
|
match(params as unknown as Fx.Fx<never, never, Path.ParamsOf<P>>),
|
|
253
|
+
Fx.provideContext(env),
|
|
253
254
|
Router.provideFx(nestedRouter as Router),
|
|
254
255
|
)
|
|
255
256
|
|
package/src/router.ts
CHANGED
|
@@ -66,60 +66,60 @@ export interface Router<out R = never, out E = never, in out P extends string =
|
|
|
66
66
|
readonly provideContext: (environment: Context.Context<R>) => Router<never, E, P>
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
export const Router = Object.assign(
|
|
70
|
-
R = never,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
69
|
+
export const Router = Object.assign(Context.Tag<Router>('@typed/router/Router'), {
|
|
70
|
+
make: function makeRouter<R = never, E = never, P extends string = string>(
|
|
71
|
+
route: Route.Route<R, E, P>,
|
|
72
|
+
currentPath: Fx.RefSubject<string>,
|
|
73
|
+
parent: Option.Option<Router<any, any, string>> = Option.none(),
|
|
74
|
+
): Router<R, E, P> {
|
|
75
|
+
const outlet = Fx.RefSubject.unsafeMake((): html.Renderable => null)
|
|
76
|
+
|
|
77
|
+
const createPath = <R2 extends Route.Route<any, any, string>, P extends Route.ParamsOf<R2>>(
|
|
78
|
+
other: R2,
|
|
79
|
+
...[params]: [keyof P] extends [never] ? [] : [P]
|
|
80
|
+
): Effect.Effect<
|
|
81
|
+
R,
|
|
82
|
+
E,
|
|
83
|
+
Path.PathJoin<
|
|
84
|
+
[
|
|
85
|
+
Path.Interpolate<Route.PathOf<R>, Route.ParamsOf<R>>,
|
|
86
|
+
Path.Interpolate<Route.PathOf<R2>, P>,
|
|
87
|
+
]
|
|
88
|
+
>
|
|
89
|
+
> =>
|
|
90
|
+
Effect.gen(function* ($) {
|
|
91
|
+
const path = yield* $(currentPath.get)
|
|
92
|
+
const baseParams = yield* $(route.match(path))
|
|
93
|
+
|
|
94
|
+
if (Option.isNone(baseParams)) {
|
|
95
|
+
return yield* $(
|
|
96
|
+
Effect.dieMessage(
|
|
97
|
+
`Can not create path when the parent can not be matched.
|
|
98
98
|
Parent Route: ${route.path}
|
|
99
99
|
Current Route: ${other.path}
|
|
100
100
|
Current Path: ${path}`,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
101
|
+
),
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return route.concat(other).make({ ...baseParams.value, ...params } as any) as any
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
const router: Router<R, E, P> = {
|
|
109
|
+
route,
|
|
110
|
+
currentPath,
|
|
111
|
+
params: pipe(currentPath, Fx.switchMapEffect(route.match), Fx.compact, Fx.skipRepeats),
|
|
112
|
+
outlet,
|
|
113
|
+
createPath: createPath as Router<R, P>['createPath'],
|
|
114
|
+
define: <R2, E2, Path2 extends string>(other: Route.Route<R2, E2, Path2>) =>
|
|
115
|
+
makeRouter(route.concat(other), currentPath, Option.some(router as any)) as any,
|
|
116
|
+
provideContext: (env) => provideContext(env)(router),
|
|
117
|
+
parent,
|
|
118
|
+
}
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
},
|
|
122
|
-
|
|
120
|
+
return router
|
|
121
|
+
},
|
|
122
|
+
})
|
|
123
123
|
|
|
124
124
|
export const outlet: Fx.Fx<RenderContext | Router, never, html.Renderable> = RenderContext.withFx(
|
|
125
125
|
({ environment }) =>
|
|
@@ -240,7 +240,7 @@ export const makeRouter = (
|
|
|
240
240
|
const baseHref = base ? getBasePathFromHref(base.href) : '/'
|
|
241
241
|
|
|
242
242
|
// Make our base router
|
|
243
|
-
return Router(Route.Route(baseHref), currentPath) as Router
|
|
243
|
+
return Router.make(Route.Route(baseHref), currentPath) as Router
|
|
244
244
|
})
|
|
245
245
|
|
|
246
246
|
export const live = (
|