Created
December 12, 2016 20:58
-
-
Save VincentHelwig/f952e7961e38d2703c03497ddffc7bf6 to your computer and use it in GitHub Desktop.
ELM 2
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
import Html exposing (Html, button, div, text) | |
import Html.Events exposing (onClick) | |
main = | |
Html.beginnerProgram { model = model, view = view, update = update } | |
-- MODEL | |
type alias Model = { | |
num: Int, | |
action: String | |
} | |
model : Model | |
model = | |
{ | |
num = 0 | |
, action = "init" | |
} | |
-- UPDATE | |
type Msg = Increment | Decrement | |
update : Msg -> Model -> Model | |
update msg model = | |
case msg of | |
Increment -> | |
( { model | num = model.num + 1, action = "Incr" } ) | |
Decrement -> | |
( { model | num = model.num - 1, action = "Decr" } ) | |
-- VIEW | |
view : Model -> Html Msg | |
view model = | |
div [] | |
[ iButton Decrement "-" | |
, div [] [ text (toString model.num) ] | |
, iButton Increment "+" | |
] | |
iButton : msg -> String -> Html msg | |
iButton msg label = | |
button [ onClick msg ] [ text label ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment