Report a paste

Please put a quick comment for the admin.

If it looks like spam, the admin will mark it as spam so that the spam filter picks it up in the future.

If the paste contains something private or offensive, it'll probably just be deleted.

No title

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