Form work
All checks were successful
Lint / lint (push) Successful in 39s

This commit is contained in:
Julien Valverdé
2025-09-24 06:08:02 +02:00
parent bfd4b7f073
commit 2df12d7f40

View File

@@ -71,16 +71,6 @@ export const make: {
)
})
const run = <A, I, R>(self: Form<A, I, R>) => Stream.runForEach(
self.encodedValueRef.changes,
flow(
Schema.decode(self.schema, { errors: "all" }),
Effect.andThen(v => SubscriptionRef.set(self.valueRef, Option.some(v))),
Effect.andThen(SubscriptionRef.set(self.errorRef, Option.none())),
Effect.catchTag("ParseError", e => SubscriptionRef.set(self.errorRef, Option.some(e)))
),
)
export namespace service {
export interface Options<in out A, in out I, out R> extends make.Options<A, I, R> {}
}
@@ -104,6 +94,16 @@ export const useForm: {
return form
})
const run = <A, I, R>(self: Form<A, I, R>) => Stream.runForEach(
self.encodedValueRef.changes,
flow(
Schema.decode(self.schema, { errors: "all" }),
Effect.andThen(v => SubscriptionRef.set(self.valueRef, Option.some(v))),
Effect.andThen(SubscriptionRef.set(self.errorRef, Option.none())),
Effect.catchTag("ParseError", e => SubscriptionRef.set(self.errorRef, Option.some(e)))
),
)
export namespace useInput {
export interface Options {
@@ -139,7 +139,19 @@ export const useInput: {
const [value, setValue] = yield* Hooks.useRefState(internalValueRef)
const [issues] = yield* Hooks.useSubscribables(issuesSubscribable)
yield* Hooks.useFork(() => Stream.runForEach(
yield* Hooks.useFork(() => Effect.all([
Stream.runForEach(
self.encodedValueRef.changes.pipe(
Stream.flatMap(PropertyPath.get(path)),
Stream.drop(1),
),
upstreamEncodedValue => internalValueRef.pipe(
),
),
Stream.runForEach(
internalValueRef.changes.pipe(
Stream.changesWith(Equivalence.strict()),
options?.debounce ? Stream.debounce(options.debounce) : identity,
@@ -150,7 +162,8 @@ export const useInput: {
Effect.andThen(encodedValue => PropertyPath.immutableSet(encodedValue, path, internalValue)),
Effect.andThen(encodedValue => SubscriptionRef.set(self.encodedValueRef, encodedValue)),
),
), [internalValueRef, self, ...path])
),
], { concurrency: "unbounded" }), [internalValueRef, self, ...path])
return { value, setValue, issues }
})