diff --git a/packages/effect-fc/src/SynchronizedForm.ts b/packages/effect-fc/src/SynchronizedForm.ts index b0d48e3..c732b9b 100644 --- a/packages/effect-fc/src/SynchronizedForm.ts +++ b/packages/effect-fc/src/SynchronizedForm.ts @@ -1,4 +1,4 @@ -import { Array, type Context, Effect, Equal, Fiber, Option, ParseResult, Pipeable, Predicate, Schema, type Scope, Stream, SubscriptionRef } from "effect" +import { Array, type Context, Effect, Equal, Fiber, flow, Option, ParseResult, Pipeable, Predicate, Schema, type Scope, Stream, SubscriptionRef } from "effect" import * as Form from "./Form.js" import * as Lens from "./Lens.js" import * as Subscribable from "./Subscribable.js" @@ -115,7 +115,7 @@ export class SynchronizedFormImpl< ) } - synchronizeEncodedValue(encodedValue: I): Effect.Effect { + synchronizeEncodedValue(encodedValue: I): Effect.Effect { return Lens.get(this.validationFiber).pipe( Effect.andThen(Option.match({ onSome: Fiber.interrupt, @@ -128,21 +128,23 @@ export class SynchronizedFormImpl< ) )), Effect.tap(fiber => Lens.set(this.validationFiber, Option.some(fiber))), - Effect.andThen(Fiber.join), + Effect.flatMap(Fiber.join), - Effect.catchTag("ParseError", e => ParseResult.ArrayFormatter.formatError(e).pipe( - Effect.flatMap(v => Lens.set(this.issues, v)), - Effect.andThen(Effect.fail(e)), - )), - Effect.tap(value => Effect.ensuring( + Effect.flatMap(value => Effect.ensuring( Lens.set(this.isCommitting, true).pipe( Effect.andThen(Lens.set(this.issues, Array.empty())), Effect.andThen(Lens.set(this.target, value)), ), Lens.set(this.isCommitting, false), )), + Effect.catchIf( + ParseResult.isParseError, + flow( + ParseResult.ArrayFormatter.formatError, + Effect.flatMap(v => Lens.set(this.issues, v)), + ), + ), - Effect.ignore, Effect.provide(this.context), ) }