Created
August 10, 2018 15:42
-
-
Save stevekrouse/5d763977c620c590d9f3434231348c76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main exposing (main) | |
import Html exposing (Html, button, div, text) | |
import Html.Events exposing (onClick) | |
type alias Model = | |
{ count : Int } | |
initialModel : Model | |
initialModel = | |
{ count = 0 } | |
type Msg | |
= Increment | |
| Decrement | |
update : Msg -> Model -> Model | |
update msg model = | |
case msg of | |
Increment -> | |
{ model | count = model.count + 1 } | |
Decrement -> | |
{ model | count = model.count - 1 } | |
view : Model -> Html Msg | |
view model = | |
div [] | |
[ button [ onClick Increment ] [ text "+1" ] | |
, div [] [ text <| toString model.count ] | |
, button [ onClick Decrement ] [ text "-1" ] | |
] | |
main : Program Never Model Msg | |
main = | |
Html.beginnerProgram | |
{ model = initialModel | |
, view = view | |
, update = update | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment