@typed/navigation 0.10.3 → 0.12.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/cjs/Layer.js.map +1 -1
- package/dist/cjs/internal/fromWindow.js.map +1 -1
- package/dist/cjs/internal/memory.js.map +1 -1
- package/dist/cjs/internal/shared.js.map +1 -1
- package/dist/dts/Blocking.d.ts +7 -7
- package/dist/dts/Blocking.d.ts.map +1 -1
- package/dist/dts/Layer.d.ts +4 -4
- package/dist/dts/Layer.d.ts.map +1 -1
- package/dist/dts/Navigation.d.ts +117 -117
- package/dist/dts/Navigation.d.ts.map +1 -1
- package/dist/dts/internal/fromWindow.d.ts +1 -1
- package/dist/dts/internal/fromWindow.d.ts.map +1 -1
- package/dist/dts/internal/memory.d.ts +2 -2
- package/dist/dts/internal/memory.d.ts.map +1 -1
- package/dist/dts/internal/shared.d.ts +60 -60
- package/dist/dts/internal/shared.d.ts.map +1 -1
- package/dist/esm/Layer.js.map +1 -1
- package/dist/esm/internal/fromWindow.js.map +1 -1
- package/dist/esm/internal/memory.js.map +1 -1
- package/dist/esm/internal/shared.js.map +1 -1
- package/package.json +8 -8
- package/src/Blocking.ts +9 -9
- package/src/Layer.ts +4 -5
- package/src/Navigation.ts +42 -42
- package/src/internal/fromWindow.ts +9 -21
- package/src/internal/memory.ts +3 -7
- package/src/internal/shared.ts +21 -39
package/src/Navigation.ts
CHANGED
|
@@ -22,58 +22,58 @@ export interface Navigation {
|
|
|
22
22
|
|
|
23
23
|
readonly base: string
|
|
24
24
|
|
|
25
|
-
readonly currentEntry: RefSubject.Computed<
|
|
25
|
+
readonly currentEntry: RefSubject.Computed<Destination>
|
|
26
26
|
|
|
27
|
-
readonly entries: RefSubject.Computed<
|
|
27
|
+
readonly entries: RefSubject.Computed<ReadonlyArray<Destination>>
|
|
28
28
|
|
|
29
|
-
readonly transition: RefSubject.Computed<
|
|
29
|
+
readonly transition: RefSubject.Computed<Option.Option<Transition>>
|
|
30
30
|
|
|
31
|
-
readonly canGoBack: RefSubject.Computed<
|
|
31
|
+
readonly canGoBack: RefSubject.Computed<boolean>
|
|
32
32
|
|
|
33
|
-
readonly canGoForward: RefSubject.Computed<
|
|
33
|
+
readonly canGoForward: RefSubject.Computed<boolean>
|
|
34
34
|
|
|
35
35
|
readonly navigate: (
|
|
36
36
|
url: string | URL,
|
|
37
37
|
options?: NavigateOptions
|
|
38
|
-
) => Effect.Effect<
|
|
38
|
+
) => Effect.Effect<Destination, NavigationError>
|
|
39
39
|
|
|
40
|
-
readonly back: (options?: { readonly info?: unknown }) => Effect.Effect<
|
|
40
|
+
readonly back: (options?: { readonly info?: unknown }) => Effect.Effect<Destination, NavigationError>
|
|
41
41
|
|
|
42
|
-
readonly forward: (options?: { readonly info?: unknown }) => Effect.Effect<
|
|
42
|
+
readonly forward: (options?: { readonly info?: unknown }) => Effect.Effect<Destination, NavigationError>
|
|
43
43
|
|
|
44
44
|
readonly traverseTo: (
|
|
45
45
|
key: Destination["key"],
|
|
46
46
|
options?: { readonly info?: unknown }
|
|
47
|
-
) => Effect.Effect<
|
|
47
|
+
) => Effect.Effect<Destination, NavigationError>
|
|
48
48
|
|
|
49
49
|
readonly updateCurrentEntry: (
|
|
50
50
|
options: { readonly state: unknown }
|
|
51
|
-
) => Effect.Effect<
|
|
51
|
+
) => Effect.Effect<Destination, NavigationError>
|
|
52
52
|
|
|
53
53
|
readonly reload: (
|
|
54
54
|
options?: { readonly info?: unknown; readonly state?: unknown }
|
|
55
|
-
) => Effect.Effect<
|
|
55
|
+
) => Effect.Effect<Destination, NavigationError>
|
|
56
56
|
|
|
57
57
|
readonly beforeNavigation: <R = never, R2 = never>(
|
|
58
58
|
handler: BeforeNavigationHandler<R, R2>
|
|
59
|
-
) => Effect.Effect<R | R2 | Scope.Scope
|
|
59
|
+
) => Effect.Effect<void, never, R | R2 | Scope.Scope>
|
|
60
60
|
|
|
61
61
|
readonly onNavigation: <R = never, R2 = never>(
|
|
62
62
|
handler: NavigationHandler<R, R2>
|
|
63
|
-
) => Effect.Effect<R | R2 | Scope.Scope
|
|
63
|
+
) => Effect.Effect<void, never, R | R2 | Scope.Scope>
|
|
64
64
|
|
|
65
65
|
readonly submit: (
|
|
66
66
|
data: FormData,
|
|
67
67
|
formInput?: Simplify<Omit<FormInputFrom, "data">>
|
|
68
68
|
) => Effect.Effect<
|
|
69
|
-
HttpClient.
|
|
69
|
+
Option.Option<HttpClient.response.ClientResponse>,
|
|
70
70
|
NavigationError | HttpClient.error.HttpClientError,
|
|
71
|
-
|
|
71
|
+
Scope.Scope | HttpClient.client.Client.Default
|
|
72
72
|
>
|
|
73
73
|
|
|
74
74
|
readonly onFormData: <R = never, R2 = never>(
|
|
75
75
|
handler: FormDataHandler<R, R2>
|
|
76
|
-
) => Effect.Effect<R | R2 | Scope.Scope
|
|
76
|
+
) => Effect.Effect<void, never, R | R2 | Scope.Scope>
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
/**
|
|
@@ -203,11 +203,11 @@ export interface NavigationEvent extends Schema.Schema.To<typeof NavigationEvent
|
|
|
203
203
|
export type BeforeNavigationHandler<R, R2> = (
|
|
204
204
|
event: BeforeNavigationEvent
|
|
205
205
|
) => Effect.Effect<
|
|
206
|
-
R,
|
|
207
|
-
RedirectError | CancelNavigation,
|
|
208
206
|
Option.Option<
|
|
209
|
-
Effect.Effect<
|
|
210
|
-
|
|
207
|
+
Effect.Effect<unknown, RedirectError | CancelNavigation, R2>
|
|
208
|
+
>,
|
|
209
|
+
RedirectError | CancelNavigation,
|
|
210
|
+
R
|
|
211
211
|
>
|
|
212
212
|
|
|
213
213
|
/**
|
|
@@ -216,11 +216,11 @@ export type BeforeNavigationHandler<R, R2> = (
|
|
|
216
216
|
export type NavigationHandler<R, R2> = (
|
|
217
217
|
event: NavigationEvent
|
|
218
218
|
) => Effect.Effect<
|
|
219
|
-
R,
|
|
220
|
-
never,
|
|
221
219
|
Option.Option<
|
|
222
|
-
Effect.Effect<
|
|
223
|
-
|
|
220
|
+
Effect.Effect<unknown, never, R2>
|
|
221
|
+
>,
|
|
222
|
+
never,
|
|
223
|
+
R
|
|
224
224
|
>
|
|
225
225
|
|
|
226
226
|
/**
|
|
@@ -229,11 +229,11 @@ export type NavigationHandler<R, R2> = (
|
|
|
229
229
|
export type FormDataHandler<R, R2> = (
|
|
230
230
|
event: FormDataEvent
|
|
231
231
|
) => Effect.Effect<
|
|
232
|
-
R,
|
|
233
|
-
RedirectError | CancelNavigation,
|
|
234
232
|
Option.Option<
|
|
235
|
-
Effect.Effect<
|
|
236
|
-
|
|
233
|
+
Effect.Effect<Option.Option<HttpClient.response.ClientResponse>, RedirectError | CancelNavigation, R2>
|
|
234
|
+
>,
|
|
235
|
+
RedirectError | CancelNavigation,
|
|
236
|
+
R
|
|
237
237
|
>
|
|
238
238
|
|
|
239
239
|
/**
|
|
@@ -400,12 +400,12 @@ export function isCancelNavigation(e: unknown): e is CancelNavigation {
|
|
|
400
400
|
export const navigate = (
|
|
401
401
|
url: string | URL,
|
|
402
402
|
options?: NavigateOptions
|
|
403
|
-
): Effect.Effect<
|
|
403
|
+
): Effect.Effect<Destination, NavigationError, Navigation> => Navigation.withEffect((n) => n.navigate(url, options))
|
|
404
404
|
|
|
405
405
|
/**
|
|
406
406
|
* @since 1.0.0
|
|
407
407
|
*/
|
|
408
|
-
export const back: (options?: { readonly info?: unknown }) => Effect.Effect<
|
|
408
|
+
export const back: (options?: { readonly info?: unknown }) => Effect.Effect<Destination, NavigationError, Navigation> =
|
|
409
409
|
(opts) => Navigation.withEffect((n) => n.back(opts))
|
|
410
410
|
|
|
411
411
|
/**
|
|
@@ -413,7 +413,7 @@ export const back: (options?: { readonly info?: unknown }) => Effect.Effect<Navi
|
|
|
413
413
|
*/
|
|
414
414
|
export const forward: (
|
|
415
415
|
options?: { readonly info?: unknown }
|
|
416
|
-
) => Effect.Effect<
|
|
416
|
+
) => Effect.Effect<Destination, NavigationError, Navigation> = (
|
|
417
417
|
opts
|
|
418
418
|
) => Navigation.withEffect((n) => n.forward(opts))
|
|
419
419
|
|
|
@@ -423,7 +423,7 @@ export const forward: (
|
|
|
423
423
|
export const traverseTo: (
|
|
424
424
|
key: Uuid,
|
|
425
425
|
options?: { readonly info?: unknown }
|
|
426
|
-
) => Effect.Effect<
|
|
426
|
+
) => Effect.Effect<Destination, NavigationError, Navigation> = (key, opts) =>
|
|
427
427
|
Navigation.withEffect((n) => n.traverseTo(key, opts))
|
|
428
428
|
|
|
429
429
|
/**
|
|
@@ -431,7 +431,7 @@ export const traverseTo: (
|
|
|
431
431
|
*/
|
|
432
432
|
export const updateCurrentEntry: (
|
|
433
433
|
options: { readonly state: unknown }
|
|
434
|
-
) => Effect.Effect<
|
|
434
|
+
) => Effect.Effect<Destination, NavigationError, Navigation> = (opts) =>
|
|
435
435
|
Navigation.withEffect((n) => n.updateCurrentEntry(opts))
|
|
436
436
|
|
|
437
437
|
/**
|
|
@@ -439,14 +439,14 @@ export const updateCurrentEntry: (
|
|
|
439
439
|
*/
|
|
440
440
|
export const reload: (
|
|
441
441
|
options?: { readonly info?: unknown; readonly state?: unknown }
|
|
442
|
-
) => Effect.Effect<
|
|
442
|
+
) => Effect.Effect<Destination, NavigationError, Navigation> = (
|
|
443
443
|
opts
|
|
444
444
|
) => Navigation.withEffect((n) => n.reload(opts))
|
|
445
445
|
|
|
446
446
|
/**
|
|
447
447
|
* @since 1.0.0
|
|
448
448
|
*/
|
|
449
|
-
export const CurrentEntry: RefSubject.Computed<
|
|
449
|
+
export const CurrentEntry: RefSubject.Computed<Destination, never, Navigation> = RefSubject.computedFromTag(
|
|
450
450
|
Navigation,
|
|
451
451
|
(nav) => nav.currentEntry
|
|
452
452
|
)
|
|
@@ -461,7 +461,7 @@ export function getCurrentPathFromUrl(location: Pick<URL, "pathname" | "search"
|
|
|
461
461
|
/**
|
|
462
462
|
* @since 1.0.0
|
|
463
463
|
*/
|
|
464
|
-
export const CurrentPath: RefSubject.Computed<
|
|
464
|
+
export const CurrentPath: RefSubject.Computed<string, never, Navigation> = RefSubject.map(
|
|
465
465
|
CurrentEntry,
|
|
466
466
|
(d) => getCurrentPathFromUrl(d.url)
|
|
467
467
|
)
|
|
@@ -469,7 +469,7 @@ export const CurrentPath: RefSubject.Computed<Navigation, never, string> = RefSu
|
|
|
469
469
|
/**
|
|
470
470
|
* @since 1.0.0
|
|
471
471
|
*/
|
|
472
|
-
export const CurrentEntries: RefSubject.Computed<
|
|
472
|
+
export const CurrentEntries: RefSubject.Computed<ReadonlyArray<Destination>, never, Navigation> = RefSubject
|
|
473
473
|
.computedFromTag(
|
|
474
474
|
Navigation,
|
|
475
475
|
(n) => n.entries
|
|
@@ -478,7 +478,7 @@ export const CurrentEntries: RefSubject.Computed<Navigation, never, ReadonlyArra
|
|
|
478
478
|
/**
|
|
479
479
|
* @since 1.0.0
|
|
480
480
|
*/
|
|
481
|
-
export const CanGoForward: RefSubject.Computed<
|
|
481
|
+
export const CanGoForward: RefSubject.Computed<boolean, never, Navigation> = RefSubject.computedFromTag(
|
|
482
482
|
Navigation,
|
|
483
483
|
(n) => n.canGoForward
|
|
484
484
|
)
|
|
@@ -486,7 +486,7 @@ export const CanGoForward: RefSubject.Computed<Navigation, never, boolean> = Ref
|
|
|
486
486
|
/**
|
|
487
487
|
* @since 1.0.0
|
|
488
488
|
*/
|
|
489
|
-
export const CanGoBack: RefSubject.Computed<
|
|
489
|
+
export const CanGoBack: RefSubject.Computed<boolean, never, Navigation> = RefSubject.computedFromTag(
|
|
490
490
|
Navigation,
|
|
491
491
|
(n) => n.canGoBack
|
|
492
492
|
)
|
|
@@ -508,9 +508,9 @@ export function submit(
|
|
|
508
508
|
data: FormData,
|
|
509
509
|
formInput?: Simplify<Omit<FormInputFrom, "data">>
|
|
510
510
|
): Effect.Effect<
|
|
511
|
-
|
|
511
|
+
Option.Option<HttpClient.response.ClientResponse>,
|
|
512
512
|
NavigationError | HttpClient.error.HttpClientError,
|
|
513
|
-
|
|
513
|
+
Navigation | HttpClient.client.Client.Default | Scope.Scope
|
|
514
514
|
> {
|
|
515
515
|
return Navigation.withEffect((n) => n.submit(data, formInput))
|
|
516
516
|
}
|
|
@@ -520,6 +520,6 @@ export function submit(
|
|
|
520
520
|
*/
|
|
521
521
|
export function onFormData<R = never, R2 = never>(
|
|
522
522
|
handler: FormDataHandler<R, R2>
|
|
523
|
-
): Effect.Effect<Navigation | R | R2 | Scope.Scope
|
|
523
|
+
): Effect.Effect<void, never, Navigation | R | R2 | Scope.Scope> {
|
|
524
524
|
return Navigation.withEffect((n) => n.onFormData(handler))
|
|
525
525
|
}
|
|
@@ -38,7 +38,7 @@ declare global {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export const fromWindow: Layer.Layer<
|
|
41
|
+
export const fromWindow: Layer.Layer<Navigation, never, Window> = Navigation.scoped(
|
|
42
42
|
Window.withEffect((window) => {
|
|
43
43
|
const getRandomValues = (length: number) => Effect.sync(() => window.crypto.getRandomValues(new Uint8Array(length)))
|
|
44
44
|
return Effect.gen(function*(_) {
|
|
@@ -108,12 +108,8 @@ const getNavigationState = (navigation: NativeNavigation): NavigationState => {
|
|
|
108
108
|
|
|
109
109
|
function setupWithNavigation(
|
|
110
110
|
navigation: NativeNavigation,
|
|
111
|
-
runPromise: <E, A>(effect: Effect.Effect<
|
|
112
|
-
): Effect.Effect<
|
|
113
|
-
Scope.Scope | GetRandomValues,
|
|
114
|
-
never,
|
|
115
|
-
ModelAndIntent
|
|
116
|
-
> {
|
|
111
|
+
runPromise: <E, A>(effect: Effect.Effect<A, E, Scope.Scope>) => Promise<A>
|
|
112
|
+
): Effect.Effect<ModelAndIntent, never, Scope.Scope | GetRandomValues> {
|
|
117
113
|
return Effect.gen(function*(_) {
|
|
118
114
|
const state = yield* _(
|
|
119
115
|
RefSubject.fromEffect(
|
|
@@ -150,7 +146,7 @@ function setupWithNavigation(
|
|
|
150
146
|
const runHandlers = (native: NativeEvent) =>
|
|
151
147
|
Effect.gen(function*(_) {
|
|
152
148
|
const eventHandlers = yield* _(handlers)
|
|
153
|
-
const matches: Array<Effect.Effect<
|
|
149
|
+
const matches: Array<Effect.Effect<unknown>> = []
|
|
154
150
|
|
|
155
151
|
const event: NavigationEvent = {
|
|
156
152
|
type: native.navigationType,
|
|
@@ -220,11 +216,7 @@ function shouldNotIntercept(navigationEvent: NativeEvent): boolean {
|
|
|
220
216
|
function setupWithHistory(
|
|
221
217
|
window: Window,
|
|
222
218
|
onEvent: (event: HistoryEvent) => void
|
|
223
|
-
): Effect.Effect<
|
|
224
|
-
GetRandomValues | Scope.Scope,
|
|
225
|
-
never,
|
|
226
|
-
ModelAndIntent
|
|
227
|
-
> {
|
|
219
|
+
): Effect.Effect<ModelAndIntent, never, GetRandomValues | Scope.Scope> {
|
|
228
220
|
return Effect.gen(function*(_) {
|
|
229
221
|
const { location } = window
|
|
230
222
|
const { original: history, unpatch } = patchHistory(window, onEvent)
|
|
@@ -411,19 +403,15 @@ function patchHistory(window: Window, onEvent: (event: HistoryEvent) => void) {
|
|
|
411
403
|
type ScopedRuntime<R> = {
|
|
412
404
|
readonly runtime: Runtime.Runtime<R | Scope.Scope>
|
|
413
405
|
readonly scope: Scope.Scope
|
|
414
|
-
readonly run: <E, A>(effect: Effect.Effect<R | Scope.Scope
|
|
415
|
-
readonly runPromise: <E, A>(effect: Effect.Effect<R | Scope.Scope
|
|
406
|
+
readonly run: <E, A>(effect: Effect.Effect<A, E, R | Scope.Scope>) => Fiber.RuntimeFiber<A, E>
|
|
407
|
+
readonly runPromise: <E, A>(effect: Effect.Effect<A, E, R | Scope.Scope>) => Promise<A>
|
|
416
408
|
}
|
|
417
409
|
|
|
418
|
-
function scopedRuntime<R>(): Effect.Effect<
|
|
419
|
-
R | Scope.Scope,
|
|
420
|
-
never,
|
|
421
|
-
ScopedRuntime<R>
|
|
422
|
-
> {
|
|
410
|
+
function scopedRuntime<R>(): Effect.Effect<ScopedRuntime<R>, never, R | Scope.Scope> {
|
|
423
411
|
return Effect.map(Effect.runtime<R | Scope.Scope>(), (runtime) => {
|
|
424
412
|
const scope = Context.get(runtime.context, Scope.Scope)
|
|
425
413
|
const runFork = Runtime.runFork(runtime)
|
|
426
|
-
const runPromise = <E, A>(effect: Effect.Effect<R | Scope.Scope
|
|
414
|
+
const runPromise = <E, A>(effect: Effect.Effect<A, E, R | Scope.Scope>): Promise<A> =>
|
|
427
415
|
new Promise((resolve, reject) => {
|
|
428
416
|
const fiber = runFork(effect, { scope })
|
|
429
417
|
fiber.addObserver(Exit.match({
|
package/src/internal/memory.ts
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
setupFromModelAndIntent
|
|
19
19
|
} from "./shared.js"
|
|
20
20
|
|
|
21
|
-
export const memory = (options: MemoryOptions): Layer.Layer<
|
|
21
|
+
export const memory = (options: MemoryOptions): Layer.Layer<Navigation> =>
|
|
22
22
|
Navigation.scoped(
|
|
23
23
|
Effect.gen(function*(_) {
|
|
24
24
|
const getRandomValues = yield* _(GetRandomValues)
|
|
@@ -33,7 +33,7 @@ export const memory = (options: MemoryOptions): Layer.Layer<never, never, Naviga
|
|
|
33
33
|
|
|
34
34
|
export function initialMemory(
|
|
35
35
|
options: InitialMemoryOptions
|
|
36
|
-
): Layer.Layer<
|
|
36
|
+
): Layer.Layer<Navigation> {
|
|
37
37
|
return Navigation.scoped(
|
|
38
38
|
Effect.gen(function*(_) {
|
|
39
39
|
const getRandomValues = yield* _(GetRandomValues)
|
|
@@ -56,11 +56,7 @@ export function initialMemory(
|
|
|
56
56
|
|
|
57
57
|
function setupMemory(
|
|
58
58
|
options: MemoryOptions
|
|
59
|
-
): Effect.Effect<
|
|
60
|
-
GetRandomValues | Scope.Scope,
|
|
61
|
-
never,
|
|
62
|
-
ModelAndIntent
|
|
63
|
-
> {
|
|
59
|
+
): Effect.Effect<ModelAndIntent, never, GetRandomValues | Scope.Scope> {
|
|
64
60
|
return Effect.gen(function*(_) {
|
|
65
61
|
const state = yield* _(
|
|
66
62
|
RefSubject.fromEffect(
|
package/src/internal/shared.ts
CHANGED
|
@@ -44,33 +44,15 @@ export const getUrl = (origin: string, urlOrPath: string | URL): URL => {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
export type ModelAndIntent = {
|
|
47
|
-
readonly state: RefSubject.RefSubject<
|
|
48
|
-
readonly canGoBack: RefSubject.Computed<
|
|
49
|
-
|
|
50
|
-
never,
|
|
51
|
-
boolean
|
|
52
|
-
>
|
|
53
|
-
readonly canGoForward: RefSubject.Computed<
|
|
54
|
-
never,
|
|
55
|
-
never,
|
|
56
|
-
boolean
|
|
57
|
-
>
|
|
47
|
+
readonly state: RefSubject.RefSubject<NavigationState>
|
|
48
|
+
readonly canGoBack: RefSubject.Computed<boolean>
|
|
49
|
+
readonly canGoForward: RefSubject.Computed<boolean>
|
|
58
50
|
readonly beforeHandlers: RefSubject.RefSubject<
|
|
59
|
-
never,
|
|
60
|
-
never,
|
|
61
51
|
Set<readonly [BeforeNavigationHandler<any, any>, Context.Context<any>]>
|
|
62
52
|
>
|
|
63
|
-
readonly handlers: RefSubject.RefSubject<
|
|
64
|
-
never,
|
|
65
|
-
never,
|
|
66
|
-
Set<readonly [NavigationHandler<any, any>, Context.Context<any>]>
|
|
67
|
-
>
|
|
53
|
+
readonly handlers: RefSubject.RefSubject<Set<readonly [NavigationHandler<any, any>, Context.Context<any>]>>
|
|
68
54
|
|
|
69
|
-
readonly formDataHandlers: RefSubject.RefSubject<
|
|
70
|
-
never,
|
|
71
|
-
never,
|
|
72
|
-
Set<readonly [FormDataHandler<any, any>, Context.Context<any>]>
|
|
73
|
-
>
|
|
55
|
+
readonly formDataHandlers: RefSubject.RefSubject<Set<readonly [FormDataHandler<any, any>, Context.Context<any>]>>
|
|
74
56
|
|
|
75
57
|
readonly commit: Commit
|
|
76
58
|
}
|
|
@@ -92,7 +74,7 @@ export function setupFromModelAndIntent(
|
|
|
92
74
|
const runBeforeHandlers = (event: BeforeNavigationEvent) =>
|
|
93
75
|
Effect.gen(function*(_) {
|
|
94
76
|
const handlers = yield* _(beforeHandlers)
|
|
95
|
-
const matches: Array<Effect.Effect<
|
|
77
|
+
const matches: Array<Effect.Effect<unknown, RedirectError | CancelNavigation>> = []
|
|
96
78
|
|
|
97
79
|
for (const [handler, ctx] of handlers) {
|
|
98
80
|
const exit = yield* _(handler(event), Effect.provide(ctx), Effect.either)
|
|
@@ -121,7 +103,7 @@ export function setupFromModelAndIntent(
|
|
|
121
103
|
const runHandlers = (event: NavigationEvent) =>
|
|
122
104
|
Effect.gen(function*(_) {
|
|
123
105
|
const eventHandlers = yield* _(handlers)
|
|
124
|
-
const matches: Array<Effect.Effect<
|
|
106
|
+
const matches: Array<Effect.Effect<unknown>> = []
|
|
125
107
|
|
|
126
108
|
for (const [handler, ctx] of eventHandlers) {
|
|
127
109
|
const match = yield* _(handler(event), Effect.provide(ctx))
|
|
@@ -138,14 +120,14 @@ export function setupFromModelAndIntent(
|
|
|
138
120
|
const runFormDataHandlers = (
|
|
139
121
|
event: FormDataEvent
|
|
140
122
|
): Effect.Effect<
|
|
141
|
-
HttpClient.
|
|
123
|
+
Either.Either<RedirectError | CancelNavigation, Option.Option<HttpClient.response.ClientResponse>>,
|
|
142
124
|
NavigationError | HttpClient.error.HttpClientError,
|
|
143
|
-
|
|
125
|
+
Scope.Scope | HttpClient.client.Client.Default
|
|
144
126
|
> =>
|
|
145
127
|
Effect.gen(function*(_) {
|
|
146
128
|
const handlers = yield* _(formDataHandlers)
|
|
147
129
|
const matches: Array<
|
|
148
|
-
Effect.Effect<
|
|
130
|
+
Effect.Effect<Option.Option<HttpClient.response.ClientResponse>, RedirectError | CancelNavigation>
|
|
149
131
|
> = []
|
|
150
132
|
|
|
151
133
|
for (const [handler, ctx] of handlers) {
|
|
@@ -183,11 +165,11 @@ export function setupFromModelAndIntent(
|
|
|
183
165
|
|
|
184
166
|
const runNavigationEvent = (
|
|
185
167
|
beforeEvent: BeforeNavigationEvent,
|
|
186
|
-
get: Effect.Effect<
|
|
187
|
-
set: (a: NavigationState) => Effect.Effect<
|
|
168
|
+
get: Effect.Effect<NavigationState>,
|
|
169
|
+
set: (a: NavigationState) => Effect.Effect<NavigationState>,
|
|
188
170
|
depth: number,
|
|
189
171
|
skipCommit: boolean = false
|
|
190
|
-
): Effect.Effect<
|
|
172
|
+
): Effect.Effect<Destination, NavigationError> =>
|
|
191
173
|
Effect.gen(function*(_) {
|
|
192
174
|
let current = yield* _(get)
|
|
193
175
|
current = yield* _(set({ ...current, transition: Option.some(beforeEvent) }))
|
|
@@ -246,10 +228,10 @@ export function setupFromModelAndIntent(
|
|
|
246
228
|
|
|
247
229
|
const handleError = (
|
|
248
230
|
error: RedirectError | CancelNavigation,
|
|
249
|
-
get: Effect.Effect<
|
|
250
|
-
set: (a: NavigationState) => Effect.Effect<
|
|
231
|
+
get: Effect.Effect<NavigationState>,
|
|
232
|
+
set: (a: NavigationState) => Effect.Effect<NavigationState>,
|
|
251
233
|
depth: number
|
|
252
|
-
): Effect.Effect<
|
|
234
|
+
): Effect.Effect<Destination, NavigationError> =>
|
|
253
235
|
Effect.gen(function*(_) {
|
|
254
236
|
if (depth >= 25) {
|
|
255
237
|
return yield* _(Effect.dieMessage(`Redirect loop detected.`))
|
|
@@ -355,7 +337,7 @@ export function setupFromModelAndIntent(
|
|
|
355
337
|
|
|
356
338
|
const beforeNavigation = <R = never, R2 = never>(
|
|
357
339
|
handler: BeforeNavigationHandler<R, R2>
|
|
358
|
-
): Effect.Effect<R | R2 | Scope.Scope
|
|
340
|
+
): Effect.Effect<void, never, R | R2 | Scope.Scope> =>
|
|
359
341
|
Effect.contextWithEffect((ctx) => {
|
|
360
342
|
const entry = [handler, ctx] as const
|
|
361
343
|
|
|
@@ -373,7 +355,7 @@ export function setupFromModelAndIntent(
|
|
|
373
355
|
|
|
374
356
|
const onNavigation = <R = never, R2 = never>(
|
|
375
357
|
handler: NavigationHandler<R, R2>
|
|
376
|
-
): Effect.Effect<R | R2 | Scope.Scope
|
|
358
|
+
): Effect.Effect<void, never, R | R2 | Scope.Scope> =>
|
|
377
359
|
Effect.contextWithEffect((ctx) => {
|
|
378
360
|
const entry = [handler, ctx] as const
|
|
379
361
|
|
|
@@ -410,9 +392,9 @@ export function setupFromModelAndIntent(
|
|
|
410
392
|
data: FormData,
|
|
411
393
|
input?: Omit<FormInputFrom, "data">
|
|
412
394
|
): Effect.Effect<
|
|
413
|
-
HttpClient.
|
|
395
|
+
Option.Option<HttpClient.response.ClientResponse>,
|
|
414
396
|
NavigationError | HttpClient.error.HttpClientError,
|
|
415
|
-
|
|
397
|
+
Scope.Scope | HttpClient.client.Client.Default
|
|
416
398
|
> =>
|
|
417
399
|
state.runUpdates(({ get, set }) =>
|
|
418
400
|
Effect.gen(function*(_) {
|
|
@@ -457,7 +439,7 @@ export function setupFromModelAndIntent(
|
|
|
457
439
|
|
|
458
440
|
const onFormData = <R = never, R2 = never>(
|
|
459
441
|
handler: FormDataHandler<R, R2>
|
|
460
|
-
): Effect.Effect<R | R2 | Scope.Scope
|
|
442
|
+
): Effect.Effect<void, never, R | R2 | Scope.Scope> =>
|
|
461
443
|
Effect.contextWithEffect((ctx) => {
|
|
462
444
|
const entry = [handler, ctx] as const
|
|
463
445
|
|