2016-01-18 22:17:22 +01:00
|
|
|
module Main where
|
|
|
|
|
|
|
|
import Prelude
|
|
|
|
|
2016-06-25 19:34:02 +02:00
|
|
|
import Control.Monad.Eff (Eff)
|
2016-01-18 22:17:22 +01:00
|
|
|
|
2016-06-25 19:34:02 +02:00
|
|
|
import Halogen as H
|
|
|
|
import Halogen.HTML.Events.Indexed as HE
|
|
|
|
import Halogen.HTML.Indexed as HH
|
2016-03-24 18:22:10 +01:00
|
|
|
import Halogen.Util (awaitBody, runHalogenAff)
|
2016-01-18 22:17:22 +01:00
|
|
|
|
|
|
|
data Query a = ToggleState a
|
|
|
|
|
|
|
|
type State = { on :: Boolean }
|
|
|
|
|
|
|
|
initialState :: State
|
|
|
|
initialState = { on: false }
|
|
|
|
|
2016-06-25 19:34:02 +02:00
|
|
|
ui :: forall g. H.Component State Query g
|
|
|
|
ui = H.component { render, eval }
|
2016-01-18 22:17:22 +01:00
|
|
|
where
|
|
|
|
|
2016-06-25 19:34:02 +02:00
|
|
|
render :: State -> H.ComponentHTML Query
|
2016-01-18 22:17:22 +01:00
|
|
|
render state =
|
2016-06-25 19:34:02 +02:00
|
|
|
HH.div_
|
|
|
|
[ HH.h1_
|
|
|
|
[ HH.text "Hello world!" ]
|
|
|
|
, HH.p_
|
|
|
|
[ HH.text "Why not toggle this button:" ]
|
|
|
|
, HH.button
|
|
|
|
[ HE.onClick (HE.input_ ToggleState) ]
|
|
|
|
[ HH.text
|
2016-01-18 22:17:22 +01:00
|
|
|
if not state.on
|
|
|
|
then "Don't push me"
|
|
|
|
else "I said don't push me!"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
2016-06-25 19:34:02 +02:00
|
|
|
eval :: Query ~> H.ComponentDSL State Query g
|
2016-01-18 22:17:22 +01:00
|
|
|
eval (ToggleState next) = do
|
2016-06-25 19:34:02 +02:00
|
|
|
H.modify (\state -> { on: not state.on })
|
2016-01-18 22:17:22 +01:00
|
|
|
pure next
|
|
|
|
|
2016-06-25 19:34:02 +02:00
|
|
|
main :: Eff (H.HalogenEffects ()) Unit
|
2016-03-24 18:22:10 +01:00
|
|
|
main = runHalogenAff do
|
2016-03-24 17:48:29 +01:00
|
|
|
body <- awaitBody
|
2016-06-25 19:34:02 +02:00
|
|
|
H.runUI ui initialState body
|