No title

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import Control.Monad.Aff (Aff)

import Halogen as H
import Halogen.HTML as HH
import Halogen.HTML.Events as HE

data Query a = ToggleState a

type State = { uuid :: Int }

type ComponentEff eff = Aff (random :: RAND.RANDOM | eff )

component :: forall m. H.Component HH.HTML Query Unit Void (ComponentEff m)
component =
  H.component
    { initialState: const initialState
    , render
    , eval
    , receiver: const Nothing
    }
  where

  initialState :: State
  initialState = { uuid: 0 }

  render :: State -> H.ComponentHTML Query
  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 (show state.uuid) ]
      ]

  eval :: Query ~> H.ComponentDSL State Query Void (ComponentEff m)
  eval (ToggleState next) = do
      r <- (RAND.randomInt 1 10)
      H.modify (\state -> { uuid: r })
      pure next