@@ -1,4 +1,4 @@
|
||||
import { Array, Duration, Effect, Equivalence, flow, identity, Option, ParseResult, Pipeable, Schema, Scope, Stream, Subscribable, SubscriptionRef } from "effect"
|
||||
import { Array, Duration, Effect, Equal, Equivalence, flow, identity, Option, ParseResult, pipe, Pipeable, Schema, Scope, Stream, Subscribable, SubscriptionRef } from "effect"
|
||||
import type { NoSuchElementException } from "effect/Cause"
|
||||
import * as React from "react"
|
||||
import { Hooks } from "./hooks/index.js"
|
||||
@@ -16,6 +16,8 @@ extends Pipeable.Pipeable {
|
||||
readonly encodedValueRef: SubscriptionRef.SubscriptionRef<I>,
|
||||
readonly errorRef: SubscriptionRef.SubscriptionRef<Option.Option<ParseResult.ParseError>>,
|
||||
|
||||
readonly canSubmitSubscribable: Subscribable.Subscribable<boolean>
|
||||
|
||||
makeFieldIssuesSubscribable<const P extends PropertyPath.Paths<A>>(
|
||||
path: P
|
||||
): Subscribable.Subscribable<readonly ParseResult.ArrayFormatterIssue[]>
|
||||
@@ -25,6 +27,7 @@ extends Pipeable.Pipeable {
|
||||
class FormImpl<in out A, in out I, out R>
|
||||
extends Pipeable.Class() implements Form<A, I, R> {
|
||||
readonly [TypeId]: TypeId = TypeId
|
||||
readonly canSubmitSubscribable: Subscribable.Subscribable<boolean>
|
||||
|
||||
constructor(
|
||||
readonly schema: Schema.Schema<A, I, R>,
|
||||
@@ -33,6 +36,18 @@ extends Pipeable.Class() implements Form<A, I, R> {
|
||||
readonly errorRef: SubscriptionRef.SubscriptionRef<Option.Option<ParseResult.ParseError>>,
|
||||
) {
|
||||
super()
|
||||
|
||||
this.canSubmitSubscribable = pipe(
|
||||
<A>([value, error]: readonly [
|
||||
Option.Option<A>,
|
||||
Option.Option<ParseResult.ParseError>,
|
||||
]) => Option.isSome(value) && Option.isNone(error),
|
||||
|
||||
filter => SubscribableInternal.make({
|
||||
get: Effect.map(Effect.all([valueRef, errorRef]), filter),
|
||||
get changes() { return Stream.map(Stream.zipLatestAll(valueRef.changes, errorRef.changes), filter)},
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
makeFieldIssuesSubscribable<const P extends PropertyPath.Paths<A>>(path: P) {
|
||||
@@ -146,8 +161,9 @@ export const useInput: {
|
||||
Stream.drop(1),
|
||||
),
|
||||
|
||||
upstreamEncodedValue => internalValueRef.pipe(
|
||||
|
||||
upstreamEncodedValue => Effect.whenEffect(
|
||||
SubscriptionRef.set(internalValueRef, upstreamEncodedValue),
|
||||
Effect.andThen(internalValueRef, internalValue => !Equal.equals(upstreamEncodedValue, internalValue)),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user