Skip to content

Instantly share code, notes, and snippets.

@Fresheyeball

Fresheyeball/Shpa.hs

Forked from abradley2/Shpa.hs
Last active Aug 26, 2020
Embed
What would you like to do?
Being silly with Shpadoinkle
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Text
import Shpadoinkle as S
import Shpadoinkle.Backend.ParDiff
import Shpadoinkle.Html as H
newtype Count = Count { unCount :: Int } deriving (Eq, Ord, Num, Show)
newtype InputText = InputText { unInputText :: Text } deriving (Eq, Show)
data Model = Model
{ currentCount :: Count
, inputText :: InputText
}
deriving (Eq, Show)
initialModel :: Model
initialModel = Model (Count 0) (InputText "Hello There")
counter :: Count -> Html Count
counter model =
H.div
[]
[ H.button
[ onClick $ model - 1
]
[ S.text "--"
]
, H.button
[ onClick $ model + 1
]
[ S.text "++"
]
, H.h3
[]
[ S.text $ pack . show . unCount $ model
]
]
view :: Model -> Html Model
view model =
H.div
[]
[ H.input
[ type' "text"
, H.onInput $ (\t -> model { inputText = InputText t })
]
[]
, H.h3 [] [ S.text $ unInputText . inputText $ model ]
, (\c -> model { currentCount = c } )
<$> counter (currentCount model)
, if currentCount model > 10 then
H.h3
[]
[ S.text "You're good at counting!" ]
else
H.p
[]
[ S.text "Not there yet"]
]
main :: IO ()
main = runJSorWarp 8080 $
simple runParDiff initialModel (constly' . view) getBody
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.