@typed/router 0.5.10 → 0.6.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/dist/RouteMatch.js +1 -1
- package/dist/RouteMatch.js.map +1 -1
- package/dist/RouteMatcher.d.ts.map +1 -1
- package/dist/RouteMatcher.js +4 -4
- package/dist/RouteMatcher.js.map +1 -1
- package/dist/cjs/RouteMatch.js +1 -1
- package/dist/cjs/RouteMatch.js.map +1 -1
- package/dist/cjs/RouteMatcher.d.ts.map +1 -1
- package/dist/cjs/RouteMatcher.js +4 -4
- package/dist/cjs/RouteMatcher.js.map +1 -1
- package/dist/cjs/router.d.ts +6 -6
- package/dist/cjs/router.d.ts.map +1 -1
- package/dist/cjs/router.js +6 -6
- package/dist/cjs/router.js.map +1 -1
- package/dist/router.d.ts +6 -6
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +6 -6
- package/dist/router.js.map +1 -1
- package/dist/tsconfig.cjs.build.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/src/RouteMatch.ts +2 -2
- package/src/RouteMatcher.ts +4 -6
- package/src/router.ts +26 -21
- package/tsconfig.build.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typed/router",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
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.
|
|
25
|
-
"@typed/dom": "^8.
|
|
26
|
-
"@typed/fx": "^1.
|
|
27
|
-
"@typed/html": "^3.
|
|
24
|
+
"@typed/context": "^0.6.0",
|
|
25
|
+
"@typed/dom": "^8.6.0",
|
|
26
|
+
"@typed/fx": "^1.6.0",
|
|
27
|
+
"@typed/html": "^3.6.0",
|
|
28
28
|
"@typed/path": "^0.1.2",
|
|
29
29
|
"@typed/route": "^0.4.2"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "7207e1edf7a2ba3fbfe7c502d3360d715fa612d2",
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
package/src/RouteMatch.ts
CHANGED
|
@@ -41,8 +41,8 @@ export function RouteMatch<R, E, P extends string, R2, E2, R3, E3>(
|
|
|
41
41
|
provideService: (tag, service) =>
|
|
42
42
|
RouteMatch(
|
|
43
43
|
Route.provideService(tag, service)(route),
|
|
44
|
-
flow(match, Fx.provideService(tag
|
|
45
|
-
layout ? Fx.provideService(tag
|
|
44
|
+
flow(match, Fx.provideService(tag, service)),
|
|
45
|
+
layout ? Fx.provideService(tag, service)(layout) : undefined,
|
|
46
46
|
),
|
|
47
47
|
provideSomeLayer: (layer) =>
|
|
48
48
|
RouteMatch(
|
package/src/RouteMatcher.ts
CHANGED
|
@@ -200,24 +200,22 @@ export function RouteMatcher<R, E>(routes: RouteMatcher<R, E>['routes']): RouteM
|
|
|
200
200
|
const currentPath =
|
|
201
201
|
matchedPath === '/' ? path : path.replace(matchedPath, '') || '/'
|
|
202
202
|
|
|
203
|
-
yield* $(Effect.
|
|
203
|
+
yield* $(Effect.logInfo(`[@typed/router] Matching path: ${currentPath}`))
|
|
204
204
|
|
|
205
205
|
// Attempt to find the best match
|
|
206
206
|
for (const [match, render] of matchers) {
|
|
207
|
-
yield* $(Effect.
|
|
207
|
+
yield* $(Effect.logInfo(`[@typed/router] Matching against: ${match.route.path}`))
|
|
208
208
|
|
|
209
209
|
const result = yield* $(match.route.match(currentPath))
|
|
210
210
|
|
|
211
211
|
if (Option.isSome(result)) {
|
|
212
|
-
yield* $(
|
|
213
|
-
Effect.logDebug(`[@typed/router] Matched against: ${match.route.path}`),
|
|
214
|
-
)
|
|
212
|
+
yield* $(Effect.logInfo(`[@typed/router] Matched against: ${match.route.path}`))
|
|
215
213
|
|
|
216
214
|
return yield* $(verifyShouldRerender(render, match.layout))
|
|
217
215
|
}
|
|
218
216
|
}
|
|
219
217
|
|
|
220
|
-
yield* $(Effect.
|
|
218
|
+
yield* $(Effect.logInfo(`[@typed/router] Rendering fallback`))
|
|
221
219
|
|
|
222
220
|
// If we didn't find a match, render the not found page
|
|
223
221
|
return yield* $(verifyShouldRerender(renderFallback, options.layout))
|
package/src/router.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface Router<out R = never, out E = never, in out P extends string =
|
|
|
22
22
|
/**
|
|
23
23
|
* The current path of the application
|
|
24
24
|
*/
|
|
25
|
-
readonly currentPath: Fx.RefSubject<string>
|
|
25
|
+
readonly currentPath: Fx.RefSubject<never, string>
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* The current matched params of the router
|
|
@@ -32,7 +32,7 @@ export interface Router<out R = never, out E = never, in out P extends string =
|
|
|
32
32
|
/**
|
|
33
33
|
* The current outlet of this Router
|
|
34
34
|
*/
|
|
35
|
-
readonly outlet: Fx.RefSubject<html.Renderable>
|
|
35
|
+
readonly outlet: Fx.RefSubject<Redirect, html.Renderable>
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Helper for constructing a path from a route relative to the router.
|
|
@@ -69,10 +69,12 @@ export interface Router<out R = never, out E = never, in out P extends string =
|
|
|
69
69
|
export const Router = Object.assign(Context.Tag<Router>('@typed/router/Router'), {
|
|
70
70
|
make: function makeRouter<R = never, E = never, P extends string = string>(
|
|
71
71
|
route: Route.Route<R, E, P>,
|
|
72
|
-
currentPath: Fx.RefSubject<string>,
|
|
72
|
+
currentPath: Fx.RefSubject<never, string>,
|
|
73
73
|
parent: Option.Option<Router<any, any, string>> = Option.none(),
|
|
74
74
|
): Router<R, E, P> {
|
|
75
|
-
const outlet = Fx.RefSubject.unsafeMake
|
|
75
|
+
const outlet = Fx.RefSubject.unsafeMake<Redirect, html.Renderable>(
|
|
76
|
+
Effect.sync((): html.Renderable => null),
|
|
77
|
+
)
|
|
76
78
|
|
|
77
79
|
const createPath = <R2 extends Route.Route<any, any, string>, P extends Route.ParamsOf<R2>>(
|
|
78
80
|
other: R2,
|
|
@@ -121,8 +123,8 @@ export const Router = Object.assign(Context.Tag<Router>('@typed/router/Router'),
|
|
|
121
123
|
},
|
|
122
124
|
})
|
|
123
125
|
|
|
124
|
-
export const outlet: Fx.Fx<RenderContext | Router,
|
|
125
|
-
({ environment }) =>
|
|
126
|
+
export const outlet: Fx.Fx<RenderContext | Router, Redirect, html.Renderable> =
|
|
127
|
+
RenderContext.withFx(({ environment }) =>
|
|
126
128
|
Router.withFx((r) =>
|
|
127
129
|
environment === 'browser'
|
|
128
130
|
? r.outlet
|
|
@@ -132,7 +134,7 @@ export const outlet: Fx.Fx<RenderContext | Router, never, html.Renderable> = Ren
|
|
|
132
134
|
Fx.take(1),
|
|
133
135
|
),
|
|
134
136
|
),
|
|
135
|
-
)
|
|
137
|
+
)
|
|
136
138
|
|
|
137
139
|
export const currentPath: Fx.Fx<Router, never, string> = Router.withFx((r) => r.currentPath)
|
|
138
140
|
|
|
@@ -194,14 +196,16 @@ redirectTo.fx = <R, E, P extends string>(
|
|
|
194
196
|
// TOOD: Add support for reading <base> tag for default Router path.
|
|
195
197
|
|
|
196
198
|
export const makeRouter = (
|
|
197
|
-
currentPath?: Fx.RefSubject<string>,
|
|
199
|
+
currentPath?: Fx.RefSubject<never, string>,
|
|
198
200
|
): Effect.Effect<Location | History | Window | Document | Scope.Scope, never, Router> =>
|
|
199
201
|
Effect.gen(function* ($) {
|
|
200
202
|
const history = yield* $(History)
|
|
201
203
|
const location = yield* $(Location)
|
|
202
204
|
|
|
203
205
|
if (!currentPath) {
|
|
204
|
-
currentPath = Fx.RefSubject.unsafeMake(
|
|
206
|
+
currentPath = Fx.RefSubject.unsafeMake(
|
|
207
|
+
Effect.sync(() => getCurrentPathFromLocation(location)),
|
|
208
|
+
)
|
|
205
209
|
}
|
|
206
210
|
|
|
207
211
|
// Patch history events to emit an event when the path changes
|
|
@@ -212,12 +216,11 @@ export const makeRouter = (
|
|
|
212
216
|
// - hashchange
|
|
213
217
|
// - history events
|
|
214
218
|
yield* $(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
),
|
|
219
|
+
Fx.mergeAll(addWindowListener('popstate'), addWindowListener('hashchange'), historyEvents),
|
|
220
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
221
|
+
Fx.switchMapEffect(() => currentPath!.set(getCurrentPathFromLocation(location))),
|
|
222
|
+
Fx.drain,
|
|
223
|
+
Effect.forkScoped,
|
|
221
224
|
)
|
|
222
225
|
|
|
223
226
|
// Listen to path changes and update the current history location, if necessary
|
|
@@ -225,11 +228,13 @@ export const makeRouter = (
|
|
|
225
228
|
pipe(
|
|
226
229
|
currentPath,
|
|
227
230
|
Fx.skipRepeats,
|
|
228
|
-
Fx.
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
231
|
+
Fx.observe((path) =>
|
|
232
|
+
Effect.sync(() => {
|
|
233
|
+
if (path !== getCurrentPathFromLocation(location)) {
|
|
234
|
+
history.pushState({}, '', path)
|
|
235
|
+
}
|
|
236
|
+
}),
|
|
237
|
+
),
|
|
233
238
|
Effect.forkScoped,
|
|
234
239
|
),
|
|
235
240
|
)
|
|
@@ -244,7 +249,7 @@ export const makeRouter = (
|
|
|
244
249
|
})
|
|
245
250
|
|
|
246
251
|
export const live = (
|
|
247
|
-
currentPath?: Fx.RefSubject<string>,
|
|
252
|
+
currentPath?: Fx.RefSubject<never, string>,
|
|
248
253
|
): Layer.Layer<Location | History | Window | Document, never, Router<never, never, string>> =>
|
|
249
254
|
Router.layerScoped(makeRouter(currentPath))
|
|
250
255
|
|