Form work
Some checks failed
Lint / lint (push) Failing after 9s

This commit is contained in:
Julien Valverdé
2025-10-21 14:49:53 +02:00
parent e8b8df9449
commit 8642619a6a

View File

@@ -18,7 +18,7 @@ extends Pipeable.Pipeable {
readonly schema: Schema.Schema<A, I, R> readonly schema: Schema.Schema<A, I, R>
readonly onSubmit: (value: NoInfer<A>) => Effect.Effect<SA, SE, SR> readonly onSubmit: (value: NoInfer<A>) => Effect.Effect<SA, SE, SR>
readonly autosubmit: Option.Option<boolean> readonly autosubmit: boolean
readonly debounce: Option.Option<Duration.DurationInput> readonly debounce: Option.Option<Duration.DurationInput>
readonly valueRef: SubscriptionRef.SubscriptionRef<Option.Option<A>> readonly valueRef: SubscriptionRef.SubscriptionRef<Option.Option<A>>
@@ -37,7 +37,7 @@ extends Pipeable.Class() implements Form<A, I, R, SA, SE, SR> {
constructor( constructor(
readonly schema: Schema.Schema<A, I, R>, readonly schema: Schema.Schema<A, I, R>,
readonly onSubmit: (value: NoInfer<A>) => Effect.Effect<SA, SE, SR>, readonly onSubmit: (value: NoInfer<A>) => Effect.Effect<SA, SE, SR>,
readonly autosubmit: Option.Option<boolean>, readonly autosubmit: boolean,
readonly debounce: Option.Option<Duration.DurationInput>, readonly debounce: Option.Option<Duration.DurationInput>,
readonly valueRef: SubscriptionRef.SubscriptionRef<Option.Option<A>>, readonly valueRef: SubscriptionRef.SubscriptionRef<Option.Option<A>>,
@@ -82,7 +82,7 @@ export const make: {
return new FormImpl( return new FormImpl(
options.schema, options.schema,
options.onSubmit, options.onSubmit,
Option.fromNullable(options.autosubmit), options.autosubmit ?? false,
Option.fromNullable(options.debounce), Option.fromNullable(options.debounce),
valueRef, valueRef,
@@ -128,13 +128,17 @@ export const run = <A, I, R, SA, SE, SR>(
onFailure: c => Option.match( onFailure: c => Option.match(
Chunk.findFirst(Cause.failures(c), e => e._tag === "ParseError"), Chunk.findFirst(Cause.failures(c), e => e._tag === "ParseError"),
{ {
onSome: e => SubscriptionRef.set(self.errorRef, Option.some(e)), onSome: e => Effect.as(SubscriptionRef.set(self.errorRef, Option.some(e)), Option.none()),
onNone: () => Effect.void, onNone: () => Effect.succeed(Option.none()),
}, },
), ),
}), }),
Effect.uninterruptible, Effect.uninterruptible,
)), )),
Effect.andThen(value => Option.isSome(value) && self.autosubmit
?
: Effect.void
),
Effect.scoped, Effect.scoped,
Effect.forkScoped, Effect.forkScoped,
) )