@typed/router 0.5.5 → 0.5.6
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.d.ts.map +1 -1
- package/dist/RouteMatcher.js +12 -6
- package/dist/RouteMatcher.js.map +1 -1
- package/dist/cjs/RouteMatcher.d.ts.map +1 -1
- package/dist/cjs/RouteMatcher.js +11 -5
- package/dist/cjs/RouteMatcher.js.map +1 -1
- package/dist/tsconfig.cjs.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/RouteMatcher.ts +16 -7
- package/tsconfig.build.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typed/router",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@typed/path": "^0.1.2",
|
|
29
29
|
"@typed/route": "^0.4.2"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "1087e5682c3fb0cf3ded66e7a84ed8306fb6339d",
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
package/src/RouteMatcher.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
|
-
import { pipe } from '@effect/data/Function'
|
|
2
|
+
import { identity, pipe } from '@effect/data/Function'
|
|
3
3
|
import * as Option from '@effect/data/Option'
|
|
4
4
|
import * as Cause from '@effect/io/Cause'
|
|
5
5
|
import * as Effect from '@effect/io/Effect'
|
|
@@ -116,8 +116,7 @@ export function RouteMatcher<R, E>(routes: RouteMatcher<R, E>['routes']): RouteM
|
|
|
116
116
|
const { environment } = yield* $(RenderContext)
|
|
117
117
|
// Create stable references to the route matchers
|
|
118
118
|
const matchers = Array.from(routes.values()).map(
|
|
119
|
-
(v) =>
|
|
120
|
-
[{ ...v, route: router.route.concat(v.route) }, runRouteMatch(router, v)] as const,
|
|
119
|
+
(v) => [v, runRouteMatch(router, v)] as const,
|
|
121
120
|
)
|
|
122
121
|
|
|
123
122
|
const renderFallback = Fx.switchMap(f)(router.currentPath)
|
|
@@ -188,16 +187,26 @@ export function RouteMatcher<R, E>(routes: RouteMatcher<R, E>['routes']): RouteM
|
|
|
188
187
|
|
|
189
188
|
return pipe(
|
|
190
189
|
router.currentPath,
|
|
191
|
-
environment === 'browser' ?
|
|
190
|
+
environment === 'browser' ? identity : Fx.take(1),
|
|
192
191
|
Fx.switchMapEffect((path) =>
|
|
193
192
|
Effect.gen(function* ($) {
|
|
194
|
-
yield* $(
|
|
193
|
+
const currentParams = yield* $(router.route.match(path))
|
|
194
|
+
|
|
195
|
+
if (Option.isNone(currentParams)) {
|
|
196
|
+
return Option.none()
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const matchedPath: string = router.route.make(currentParams.value)
|
|
200
|
+
const currentPath =
|
|
201
|
+
matchedPath === '/' ? path : path.replace(matchedPath, '') || '/'
|
|
202
|
+
|
|
203
|
+
yield* $(Effect.logDebug(`[@typed/router] Matching path: ${currentPath}`))
|
|
195
204
|
|
|
196
205
|
// Attempt to find the best match
|
|
197
206
|
for (const [match, render] of matchers) {
|
|
198
207
|
yield* $(Effect.logDebug(`[@typed/router] Matching against: ${match.route.path}`))
|
|
199
208
|
|
|
200
|
-
const result = yield* $(match.route.match(
|
|
209
|
+
const result = yield* $(match.route.match(currentPath))
|
|
201
210
|
|
|
202
211
|
if (Option.isSome(result)) {
|
|
203
212
|
yield* $(
|
|
@@ -250,8 +259,8 @@ function runRouteMatch<R, E, P extends string>(
|
|
|
250
259
|
const params = pipe(nestedRouter.params, Fx.provideContext(env))
|
|
251
260
|
const render = pipe(
|
|
252
261
|
match(params as unknown as Fx.Fx<never, never, Path.ParamsOf<P>>),
|
|
253
|
-
Fx.provideContext(env),
|
|
254
262
|
Router.provideFx(nestedRouter as Router),
|
|
263
|
+
Fx.provideContext(env),
|
|
255
264
|
)
|
|
256
265
|
|
|
257
266
|
return render
|