-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to generate a record of symbol proxies for large forms (#13)
* First cut at generating proxies * Remove duplicate code. * Generating symbol proxies * Other versions... * Added ability to generate symbol proxies for particularly large forms.
- Loading branch information
1 parent
dc87a1e
commit f3a24b8
Showing
15 changed files
with
164 additions
and
122 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ import Prelude | |
import Effect.Aff (Aff) | ||
import Example.App.UI.Element as UI | ||
import Example.App.UI.Typeahead as TA | ||
import Example.ExternalComponents.Spec (Form, User, _email, _language, _name, _whiskey) | ||
import Example.ExternalComponents.Spec (Form, User, proxies) | ||
import Example.ExternalComponents.Types (Query(..), Slot(..)) | ||
import Formless as F | ||
import Halogen as H | ||
|
@@ -21,7 +21,7 @@ formless state = | |
{ label: "Name" | ||
, help: "Write your name" | ||
, placeholder: "Dale" | ||
, sym: _name | ||
, sym: proxies.name | ||
} state | ||
, email state | ||
, whiskey state | ||
|
@@ -55,7 +55,7 @@ email :: F.State Form User Aff -> F.HTML Query (TA.Query String) Slot Form User | |
email state = | ||
UI.field | ||
{ label: "Email" | ||
, help: UI.resultToHelp "Choose an email address -- carefully." (F.getResult _email state.form) | ||
, help: UI.resultToHelp "Choose an email address -- carefully." (F.getResult proxies.email state.form) | ||
} | ||
[ HH.slot Email TA.single | ||
{ placeholder: "[email protected]" | ||
|
@@ -74,7 +74,7 @@ whiskey :: F.State Form User Aff -> F.HTML Query (TA.Query String) Slot Form Use | |
whiskey state = | ||
UI.field | ||
{ label: "Whiskey" | ||
, help: UI.resultToHelp "Select a favorite whiskey" (F.getResult _whiskey state.form) | ||
, help: UI.resultToHelp "Select a favorite whiskey" (F.getResult proxies.whiskey state.form) | ||
} | ||
[ HH.slot Whiskey TA.single | ||
{ placeholder: "Lagavulin 12" | ||
|
@@ -92,7 +92,7 @@ language :: F.State Form User Aff -> F.HTML Query (TA.Query String) Slot Form Us | |
language state = | ||
UI.field | ||
{ label: "Language" | ||
, help: UI.resultToHelp "Choose your favorite programming language." (F.getResult _language state.form) | ||
, help: UI.resultToHelp "Choose your favorite programming language." (F.getResult proxies.language state.form) | ||
} | ||
[ HH.slot Language TA.single | ||
{ placeholder: "Haskell" | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,13 @@ module Example.Polyform.Component where | |
|
||
import Prelude | ||
|
||
import Example.App.UI.Element as UI | ||
import Data.Maybe (Maybe(..)) | ||
import Data.Newtype (class Newtype) | ||
import Data.Symbol (SProxy(..)) | ||
import Effect.Aff (Aff) | ||
import Effect.Class (class MonadEffect) | ||
import Effect.Console as Console | ||
import Example.App.UI.Element as UI | ||
import Example.App.Validation as V | ||
import Formless as F | ||
import Formless.Validation.Polyform (applyOnInputFields) | ||
|
@@ -18,7 +18,6 @@ import Halogen.HTML.Events as HE | |
import Halogen.HTML.Properties as HP | ||
import Polyform.Validation as Validation | ||
import Record (delete) | ||
import Type.Row (RProxy(..)) | ||
|
||
data Query a = HandleFormless (F.Message' Form User) a | ||
|
||
|
@@ -72,7 +71,7 @@ component = | |
, HH.slot | ||
unit | ||
F.component | ||
{ formSpec: F.mkFormSpecFromRow $ RProxy :: RProxy (FormRow F.InputType) | ||
{ formSpec: F.mkFormSpecFromProxy _form | ||
, validator | ||
, submitter: pure <<< F.unwrapOutput | ||
, render: renderFormless | ||
|
@@ -84,23 +83,29 @@ component = | |
---------- | ||
-- Formless | ||
|
||
-- We can recover both our user type and our form from the same row. | ||
type User = Record (FormRow F.OutputType) | ||
|
||
newtype Form f = Form (Record (FormRow f)) | ||
derive instance newtypeForm :: Newtype (Form f) _ | ||
|
||
-- This proxy will let us generate all the SProxies for our form as | ||
-- well as our entire initial form. | ||
_form = F.FormProxy :: F.FormProxy Form | ||
|
||
-- This is a record of symbol proxies, which we can now pass to the | ||
-- various Formless functions that require them. See the render function | ||
-- below as an example in practice. | ||
proxies :: F.SProxies Form | ||
proxies = F.mkSProxies _form | ||
|
||
type FormRow f = | ||
( name :: f V.Errs String V.Name | ||
, email :: f V.Errs String V.Email | ||
, city :: f V.Errs String String | ||
, state :: f V.Errs String String | ||
) | ||
|
||
_name = SProxy :: SProxy "name" | ||
_email = SProxy :: SProxy "email" | ||
_city = SProxy :: SProxy "city" | ||
_state = SProxy :: SProxy "state" | ||
|
||
validator :: ∀ m. MonadEffect m => Form F.InputField -> m (Form F.InputField) | ||
validator = applyOnInputFields | ||
{ name: V.Name <$> (V.minLength 5 *> V.maxLength 10) | ||
|
@@ -117,28 +122,28 @@ renderFormless state = | |
{ label: "Name" | ||
, help: "Write your name" | ||
, placeholder: "Dale" | ||
, sym: _name | ||
, sym: proxies.name | ||
} state | ||
, UI.formlessField | ||
UI.input | ||
{ label: "Email Address" | ||
, help: "Write your email" | ||
, placeholder: "[email protected]" | ||
, sym: _email | ||
, sym: proxies.email | ||
} state | ||
, UI.formlessField | ||
UI.input | ||
{ label: "City" | ||
, help: "Write your favorite city" | ||
, placeholder: "Los Angeles" | ||
, sym: _city | ||
, sym: proxies.city | ||
} state | ||
, UI.formlessField | ||
UI.input | ||
{ label: "State" | ||
, help: "Write your favorite state of mind" | ||
, placeholder: "" | ||
, sym: _state | ||
, sym: proxies.state | ||
} state | ||
, HH.br_ | ||
, UI.p_ $ | ||
|
@@ -162,3 +167,4 @@ renderFormless state = | |
[ HH.text "Reset" ] | ||
] | ||
] | ||
|
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
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
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
Oops, something went wrong.