Skip to content

Instantly share code, notes, and snippets.

@freeman42x
Created October 19, 2019 17:47
Show Gist options
  • Save freeman42x/913c1e1c2a12ebd33eb33e6efb55dafe to your computer and use it in GitHub Desktop.
Save freeman42x/913c1e1c2a12ebd33eb33e6efb55dafe to your computer and use it in GitHub Desktop.
reading radio button state
-- | Haskell language pragma
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
-- | Haskell module declaration
module Main where
-- | Miso framework import
import Miso
import Miso.String
import Language.Javascript.JSaddle.Warp as JSaddle
import Control.Monad.IO.Class (liftIO)
-- | Type synonym for an application model
type Model = Int
-- | Sum type for application events
data Action
= NoOp
| Install
deriving (Show, Eq)
-- | Entry point for a miso application
main :: IO ()
main = JSaddle.run 8080 $ startApp App {..}
where
initialAction = NoOp -- initial action to be executed on application load
model = 0 -- initial model
update = updateModel -- update function
view = viewModel -- view function
events = defaultEvents -- default delegated events
subs = [] -- empty subscription list
mountPoint = Nothing -- mount point for application (Nothing defaults to 'body')
-- | Updates model, optionally introduces side effects
updateModel :: Action -> Model -> Effect Action Model
updateModel NoOp m = noEff m
updateModel Install m = m <# do
liftIO (putStrLn "Hello World") >> pure NoOp
-- | Constructs a virtual DOM from a model
viewModel :: Model -> View Action
viewModel x = div_ [] [
label_ [] [ text "Editor / IDE" ]
, br_ []
, label_ [] [ text "Atom" ]
, input_ [ type_ "radio", name_ "editor", value_ "Atom" ]
, label_ [] [ text "Visual Studio Code" ]
, input_ [ type_ "radio", name_ "editor", value_ "VSCode", disabled_ True ]
, br_ []
, text (ms x)
, button_ [ onClick Install ] [ text "Install" ]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment