Refactor Form
Some checks failed
Lint / lint (push) Failing after 14s

This commit is contained in:
Julien Valverdé
2026-03-28 11:32:15 +01:00
parent 5f8965ce11
commit 8cc8aa4b56
4 changed files with 48 additions and 29 deletions

View File

@@ -46,6 +46,6 @@
"react": "^19.2.0"
},
"dependencies": {
"effect-lens": "^0.1.1"
"effect-lens": "^0.1.2"
}
}

View File

@@ -232,7 +232,26 @@ export const service = <A, I = A, R = never, MA = void, ME = never, MR = never,
form => Effect.forkScoped(form.run),
)
export const focusObjectField = <P extends readonly PropertyKey[], A extends object, I extends object, ER, EW, K extends keyof A & keyof I>(
self: Form<P, A, I, ER, EW>,
key: K,
): Form<readonly [...P, K], A[K], I[K], ER, EW> => {
const form = self as FormImpl<P, A, I, ER, EW>
const path = [...form.path, key] as const
return new FormImpl(
path,
Lens.map(
form.value,
a => Option.map(a, v => v[key]),
(a, b) => Option.map(),
),
Lens.focusObjectField(form.encodedValue, key),
form.error,
form.validationFiber,
form.canSubmit,
)
}
export namespace useInput {