Skip to content

Commit 8b044ff

Browse files
Reduce groceries verbosity (#211)
* reduce groceries verbosity * Clarify why the `HH` prefix is not used Co-authored-by: Jordan Martinez <[email protected]>
1 parent f7afd34 commit 8b044ff

File tree

2 files changed

+45
-35
lines changed

2 files changed

+45
-35
lines changed

recipes/GroceriesHalogenHooks/src/Main.purs

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,44 @@ import Prelude
44
import Data.Maybe (Maybe(..))
55
import Effect (Effect)
66
import Halogen as H
7-
import Halogen.HTML as HH
87
import Halogen.Aff as HA
9-
import Halogen.VDom.Driver (runUI)
8+
import Halogen.HTML (HTML, div_, h1_, li_, text, ul_)
109
import Halogen.Hooks as Hooks
10+
import Halogen.VDom.Driver (runUI)
1111

1212
main :: Effect Unit
1313
main =
1414
HA.runHalogenAff do
1515
body <- HA.awaitBody
1616
void $ runUI hookComponent Nothing body
1717

18-
hookComponent
19-
:: forall unusedQuery unusedInput unusedOutput anyMonad
20-
. H.Component HH.HTML unusedQuery unusedInput unusedOutput anyMonad
21-
hookComponent = Hooks.component \_ _ -> Hooks.do
22-
Hooks.pure $
23-
HH.div_
24-
[ HH.h1_ [ HH.text "My Grocery List" ]
25-
, HH.ul_
26-
[ HH.li_ [ HH.text "Black Beans" ]
27-
, HH.li_ [ HH.text "Limes" ]
28-
, HH.li_ [ HH.text "Greek Yogurt" ]
29-
, HH.li_ [ HH.text "Cilantro" ]
30-
, HH.li_ [ HH.text "Honey" ]
31-
, HH.li_ [ HH.text "Sweet Potatoes" ]
32-
, HH.li_ [ HH.text "Cumin" ]
33-
, HH.li_ [ HH.text "Chili Powder" ]
34-
, HH.li_ [ HH.text "Quinoa" ]
35-
]
36-
]
18+
hookComponent ::
19+
forall unusedQuery unusedInput unusedOutput anyMonad.
20+
H.Component HTML unusedQuery unusedInput unusedOutput anyMonad
21+
hookComponent =
22+
Hooks.component \_ _ -> Hooks.do
23+
Hooks.pure
24+
$ div_
25+
[ h1_ [ text "My Grocery List" ]
26+
, ul_
27+
[ li_ [ text "Black Beans" ]
28+
, li_ [ text "Limes" ]
29+
, li_ [ text "Greek Yogurt" ]
30+
, li_ [ text "Cilantro" ]
31+
, li_ [ text "Honey" ]
32+
, li_ [ text "Sweet Potatoes" ]
33+
, li_ [ text "Cumin" ]
34+
, li_ [ text "Chili Powder" ]
35+
, li_ [ text "Quinoa" ]
36+
]
37+
]
38+
39+
{-
40+
NOTE: Most Halogen codebases will reference HTML tags via an `HH` prefix
41+
(i.e. `HH.div` rather than `div`). The `HH` is from `import Halogen.HTML as HH`.
42+
Most developers _choose_ to use the `HH` prefix, but it is not a requirement
43+
of the language, nor the library.
44+
45+
To decrease verbosity and better compare this code to Elm's code,
46+
the above syntax does not use the `HH` prefix.
47+
-}

recipes/GroceriesReactHooks/src/Main.purs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import Prelude
44
import Data.Maybe (Maybe(..))
55
import Effect (Effect)
66
import Effect.Exception (throw)
7-
import React.Basic.DOM (render)
8-
import React.Basic.DOM as R
7+
import React.Basic.DOM (div_, h1_, li_, render, text, ul_)
98
import React.Basic.Hooks (Component, component)
109
import Web.HTML (window)
1110
import Web.HTML.HTMLDocument (body)
@@ -25,17 +24,17 @@ mkGroceries :: Component {}
2524
mkGroceries = do
2625
component "Groceries" \_ -> React.do
2726
pure
28-
$ R.div_
29-
[ R.h1_ [ R.text "My Grocery List" ]
30-
, R.ul_
31-
[ R.li_ [ R.text "Black Beans" ]
32-
, R.li_ [ R.text "Limes" ]
33-
, R.li_ [ R.text "Greek Yogurt" ]
34-
, R.li_ [ R.text "Cilantro" ]
35-
, R.li_ [ R.text "Honey" ]
36-
, R.li_ [ R.text "Sweet Potatoes" ]
37-
, R.li_ [ R.text "Cumin" ]
38-
, R.li_ [ R.text "Chili Powder" ]
39-
, R.li_ [ R.text "Quinoa" ]
27+
$ div_
28+
[ h1_ [ text "My Grocery List" ]
29+
, ul_
30+
[ li_ [ text "Black Beans" ]
31+
, li_ [ text "Limes" ]
32+
, li_ [ text "Greek Yogurt" ]
33+
, li_ [ text "Cilantro" ]
34+
, li_ [ text "Honey" ]
35+
, li_ [ text "Sweet Potatoes" ]
36+
, li_ [ text "Cumin" ]
37+
, li_ [ text "Chili Powder" ]
38+
, li_ [ text "Quinoa" ]
4039
]
4140
]

0 commit comments

Comments
 (0)