@typed/router 0.5.1 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typed/router",
3
- "version": "0.5.1",
3
+ "version": "0.5.6",
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.10.3",
23
23
  "@effect/io": "^0.17.0",
24
- "@typed/context": "0.5.1",
25
- "@typed/dom": "8.5.1",
26
- "@typed/fx": "1.5.1",
27
- "@typed/html": "3.5.1",
28
- "@typed/path": "0.1.0",
29
- "@typed/route": "0.4.0"
24
+ "@typed/context": "^0.5.5",
25
+ "@typed/dom": "^8.5.5",
26
+ "@typed/fx": "^1.5.5",
27
+ "@typed/html": "^3.5.5",
28
+ "@typed/path": "^0.1.2",
29
+ "@typed/route": "^0.4.2"
30
30
  },
31
- "gitHead": "eb7de6339939cb3cad08520f2b1d179d333d10ca",
31
+ "gitHead": "1087e5682c3fb0cf3ded66e7a84ed8306fb6339d",
32
32
  "publishConfig": {
33
33
  "access": "public"
34
34
  },
@@ -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' ? Fx.skipRepeats : Fx.take(1),
190
+ environment === 'browser' ? identity : Fx.take(1),
192
191
  Fx.switchMapEffect((path) =>
193
192
  Effect.gen(function* ($) {
194
- yield* $(Effect.logDebug(`[@typed/router] Matching path: ${path}`))
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(path))
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