Skip to content

Instantly share code, notes, and snippets.

@haikyuu
Created November 4, 2017 21:14
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 haikyuu/abd1145667e02aee2332d55e0d99bd33 to your computer and use it in GitHub Desktop.
Save haikyuu/abd1145667e02aee2332d55e0d99bd33 to your computer and use it in GitHub Desktop.
Elm counter example
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
main =
Html.beginnerProgram
{ model = model
, view = view
, update = update
}
-- MODEL
type alias Model = Int
model : Model
model =
0
-- UPDATE
type Msg
= Increment
| Decrement
update : Msg -> Model -> Model
update msg model =
case msg of
Increment ->
model + 1
Decrement ->
model - 1
-- VIEW
view : Model -> Html Msg
view model =
div []
[ button [ onClick Decrement ] [ text "-" ]
, div [] [ text (toString model) ]
, button [ onClick Increment ] [ text "+" ]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment