Skip to content

Instantly share code, notes, and snippets.

@derekdreery
Last active November 27, 2016 15:51
Show Gist options
  • Save derekdreery/39e9ea9e1a3330edfce7120769519c61 to your computer and use it in GitHub Desktop.
Save derekdreery/39e9ea9e1a3330edfce7120769519c61 to your computer and use it in GitHub Desktop.
import Html
import Html.Events as HtmlEvt
main =
Html.beginnerProgram
{ model = init
, view = view
, update = update
}
-- Model
type alias Model = Int
init : Model
init =
0
-- UPDATE
type Msg = Increment | Decrement
update : Msg -> Model -> Model
update msg model =
case msg of
Increment ->
model + 1
Decrement ->
model - 1
-- VIEW
view : Model -> Html.Html Msg
view model =
Html.div []
[ Html.button [ HtmlEvt.onClick Decrement ] [ Html.text "-" ]
, Html.div [] [ Html.text (toString model) ]
, Html.button [ HtmlEvt.onClick Increment ] [ Html.text "+" ]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment