Skip to content

Instantly share code, notes, and snippets.

@jesperp
Last active July 21, 2016 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesperp/8a3f691f1ed70de8fd317497278b1f5f to your computer and use it in GitHub Desktop.
Save jesperp/8a3f691f1ed70de8fd317497278b1f5f to your computer and use it in GitHub Desktop.
import Html
import Html.App
import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
type alias Model = Int
type Msg = Increment | Decrement | Reset | Set Int
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
Increment -> (model + 1, Cmd.none)
Decrement -> (model - 1, Cmd.none)
Set value -> (value, Cmd.none)
Reset -> (0, Cmd.none)
view : Model -> Html.Html Msg
view model =
Html.div
[]
[ Html.h1 [] [Html.text <| toString model]
, Html.br [] []
, Html.button [onClick Increment] [Html.text "Increment"]
, Html.button [onClick Decrement] [Html.text "Decrement"]
, Html.button [onClick Reset] [Html.text "Reset"]
]
main : Program Never
main =
Html.App.program
{ init = (0, Cmd.none)
, subscriptions = (\_ -> Sub.none)
, update = update
, view = view
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment