Skip to content

Instantly share code, notes, and snippets.

@ggpasqualino
Last active September 9, 2016 09:32
Show Gist options
  • Save ggpasqualino/d57e43fcb5f42ef187498f8111cf5764 to your computer and use it in GitHub Desktop.
Save ggpasqualino/d57e43fcb5f42ef187498f8111cf5764 to your computer and use it in GitHub Desktop.
exercise from daily drip made in the dev meeting
import Html exposing (..)
import Html.Events exposing (onClick)
import Html.App exposing (beginnerProgram)
type Msg
= Increment
| Decrement
type alias Model =
{ actual : Int
, increasedCounter : Int
, decreasedCounter : Int
}
initModel : Model
initModel =
{ actual = 0, increasedCounter = 0, decreasedCounter = 0 }
update : Msg -> Model -> Model
update msg model =
case msg of
Increment ->
{ model
| actual = model.actual + 1
, increasedCounter = model.increasedCounter + 1
}
Decrement ->
{ model
| actual = model.actual - 1
, decreasedCounter = model.decreasedCounter + 1
}
view : Model -> Html Msg
view model =
div []
[ h3 [] [ text (toString model.increasedCounter) ]
, h3 [] [ text (toString model.decreasedCounter) ]
, button [ onClick Increment ] [ text "+" ]
, div [] [ text (toString model.actual) ]
, button [ onClick Decrement ] [ text "-" ]
]
main =
beginnerProgram { model = initModel, view = view, update = update }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment