Skip to content

Instantly share code, notes, and snippets.

@countingtoten
Last active December 8, 2016 00:02
Show Gist options
  • Save countingtoten/f554350b82c8717a0822fdcaf40d6b0b to your computer and use it in GitHub Desktop.
Save countingtoten/f554350b82c8717a0822fdcaf40d6b0b to your computer and use it in GitHub Desktop.
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