Skip to content

Instantly share code, notes, and snippets.

@CliffordAnderson
Last active July 27, 2017 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save CliffordAnderson/972907dc8c98b954290723bc68de5fd6 to your computer and use it in GitHub Desktop.
Save CliffordAnderson/972907dc8c98b954290723bc68de5fd6 to your computer and use it in GitHub Desktop.
Elm Counter Example
module Main exposing (..)
import Html exposing (br, button, div, text)
import Html.Events exposing (onClick)
import Html.App exposing (beginnerProgram)
main : Program Never
main =
beginnerProgram { model = model, view = view, update = update }
type Msg
= Increment
| Decrement
model : Int
model =
0
view : Int -> Html.Html Msg
view model =
div []
[ button [ onClick Increment ] [ text "+" ]
, br [] []
, text (toString model)
, br [] []
, button [ onClick Decrement ] [ text "-" ]
]
update : Msg -> Int -> Int
update msg model =
case msg of
Increment ->
model + 1
Decrement ->
model - 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment