diff --git a/packages/effect-fc-next/package.json b/packages/effect-fc-next/package.json index 73f5427..ce2152c 100644 --- a/packages/effect-fc-next/package.json +++ b/packages/effect-fc-next/package.json @@ -25,10 +25,6 @@ "types": "./dist/Component.d.ts", "default": "./dist/Component.js" }, - "./ErrorObserver": { - "types": "./dist/ErrorObserver.d.ts", - "default": "./dist/ErrorObserver.js" - }, "./Form": { "types": "./dist/Form.d.ts", "default": "./dist/Form.js" diff --git a/packages/effect-fc-next/src/ErrorObserver.ts b/packages/effect-fc-next/src/ErrorObserver.ts deleted file mode 100644 index 0fd19aa..0000000 --- a/packages/effect-fc-next/src/ErrorObserver.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { type Cause, Context, Effect, Layer, Option, Pipeable, Predicate, PubSub, type Scope } from "effect" - - -export const ErrorObserverTypeId: unique symbol = Symbol.for("@effect-fc/ErrorObserver/ErrorObserver") -export type ErrorObserverTypeId = typeof ErrorObserverTypeId - -export interface ErrorObserver extends Pipeable.Pipeable { - readonly [ErrorObserverTypeId]: ErrorObserverTypeId - handle(effect: Effect.Effect): Effect.Effect - readonly subscribe: Effect.Effect>, never, Scope.Scope> -} - -export const ErrorObserver = () => Context.Service>( - "@effect-fc/ErrorObserver/ErrorObserver", -) - -export class ErrorObserverImpl extends Pipeable.Class implements ErrorObserver { - readonly [ErrorObserverTypeId]: ErrorObserverTypeId = ErrorObserverTypeId - - constructor(readonly pubsub: PubSub.PubSub>) { - super() - } - - get subscribe(): Effect.Effect>, never, Scope.Scope> { - return PubSub.subscribe(this.pubsub) - } - - handle(effect: Effect.Effect): Effect.Effect { - return Effect.tapCause(effect, cause => Effect.asVoid( - PubSub.publish(this.pubsub, cause as unknown as Cause.Cause), - )) - } -} - -export const isErrorObserver = (u: unknown): u is ErrorObserver => Predicate.hasProperty(u, ErrorObserverTypeId) - -export const layer: Layer.Layer = Layer.effect(ErrorObserver())( - Effect.map(PubSub.unbounded>(), pubsub => new ErrorObserverImpl(pubsub)), -) - -export const handle = (effect: Effect.Effect): Effect.Effect => Effect.flatMap( - Effect.serviceOption(ErrorObserver()), - Option.match({ - onSome: observer => observer.handle(effect), - onNone: () => effect, - }), -) diff --git a/packages/effect-fc-next/src/index.ts b/packages/effect-fc-next/src/index.ts index 49f882e..a2d3bda 100644 --- a/packages/effect-fc-next/src/index.ts +++ b/packages/effect-fc-next/src/index.ts @@ -1,6 +1,5 @@ export * as Async from "./Async.js" export * as Component from "./Component.js" -export * as ErrorObserver from "./ErrorObserver.js" export * as Form from "./Form.js" export * as Lens from "./Lens.js" export * as LensForm from "./LensForm.js"