Skip to content

Instantly share code, notes, and snippets.

@franzejr
Created March 6, 2016 03:21
Show Gist options
  • Save franzejr/22dd23b89c9583e026aa to your computer and use it in GitHub Desktop.
Save franzejr/22dd23b89c9583e026aa to your computer and use it in GitHub Desktop.
Counter Elm
module Counter where
import Html exposing (..)
import Html.Attributes exposing (style)
import Html.Events exposing (onClick)
-- MODEL
type alias Model = Int
-- UPDATE
type Action = Increment | Decrement
update : Action -> Model -> Model
update action model =
case action of
Increment ->
model + 1
Decrement ->
model - 1
-- VIEW
view : Signal.Address Action -> Model -> Html
view address model =
div []
[ button [ onClick address Decrement ] [ text "-" ]
, div [ countStyle ] [ text (toString model) ]
, button [ onClick address Increment ] [ text "+" ]
]
countStyle : Attribute
countStyle =
style
[ ("font-size", "20px")
, ("font-family", "monospace")
, ("display", "inline-block")
, ("width", "50px")
, ("text-align", "center")
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment