This commit is contained in:
@@ -150,20 +150,16 @@ export const run = <A, I, R, SA, SE, SR>(
|
|||||||
|
|
||||||
export const submit = <A, I, R, SA, SE, SR>(
|
export const submit = <A, I, R, SA, SE, SR>(
|
||||||
self: Form<A, I, R, SA, SE, SR>
|
self: Form<A, I, R, SA, SE, SR>
|
||||||
): Effect.Effect<Option.Option<AsyncData.AsyncData<SA, SE>>, NoSuchElementException, SR> => Effect.whenEffect(
|
): Effect.Effect<Option.Option<Result.Result<SA, SE>>, NoSuchElementException, Scope.Scope | SR> => Effect.whenEffect(
|
||||||
self.valueRef.pipe(
|
self.valueRef.pipe(
|
||||||
Effect.andThen(identity),
|
Effect.andThen(identity),
|
||||||
Effect.tap(Ref.set(self.submitStateRef, AsyncData.loading())),
|
Effect.andThen(flow(self.onSubmit, Result.forkEffectScoped)),
|
||||||
Effect.andThen(flow(
|
Effect.andThen(Stream.fromQueue),
|
||||||
self.onSubmit as (value: NoInfer<A>) => Effect.Effect<SA, SE | ParseResult.ParseError, SR>,
|
Stream.unwrap,
|
||||||
Effect.tapErrorTag("ParseError", e => Ref.set(self.errorRef, Option.some(e as ParseResult.ParseError))),
|
Stream.runFoldEffect(
|
||||||
Effect.exit,
|
Result.initial() as Result.Result<SA, SE>,
|
||||||
Effect.map(Exit.match({
|
(_, result) => Effect.as(Ref.set(self.submitResultRef, result), result),
|
||||||
onSuccess: a => AsyncData.success(a),
|
),
|
||||||
onFailure: e => AsyncData.failure(e as Cause.Cause<SE>),
|
|
||||||
})),
|
|
||||||
Effect.tap(v => Ref.set(self.submitStateRef, v)),
|
|
||||||
)),
|
|
||||||
),
|
),
|
||||||
|
|
||||||
self.canSubmitSubscribable.get,
|
self.canSubmitSubscribable.get,
|
||||||
@@ -237,9 +233,9 @@ export const isFormField = (u: unknown): u is FormField<unknown, unknown> => Pre
|
|||||||
export const useSubmit = <A, I, R, SA, SE, SR>(
|
export const useSubmit = <A, I, R, SA, SE, SR>(
|
||||||
self: Form<A, I, R, SA, SE, SR>
|
self: Form<A, I, R, SA, SE, SR>
|
||||||
): Effect.Effect<
|
): Effect.Effect<
|
||||||
() => Promise<Option.Option<AsyncData.AsyncData<SA, SE>>>,
|
() => Promise<Option.Option<Result.Result<SA, SE>>>,
|
||||||
never,
|
never,
|
||||||
SR
|
Scope.Scope | SR
|
||||||
> => Component.useCallbackPromise(() => submit(self), [self])
|
> => Component.useCallbackPromise(() => submit(self), [self])
|
||||||
|
|
||||||
export const useField = <A, I, R, SA, SE, SR, const P extends PropertyPath.Paths<NoInfer<I>>>(
|
export const useField = <A, I, R, SA, SE, SR, const P extends PropertyPath.Paths<NoInfer<I>>>(
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ export const toExit = <A, E, P>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const forkEffect = <A, E, R>(
|
export const forkEffectScoped = <A, E, R>(
|
||||||
effect: Effect.Effect<A, E, R>
|
effect: Effect.Effect<A, E, R>
|
||||||
): Effect.Effect<Queue.Dequeue<Result<A, E>>, never, Scope.Scope | R> => Queue.unbounded<Result<A, E>>().pipe(
|
): Effect.Effect<Queue.Dequeue<Result<A, E>>, never, Scope.Scope | R> => Queue.unbounded<Result<A, E>>().pipe(
|
||||||
Effect.tap(Queue.offer(initial())),
|
Effect.tap(Queue.offer(initial())),
|
||||||
|
|||||||
Reference in New Issue
Block a user