@typed/router 0.2.1 → 0.4.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.2.1",
3
+ "version": "0.4.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.2.0",
23
- "@effect/io": "^0.3.0",
24
- "@typed/context": "0.2.1",
25
- "@typed/dom": "8.2.1",
26
- "@typed/fx": "1.2.1",
27
- "@typed/html": "3.2.1",
28
- "@typed/path": "0.0.8",
29
- "@typed/route": "0.1.1"
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",
28
+ "@typed/path": "0.1.0",
29
+ "@typed/route": "0.3.0"
30
30
  },
31
- "gitHead": "08436346feac1b2e5d91ac88d4610780027d89b8",
31
+ "gitHead": "2a6519605c0d9842989f18647b430d00bd5af14d",
32
32
  "publishConfig": {
33
33
  "access": "public"
34
34
  },
package/src/Link.ts CHANGED
@@ -12,7 +12,7 @@ export function Link<R = never, E = never, R2 = never>(
12
12
  return Fx.gen(function* ($) {
13
13
  const useBase = props.useBase ?? true
14
14
  const href = useBase ? pathJoin(yield* $(getBasePath), props.href) || '/' : props.href
15
- const router = yield* $(Router.get)
15
+ const router = yield* $(Router)
16
16
  const clickHandler = (event: MouseEvent & { currentTarget: HTMLAnchorElement }) =>
17
17
  Effect.gen(function* ($) {
18
18
  if (props.fullReload) {
@@ -112,7 +112,7 @@ export function RouteMatcher<R, E>(routes: RouteMatcher<R, E>['routes']): RouteM
112
112
  ) =>
113
113
  Router.withFx((router) =>
114
114
  Fx.gen(function* ($) {
115
- const { environment } = yield* $(RenderContext.get)
115
+ const { environment } = yield* $(RenderContext)
116
116
  // Create stable references to the route matchers
117
117
  const matchers = Array.from(routes.values()).map(
118
118
  (v) =>
@@ -138,7 +138,7 @@ export function RouteMatcher<R, E>(routes: RouteMatcher<R, E>['routes']): RouteM
138
138
  layout?: Fx.Fx<any, any, html.Renderable>,
139
139
  ): Effect.Effect<any, any, Option.Option<Fx.Fx<any, any, html.Renderable>>> =>
140
140
  Effect.gen(function* ($) {
141
- const { outlet } = yield* $(Router.get)
141
+ const { outlet } = yield* $(Router)
142
142
  const previous = samplePreviousValues()
143
143
 
144
144
  // Update the previous values
package/src/router.ts CHANGED
@@ -197,8 +197,8 @@ export const makeRouter = (
197
197
  currentPath?: Fx.RefSubject<string>,
198
198
  ): Effect.Effect<Location | History | Window | Document | Scope.Scope, never, Router> =>
199
199
  Effect.gen(function* ($) {
200
- const history = yield* $(History.get)
201
- const location = yield* $(Location.get)
200
+ const history = yield* $(History)
201
+ const location = yield* $(Location)
202
202
 
203
203
  if (!currentPath) {
204
204
  currentPath = Fx.RefSubject.unsafeMake(() => getCurrentPathFromLocation(location))
@@ -225,19 +225,17 @@ export const makeRouter = (
225
225
  pipe(
226
226
  currentPath,
227
227
  Fx.skipRepeats,
228
- Fx.observe((path) =>
229
- Effect.sync(() => {
230
- if (path !== getCurrentPathFromLocation(location)) {
231
- history.pushState({}, '', path)
232
- }
233
- }),
234
- ),
228
+ Fx.observeSync((path) => {
229
+ if (path !== getCurrentPathFromLocation(location)) {
230
+ history.pushState({}, '', path)
231
+ }
232
+ }),
235
233
  Effect.forkScoped,
236
234
  ),
237
235
  )
238
236
 
239
237
  // Find the configured base path
240
- const document = yield* $(Document.get)
238
+ const document = yield* $(Document)
241
239
  const base = document.querySelector('base')
242
240
  const baseHref = base ? getBasePathFromHref(base.href) : '/'
243
241
 
@@ -269,10 +267,11 @@ export const getBasePath = Router.with((r) => {
269
267
  })
270
268
 
271
269
  const patchHistory = Effect.gen(function* ($) {
272
- const history = yield* $(History.get)
270
+ const history = yield* $(History)
273
271
  const historyEvents = Fx.Subject.unsafeMake<never, void>()
274
272
  const runtime = yield* $(Effect.runtime<never>())
275
- const cleanup = patchHistory_(history, () => Runtime.runFork(runtime)(historyEvents.event()))
273
+ const runFork = Runtime.runFork(runtime)
274
+ const cleanup = patchHistory_(history, () => runFork(historyEvents.event()))
276
275
 
277
276
  // unpatch history upon finalization
278
277
  yield* $(Effect.addFinalizer(() => Effect.sync(cleanup)))