@typed/router 0.4.0 → 0.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typed/router",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -19,16 +19,16 @@
19
19
  }
20
20
  },
21
21
  "dependencies": {
22
- "@effect/data": "^0.7.4",
23
- "@effect/io": "^0.15.1",
24
- "@typed/context": "0.4.0",
25
- "@typed/dom": "8.4.0",
26
- "@typed/fx": "1.4.0",
27
- "@typed/html": "3.4.0",
22
+ "@effect/data": "^0.10.3",
23
+ "@effect/io": "^0.17.0",
24
+ "@typed/context": "0.5.0",
25
+ "@typed/dom": "8.5.0",
26
+ "@typed/fx": "1.5.0",
27
+ "@typed/html": "3.5.0",
28
28
  "@typed/path": "0.1.0",
29
- "@typed/route": "0.3.0"
29
+ "@typed/route": "0.4.0"
30
30
  },
31
- "gitHead": "2a6519605c0d9842989f18647b430d00bd5af14d",
31
+ "gitHead": "ac7e2b801557a7aa8b4d33de39021fd220a2f9e8",
32
32
  "publishConfig": {
33
33
  "access": "public"
34
34
  },
@@ -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(function makeRouter<
70
- R = never,
71
- E = never,
72
- P extends string = string,
73
- >(
74
- route: Route.Route<R, E, P>,
75
- currentPath: Fx.RefSubject<string>,
76
- parent: Option.Option<Router<any, any, string>> = Option.none(),
77
- ): Router<R, E, P> {
78
- const outlet = Fx.RefSubject.unsafeMake((): html.Renderable => null)
79
-
80
- const createPath = <R2 extends Route.Route<any, any, string>, P extends Route.ParamsOf<R2>>(
81
- other: R2,
82
- ...[params]: [keyof P] extends [never] ? [] : [P]
83
- ): Effect.Effect<
84
- R,
85
- E,
86
- Path.PathJoin<
87
- [Path.Interpolate<Route.PathOf<R>, Route.ParamsOf<R>>, Path.Interpolate<Route.PathOf<R2>, P>]
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.
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
- 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
- }
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
- return router
121
- },
122
- Context.Tag<Router>('@typed/router/Router'))
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 = (