Created
May 15, 2017 20:39
-
-
Save iacutone/09e31217db8d5d253e1978cc8ad3600f to your computer and use it in GitHub Desktop.
Basic Elm App
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 (..) | |
import Html.Events exposing (onClick) | |
main: Program Never Model Msg | |
main = | |
Html.program | |
{ init = init | |
, view = view | |
, update = update | |
, subscriptions = subscriptions | |
} | |
init : ( Model, Cmd Msg ) | |
init = | |
(initialModel, Cmd.none ) | |
-- MODEL | |
type alias Model = | |
{count: Float} | |
initialModel: Model | |
initialModel = | |
{count = 0} | |
-- VIEW | |
view : Model -> Html Msg | |
view model = | |
div [] | |
[ button [ onClick Decrement ] [ text "-" ] | |
, div [] [ text (toString model.count) ] | |
, button [ onClick Increment ] [ text "+" ] | |
] | |
type Msg = Increment | Decrement | |
update : Msg -> Model -> ( Model, Cmd Msg ) | |
update msg model = | |
case msg of | |
Increment -> | |
( { model | count = model.count + 1 }, Cmd.none ) | |
Decrement -> | |
( { model | count = model.count - 1 }, Cmd.none ) | |
subscriptions : Model -> Sub Msg | |
subscriptions model = | |
Sub.none |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment