Last active
December 8, 2016 00:02
-
-
Save countingtoten/f554350b82c8717a0822fdcaf40d6b0b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 (..) | |
import Html exposing (..) | |
import Html.Events exposing(onClick) | |
type alias Model = { incr: Int, decr: Int, value: Int } | |
type Msg = Increment | Decrement | |
update : Msg -> Model -> Model | |
update msg model = | |
case msg of | |
Increment -> {model | incr = model.incr + 1, value = model.value + 1} | |
Decrement -> {model | decr = model.decr + 1, value = model.value - 1} | |
view : Model -> Html Msg | |
view model = | |
div [] | |
[ button [onClick Decrement] [ text "-" ] | |
, div [] [ text (toString model.value) ] | |
, button [onClick Increment] [ text "+" ] | |
, h2 [] [ text (String.join " " ["Decremented", (toString model.decr), "times"]) ] | |
, h2 [] [ text (String.join " " ["Incremented", (toString model.incr), "times"]) ] | |
] | |
main : Program Never { decr : Int, incr : Int, value : Int } Msg | |
main = | |
Html.beginnerProgram | |
{ model = {incr = 0, decr = 0, value = 0} | |
, view = view | |
, update = update | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment