Skip to content

Instantly share code, notes, and snippets.

@jwthomp
Created May 10, 2016 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwthomp/5b48caa0516cc20a1df22f09eb73f8e6 to your computer and use it in GitHub Desktop.
Save jwthomp/5b48caa0516cc20a1df22f09eb73f8e6 to your computer and use it in GitHub Desktop.
import Html exposing (..)
import Html.Attributes exposing (style)
import Html.Events exposing (onClick)
import Html.App
type alias Model = Int
type Msg = Increment | Decrement
update : Msg -> Model -> Model
update msg model =
case msg of
Increment -> model + 1
Decrement -> model - 1
view : Model -> Html Msg
view model =
div []
[ button [ onClick Decrement ] [ text "-" ],
div [ countStyle ] [ text (toString model) ],
button [ onClick Increment ] [ text "+" ]
]
countStyle : Attribute msg
countStyle =
style
[ ("font-size", "20px"),
("font-family", "monospace"),
("display", "inline-block"),
("width", "50px"),
("text-align", "center")
]
main =
Html.App.beginnerProgram
{ model = 0,
update = update,
view = view
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment