-
-
Save natefaubion/ab4d4fc31f3dee721fefea18578488fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- A `Form` encapsulates some input of type `a`. A `Form` will likely bundle | |
-- up an Eq dictionary for `a` as you'll likely need to compare form values | |
-- for equality. It'll also bundle up a validator perhaps. Likely should be | |
-- an invariant functor. | |
data Form a | |
-- A `FormSet` is a mapping of labels to `Form` values. | |
data FormSet (fields :: # Type) | |
-- The initial empty `FormSet`. | |
formSet :: FormSet () | |
-- Terminal tranformation which seals the `FormSet`, yield a Form that | |
-- works on records. | |
toForm :: forall r. FormSet r -> Form (Record r) | |
-- Associates a type-level label with some `Form` in a `FormSet`. | |
row | |
:: forall sym r1 r2 a | |
. IsSymbol sym | |
=> RowCons sym a r1 r2 | |
=> SProxy sym | |
-> Form a | |
-> FormSet r1 | |
-> FormSet r2 | |
-- Some simple bare-bones inputs. In a real API they might take options | |
-- for rendered labels, help text, etc. | |
textInput :: Form String | |
emailInput :: Form Email | |
checkInput :: Form Boolean | |
myForm :: Form { name :: String, email :: Email, subscribed :: Boolean } | |
myForm = | |
formSet | |
# row (SProxy :: SPoxy "name") textInput | |
# row (SProxy :: SProxy "email") emailInput | |
# row (SProxy :: SProxy "subscribe") checkInput | |
# toForm | |
data FormQuery a | |
-- Turns a Form into a component that takes values, and yields new values. | |
-- Might also yield validation messages in a different Message. | |
toComponent :: forall m a. Form a -> H.Component H.HTML FormQuery a a m |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment