halogen-websocket-ipc-playzone/src/Main.purs

48 lines
1.0 KiB
Plaintext
Raw Normal View History

2016-01-18 22:17:22 +01:00
module Main where
import Prelude
import Control.Monad.Eff (Eff)
2016-01-18 22:17:22 +01: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 }
ui :: forall g. H.Component State Query g
ui = H.component { render, eval }
2016-01-18 22:17:22 +01:00
where
render :: State -> H.ComponentHTML Query
2016-01-18 22:17:22 +01:00
render state =
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!"
]
]
eval :: Query ~> H.ComponentDSL State Query g
2016-01-18 22:17:22 +01:00
eval (ToggleState next) = do
H.modify (\state -> { on: not state.on })
2016-01-18 22:17:22 +01:00
pure next
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
H.runUI ui initialState body