Created
October 15, 2019 22:41
-
-
Save dktn/019988601b1928605bbc92fcbb9a6954 to your computer and use it in GitHub Desktop.
Elm example program
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 (..) | |
import Html.Attributes exposing (..) | |
import Html.Events exposing (..) | |
import Browser exposing (sandbox) | |
type alias Model = | |
{ message : String | |
, count : Int | |
} | |
type Msg = | |
Message String | |
| Increment | |
| Decrement | |
initialModel : Model | |
initialModel = | |
Model "Hi, this is state" 0 | |
update : Msg -> Model -> Model | |
update msg model = | |
case msg of | |
Message newMessage -> | |
{ model | message = newMessage } | |
Increment -> | |
{ model | count = model.count + 1 } | |
Decrement -> | |
{ model | count = model.count - 1 } | |
view : Model -> Html Msg | |
view model = | |
div [] | |
[ input [ placeholder "Type some stuff", onInput Message ] [] | |
, div [] [ text model.message ] | |
, button [ onClick Increment ] [ text "+" ] | |
, button [ onClick Decrement ] [ text "-" ] | |
, div [] [ text (String.fromInt model.count) ] | |
] | |
main : Program () Model Msg | |
main = | |
sandbox | |
{ init = initialModel | |
, view = view | |
, update = update | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment