50 lines
1.2 KiB
Plaintext
50 lines
1.2 KiB
Plaintext
module Main where
|
|
|
|
import Prelude
|
|
|
|
import Control.Monad.Aff (runAff)
|
|
import Control.Monad.Eff (Eff())
|
|
import Control.Monad.Eff.Exception (throwException)
|
|
|
|
import Halogen
|
|
import Halogen.Util (appendToBody, onLoad)
|
|
import qualified Halogen.HTML.Indexed as H
|
|
import qualified Halogen.HTML.Events.Indexed as E
|
|
|
|
data Query a = ToggleState a
|
|
|
|
type State = { on :: Boolean }
|
|
|
|
initialState :: State
|
|
initialState = { on: false }
|
|
|
|
ui :: forall g. (Functor g) => Component State Query g
|
|
ui = component render eval
|
|
where
|
|
|
|
render :: State -> ComponentHTML Query
|
|
render state =
|
|
H.div_
|
|
[ H.h1_
|
|
[ H.text "Hello world!" ]
|
|
, H.p_
|
|
[ H.text "Why not toggle this button:" ]
|
|
, H.button
|
|
[ E.onClick (E.input_ ToggleState) ]
|
|
[ H.text
|
|
if not state.on
|
|
then "Don't push me"
|
|
else "I said don't push me!"
|
|
]
|
|
]
|
|
|
|
eval :: Natural Query (ComponentDSL State Query g)
|
|
eval (ToggleState next) = do
|
|
modify (\state -> { on: not state.on })
|
|
pure next
|
|
|
|
main :: Eff (HalogenEffects ()) Unit
|
|
main = runAff throwException (const (pure unit)) $ do
|
|
app <- runUI ui initialState
|
|
onLoad $ appendToBody app.node
|