0.1.4 #5

Merged
Thilawyn merged 67 commits from next into master 2025-10-02 18:18:23 +02:00
2 changed files with 48 additions and 44 deletions
Showing only changes of commit ef042ed4b1 - Show all commits

View File

@@ -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: { export const field = <A, I, R, SA, SE, SR, const P extends PropertyPath.Paths<NoInfer<I>>>(
<A, I, R, SA, SE, SR, const P extends PropertyPath.Paths<NoInfer<I>>>(
self: Form<A, I, R, SA, SE, SR>, self: Form<A, I, R, SA, SE, SR>,
path: P, path: P,
): Effect.Effect<FormField<PropertyPath.ValueFromPath<A, P>, PropertyPath.ValueFromPath<I, P>>> ): FormField<PropertyPath.ValueFromPath<A, P>, PropertyPath.ValueFromPath<I, P>> => new FormFieldImpl(
} = 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(
pipe( pipe(
(v: Option.Option<A>) => Option.match(v, { Option.match({
onSome: PropertyPath.get(path), onSome: (v: A) => Option.map(PropertyPath.get(v, path), Option.some),
onNone: () => Option.none(), onNone: () => Option.some(Option.none()),
}), }),
filter => SubscribableInternal.make({ filter => SubscribableInternal.make({
get: Effect.flatMap(self.valueRef, filter), 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 { export namespace useInput {

View File

@@ -25,13 +25,16 @@ class RegisterForm extends Effect.Service<RegisterForm>()("RegisterForm", {
scoped: Form.service({ scoped: Form.service({
schema: RegisterFormSchema, schema: RegisterFormSchema,
initialEncodedValue: { email: "", password: "" }, initialEncodedValue: { email: "", password: "" },
submit: () => Effect.void,
}) })
}) {} }) {}
class RegisterPage extends Component.makeUntraced("RegisterPage")(function*() { class RegisterPage extends Component.makeUntraced("RegisterPage")(function*() {
const form = yield* RegisterForm const form = yield* RegisterForm
const emailInput = yield* Form.useInput(form, ["email"], { debounce: "200 millis" }) const emailField = Form.useField(form, ["email"])
const passwordInput = yield* Form.useInput(form, ["password"], { debounce: "200 millis" }) 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) const [canSubmit] = yield* useSubscribables(form.canSubmitSubscribable)