Created
November 29, 2016 15:32
-
-
Save adicirstei/1f4ecc62fd5ffe19e683b0767631ab96 to your computer and use it in GitHub Desktop.
Elm run-time exceptions
This file contains 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 (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