Created
May 2, 2016 23:49
-
-
Save benjamintanweihao/d7b24778e202f6beec7b86120fc6860e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Counter (..) where | |
| import Html exposing (..) | |
| import Html.Events exposing (..) | |
| import StartApp.Simple exposing (start) | |
| -- MODEL | |
| type alias Model = | |
| Int | |
| init : Model | |
| init = | |
| 0 | |
| -- UPDATE | |
| type Action | |
| = Increment | |
| | Decrement | |
| update : Action -> Model -> Model | |
| update action model = | |
| case action of | |
| Increment -> | |
| model + 1 | |
| Decrement -> | |
| model - 1 | |
| view : Signal.Address Action -> Model -> Html | |
| view address model = | |
| div | |
| [] | |
| [ button [ onClick address Decrement ] [ text "-" ] | |
| , text (toString model) | |
| , button [ onClick address Increment ] [ text "+" ] | |
| ] | |
| main = | |
| start { model = init, update = update, view = view } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment