0.1.4 #5
@@ -155,20 +155,14 @@ const run = <A, I, R, SA, SE, SR>(self: Form<A, I, R, SA, SE, SR>) => Stream.run
|
||||
)
|
||||
|
||||
|
||||
export const field: {
|
||||
<A, I, R, SA, SE, SR, const P extends PropertyPath.Paths<NoInfer<I>>>(
|
||||
export const field = <A, I, R, SA, SE, SR, const P extends PropertyPath.Paths<NoInfer<I>>>(
|
||||
self: Form<A, I, R, SA, SE, SR>,
|
||||
path: P,
|
||||
): Effect.Effect<FormField<PropertyPath.ValueFromPath<A, P>, PropertyPath.ValueFromPath<I, P>>>
|
||||
} = Effect.fnUntraced(function* <A, I, R, SA, SE, SR, const P extends PropertyPath.Paths<NoInfer<I>>>(
|
||||
self: Form<A, I, R, SA, SE, SR>,
|
||||
path: P,
|
||||
) {
|
||||
return new FormFieldImpl(
|
||||
): FormField<PropertyPath.ValueFromPath<A, P>, PropertyPath.ValueFromPath<I, P>> => new FormFieldImpl(
|
||||
pipe(
|
||||
(v: Option.Option<A>) => Option.match(v, {
|
||||
onSome: PropertyPath.get(path),
|
||||
onNone: () => Option.none(),
|
||||
Option.match({
|
||||
onSome: (v: A) => Option.map(PropertyPath.get(v, path), Option.some),
|
||||
onNone: () => Option.some(Option.none()),
|
||||
}),
|
||||
filter => SubscribableInternal.make({
|
||||
get: Effect.flatMap(self.valueRef, filter),
|
||||
@@ -202,7 +196,14 @@ export const field: {
|
||||
}),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
export const useField = <A, I, R, SA, SE, SR, const P extends PropertyPath.Paths<NoInfer<I>>>(
|
||||
self: Form<A, I, R, SA, SE, SR>,
|
||||
path: P,
|
||||
): FormField<PropertyPath.ValueFromPath<A, P>, PropertyPath.ValueFromPath<I, P>> => React.useMemo(
|
||||
() => field(self, path),
|
||||
[self, ...path],
|
||||
)
|
||||
|
||||
|
||||
export namespace useInput {
|
||||
|
||||
@@ -25,13 +25,16 @@ class RegisterForm extends Effect.Service<RegisterForm>()("RegisterForm", {
|
||||
scoped: Form.service({
|
||||
schema: RegisterFormSchema,
|
||||
initialEncodedValue: { email: "", password: "" },
|
||||
submit: () => Effect.void,
|
||||
})
|
||||
}) {}
|
||||
|
||||
class RegisterPage extends Component.makeUntraced("RegisterPage")(function*() {
|
||||
const form = yield* RegisterForm
|
||||
const emailInput = yield* Form.useInput(form, ["email"], { debounce: "200 millis" })
|
||||
const passwordInput = yield* Form.useInput(form, ["password"], { debounce: "200 millis" })
|
||||
const emailField = Form.useField(form, ["email"])
|
||||
const passwordField = Form.useField(form, ["password"])
|
||||
const emailInput = yield* Form.useInput(emailField, { debounce: "200 millis" })
|
||||
const passwordInput = yield* Form.useInput(passwordField, { debounce: "200 millis" })
|
||||
|
||||
const [canSubmit] = yield* useSubscribables(form.canSubmitSubscribable)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user