Skip to content

Instantly share code, notes, and snippets.

@MarkNijhof
Forked from CliffordAnderson/counter.elm
Created December 20, 2016 02:45
Show Gist options
  • Save MarkNijhof/a52f4359a7ade6fb086eecc8df752cb1 to your computer and use it in GitHub Desktop.
Save MarkNijhof/a52f4359a7ade6fb086eecc8df752cb1 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