@reffuse/extension-query 0.1.4 #15
@@ -5,7 +5,7 @@ import { Layer } from "effect"
|
||||
import { StrictMode } from "react"
|
||||
import { createRoot } from "react-dom/client"
|
||||
import { ReffuseRuntime } from "reffuse"
|
||||
import { AppQueryClientLive, AppQueryErrorHandlerLive } from "./query"
|
||||
import { AppQueryClient, AppQueryErrorHandlerLive } from "./query"
|
||||
import { GlobalContext } from "./reffuse"
|
||||
import { routeTree } from "./routeTree.gen"
|
||||
|
||||
@@ -15,7 +15,7 @@ const layer = Layer.empty.pipe(
|
||||
Layer.provideMerge(Geolocation.layer),
|
||||
Layer.provideMerge(Permissions.layer),
|
||||
Layer.provideMerge(FetchHttpClient.layer),
|
||||
Layer.provideMerge(AppQueryClientLive),
|
||||
Layer.provideMerge(AppQueryClient.Live),
|
||||
Layer.provideMerge(AppQueryErrorHandlerLive),
|
||||
)
|
||||
|
||||
|
||||
@@ -7,4 +7,5 @@ export class AppQueryErrorHandler extends ErrorHandler.Tag("AppQueryErrorHandler
|
||||
>() {}
|
||||
export const AppQueryErrorHandlerLive = ErrorHandler.layer(AppQueryErrorHandler)
|
||||
|
||||
export const [AppQueryClient, AppQueryClientLive] = QueryClient.make({ ErrorHandler: AppQueryErrorHandler })
|
||||
|
||||
export class AppQueryClient extends QueryClient.Service({ ErrorHandler: AppQueryErrorHandler })<AppQueryClient>() {}
|
||||
|
||||
@@ -2,7 +2,6 @@ import { HttpClient } from "@effect/platform"
|
||||
import { Clipboard, Geolocation, Permissions } from "@effect/platform-browser"
|
||||
import { LazyRefExtension } from "@reffuse/extension-lazyref"
|
||||
import { QueryExtension } from "@reffuse/extension-query"
|
||||
import { Context } from "effect"
|
||||
import { Reffuse, ReffuseContext } from "reffuse"
|
||||
import { AppQueryClient, AppQueryErrorHandler } from "./query"
|
||||
|
||||
@@ -12,7 +11,7 @@ export const GlobalContext = ReffuseContext.make<
|
||||
| Geolocation.Geolocation
|
||||
| Permissions.Permissions
|
||||
| HttpClient.HttpClient
|
||||
| Context.Tag.Service<typeof AppQueryClient>
|
||||
| AppQueryClient
|
||||
| AppQueryErrorHandler
|
||||
>()
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Context, Effect, Layer } from "effect"
|
||||
import type { Mutable } from "effect/Types"
|
||||
import * as ErrorHandler from "./ErrorHandler.js"
|
||||
|
||||
|
||||
@@ -18,71 +19,35 @@ export interface ServiceProps<EH, HandledE> {
|
||||
readonly ErrorHandler?: Context.Tag<EH, ErrorHandler.ErrorHandler<HandledE>>
|
||||
}
|
||||
|
||||
export const Service: <
|
||||
export interface ServiceResult<Self, EH, HandledE> extends Context.TagClass<Self, typeof Id, QueryClient<EH, HandledE>> {
|
||||
readonly Live: Layer.Layer<
|
||||
| Self
|
||||
| (EH extends ErrorHandler.DefaultErrorHandler
|
||||
? ErrorHandler.DefaultErrorHandler
|
||||
: never)
|
||||
>
|
||||
}
|
||||
|
||||
export const Service = <
|
||||
EH = ErrorHandler.DefaultErrorHandler,
|
||||
HandledE = never,
|
||||
>(
|
||||
props?: ServiceProps<EH, HandledE>
|
||||
) =>
|
||||
<Self>() =>
|
||||
& Context.TagClass<Self, typeof Id, QueryClient<EH, HandledE>>
|
||||
& { readonly Live: Layer.Layer<
|
||||
| QueryClient<EH, HandledE>
|
||||
| (EH extends ErrorHandler.DefaultErrorHandler
|
||||
? ErrorHandler.DefaultErrorHandler
|
||||
: never)
|
||||
> }
|
||||
= props => () => {
|
||||
const TagClass = Context.Tag(Id)() as any
|
||||
TagClass.Live = Layer.empty.pipe(
|
||||
Layer.provideMerge(
|
||||
Layer.effect(TagClass, Effect.succeed({
|
||||
ErrorHandler: props?.ErrorHandler ?? ErrorHandler.DefaultErrorHandler
|
||||
}))
|
||||
),
|
||||
) => (
|
||||
<Self>(): ServiceResult<Self, EH, HandledE> => {
|
||||
const TagClass = Context.Tag(Id)() as ServiceResult<Self, EH, HandledE>
|
||||
(TagClass as Mutable<typeof TagClass>).Live = Layer.empty.pipe(
|
||||
Layer.provideMerge(
|
||||
Layer.effect(TagClass, Effect.succeed({
|
||||
ErrorHandler: (props?.ErrorHandler ?? ErrorHandler.DefaultErrorHandler) as Context.Tag<EH, ErrorHandler.ErrorHandler<HandledE>>
|
||||
}))
|
||||
),
|
||||
|
||||
Layer.provideMerge((props?.ErrorHandler
|
||||
? Layer.empty
|
||||
: ErrorHandler.DefaultErrorHandlerLive
|
||||
),
|
||||
))
|
||||
|
||||
return TagClass
|
||||
}
|
||||
|
||||
|
||||
// export interface MakeProps<EH, HandledE> {
|
||||
// readonly ErrorHandler?: Context.Tag<EH, ErrorHandler.ErrorHandler<HandledE>>
|
||||
// }
|
||||
|
||||
// export type MakeResult<EH, HandledE> = [
|
||||
// tag: Tag<EH, HandledE>,
|
||||
// layer: Layer.Layer<
|
||||
// | QueryClient<EH, HandledE>
|
||||
// | (EH extends ErrorHandler.DefaultErrorHandler
|
||||
// ? ErrorHandler.DefaultErrorHandler
|
||||
// : never)
|
||||
// >,
|
||||
// ]
|
||||
|
||||
// export const make = <
|
||||
// EH = ErrorHandler.DefaultErrorHandler,
|
||||
// HandledE = never,
|
||||
// >(
|
||||
// props?: MakeProps<EH, HandledE>
|
||||
// ): MakeResult<EH, HandledE> => [
|
||||
// makeTag(),
|
||||
|
||||
// Layer.empty.pipe(
|
||||
// Layer.provideMerge(
|
||||
// Layer.effect(makeTag<EH, HandledE>(), Effect.succeed({
|
||||
// ErrorHandler: (props?.ErrorHandler ?? ErrorHandler.DefaultErrorHandler) as Context.Tag<EH, ErrorHandler.ErrorHandler<HandledE>>
|
||||
// }))
|
||||
// ),
|
||||
|
||||
// Layer.provideMerge((props?.ErrorHandler
|
||||
// ? Layer.empty
|
||||
// : ErrorHandler.DefaultErrorHandlerLive
|
||||
// ) as Layer.Layer<ErrorHandler.DefaultErrorHandler>),
|
||||
// ),
|
||||
// ]
|
||||
Layer.provideMerge((props?.ErrorHandler
|
||||
? Layer.empty
|
||||
: ErrorHandler.DefaultErrorHandlerLive
|
||||
) as Layer.Layer<ErrorHandler.DefaultErrorHandler>),
|
||||
)
|
||||
return TagClass
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user