Skip to content

Instantly share code, notes, and snippets.

@iacutone
Created May 15, 2017 20:39
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 iacutone/09e31217db8d5d253e1978cc8ad3600f to your computer and use it in GitHub Desktop.
Save iacutone/09e31217db8d5d253e1978cc8ad3600f to your computer and use it in GitHub Desktop.
Basic Elm App
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