This commit is contained in:
@@ -256,19 +256,19 @@ export namespace useInput {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useInput = Effect.fnUntraced(function* <A, I>(
|
export const useInput = Effect.fnUntraced(function* <P extends readonly PropertyKey[], A, I, ER, EW>(
|
||||||
field: FormField<A, I>,
|
form: Form<P, A, I, ER, EW>,
|
||||||
options?: useInput.Options,
|
options?: useInput.Options,
|
||||||
): Effect.fn.Return<useInput.Success<I>, Cause.NoSuchElementException, Scope.Scope> {
|
): Effect.fn.Return<useInput.Success<I>, ER, Scope.Scope> {
|
||||||
const internalValueLens = yield* Component.useOnChange(() => Effect.gen(function*() {
|
const internalValueLens = yield* Component.useOnChange(() => Effect.gen(function*() {
|
||||||
const internalValueLens = yield* Lens.get(field.encodedValue).pipe(
|
const internalValueLens = yield* Lens.get(form.encodedValue).pipe(
|
||||||
Effect.flatMap(SubscriptionRef.make),
|
Effect.flatMap(SubscriptionRef.make),
|
||||||
Effect.map(Lens.fromSubscriptionRef),
|
Effect.map(Lens.fromSubscriptionRef),
|
||||||
)
|
)
|
||||||
|
|
||||||
yield* Effect.forkScoped(Effect.all([
|
yield* Effect.forkScoped(Effect.all([
|
||||||
Stream.runForEach(
|
Stream.runForEach(
|
||||||
Stream.drop(field.encodedValue.changes, 1),
|
Stream.drop(form.encodedValue.changes, 1),
|
||||||
upstreamEncodedValue => Effect.whenEffect(
|
upstreamEncodedValue => Effect.whenEffect(
|
||||||
Lens.set(internalValueLens, upstreamEncodedValue),
|
Lens.set(internalValueLens, upstreamEncodedValue),
|
||||||
Effect.andThen(Lens.get(internalValueLens), internalValue => !Equal.equals(upstreamEncodedValue, internalValue)),
|
Effect.andThen(Lens.get(internalValueLens), internalValue => !Equal.equals(upstreamEncodedValue, internalValue)),
|
||||||
@@ -281,12 +281,12 @@ export const useInput = Effect.fnUntraced(function* <A, I>(
|
|||||||
Stream.changesWith(Equal.equivalence()),
|
Stream.changesWith(Equal.equivalence()),
|
||||||
options?.debounce ? Stream.debounce(options.debounce) : identity,
|
options?.debounce ? Stream.debounce(options.debounce) : identity,
|
||||||
),
|
),
|
||||||
internalValue => Lens.set(field.encodedValue, internalValue),
|
internalValue => Lens.set(form.encodedValue, internalValue),
|
||||||
),
|
),
|
||||||
], { concurrency: "unbounded" }))
|
], { concurrency: "unbounded" }))
|
||||||
|
|
||||||
return internalValueLens
|
return internalValueLens
|
||||||
}), [field, options?.debounce])
|
}), [form, options?.debounce])
|
||||||
|
|
||||||
const [value, setValue] = yield* Lens.useState(internalValueLens)
|
const [value, setValue] = yield* Lens.useState(internalValueLens)
|
||||||
return { value, setValue }
|
return { value, setValue }
|
||||||
@@ -303,10 +303,10 @@ export namespace useOptionalInput {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useOptionalInput = Effect.fnUntraced(function* <A, I>(
|
export const useOptionalInput = Effect.fnUntraced(function* <P extends readonly PropertyKey[], A, I, ER, EW>(
|
||||||
field: FormField<A, Option.Option<I>>,
|
field: Form<P, A, Option.Option<I>, ER, EW>,
|
||||||
options: useOptionalInput.Options<I>,
|
options: useOptionalInput.Options<I>,
|
||||||
): Effect.fn.Return<useOptionalInput.Success<I>, Cause.NoSuchElementException, Scope.Scope> {
|
): Effect.fn.Return<useOptionalInput.Success<I>, ER, Scope.Scope> {
|
||||||
const [enabledLens, internalValueLens] = yield* Component.useOnChange(() => Effect.gen(function*() {
|
const [enabledLens, internalValueLens] = yield* Component.useOnChange(() => Effect.gen(function*() {
|
||||||
const [enabledLens, internalValueLens] = yield* Effect.flatMap(
|
const [enabledLens, internalValueLens] = yield* Effect.flatMap(
|
||||||
Lens.get(field.encodedValue),
|
Lens.get(field.encodedValue),
|
||||||
|
|||||||
Reference in New Issue
Block a user