Skip to content

Instantly share code, notes, and snippets.

@VincentHelwig
Created December 12, 2016 20:58
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 VincentHelwig/f952e7961e38d2703c03497ddffc7bf6 to your computer and use it in GitHub Desktop.
Save VincentHelwig/f952e7961e38d2703c03497ddffc7bf6 to your computer and use it in GitHub Desktop.
ELM 2
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