Skip to content

Instantly share code, notes, and snippets.

@adicirstei
Created November 29, 2016 15:32
Show Gist options
  • Save adicirstei/1f4ecc62fd5ffe19e683b0767631ab96 to your computer and use it in GitHub Desktop.
Save adicirstei/1f4ecc62fd5ffe19e683b0767631ab96 to your computer and use it in GitHub Desktop.
Elm run-time exceptions
import Html exposing (beginnerProgram, div, span, button, text)
import Html.Events exposing (onClick)
type Msg
= Increment Int
| Decrement Int
type alias Model =
{ action : Int -> Msg
, currentValue : Int
}
view model =
div []
[ span [] [ text "Current value: ", text (toString model.currentValue) ]
, button [ onClick (Increment 7) ] [text "Click me!"]
]
flipMsg model =
if model.action == Increment then Decrement else Increment
update msg model =
case msg of
Increment n -> {model | currentValue = model.currentValue + n, action = flipMsg model}
Decrement n -> {model | currentValue = model.currentValue - n, action = flipMsg model}
main = Html.beginnerProgram
{ model = Model Increment 0
, view = view
, update = update
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment