Skip to content

Instantly share code, notes, and snippets.

@homam
Created September 5, 2015 18:08
Show Gist options
  • Select an option

  • Save homam/cffd9e2694bcf0c66a19 to your computer and use it in GitHub Desktop.

Select an option

Save homam/cffd9e2694bcf0c66a19 to your computer and use it in GitHub Desktop.
import Html exposing (div, button, text, Attribute)
import Html.Events exposing (onClick)
import Html.Attributes exposing (style)
import StartApp.Simple as StartApp
{-| Read more about StartApp and how this works at:
https://github.com/evancz/start-app
The rough idea is that we just specify a model, a way to view it,
and a way to update it. That's all there is to it!
-}
main =
StartApp.start { model = 0, view = view, update = update }
view : Signal.Address Action -> Model -> Html.Html
view address model =
div []
[ button [ onClick address Decrement ] [ text "-" ]
, div [ countStyle ] [ text (toString model) ]
, button [ onClick address Increment ] [ text "+" ]
]
type Action = Increment | Decrement
type alias Model = Int
update : Action -> Model -> Model
update action model =
case action of
Increment -> model + 1
Decrement -> model - 1
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