Created
May 2, 2018 08:22
-
-
Save iwillspeak/57596ba85fe7ae5744c1b8d089765e11 to your computer and use it in GitHub Desktop.
Simple Elm Counter
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
import Html exposing (..) | |
import Html.Attributes exposing (..) | |
import Html.Events exposing (..) | |
main = Html.beginnerProgram { model = model, view = view, update = update } | |
--- MODEL | |
type alias Model = Int | |
model : Model | |
model = | |
0 | |
-- UPDATE | |
type Msg = Increment | Decrement | Reset | |
update : Msg -> Model -> Model | |
update msg model = | |
case msg of | |
Increment -> model + 1 | |
Decrement -> model - 1 | |
Reset -> 0 | |
-- VIEW | |
view : Model -> Html Msg | |
view model = | |
p [] | |
[ button [ onClick Decrement ] [ text "<" ] | |
, span [] [ text (toString model) ] | |
, button [ onClick Increment ] [ text ">" ] | |
, button [ onClick Reset, disabled (model == 0) ] [ text "Reset" ] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment