Skip to content

Instantly share code, notes, and snippets.

@groz
Created December 15, 2016 12:16
Show Gist options
  • Save groz/e9f7ef5aedc6090a84e76135f919b8d7 to your computer and use it in GitHub Desktop.
Save groz/e9f7ef5aedc6090a84e76135f919b8d7 to your computer and use it in GitHub Desktop.
Lunch and learn demo on Elm
module Demo exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
main =
Html.beginnerProgram
{ model = model
, view = view
, update = update
}
type alias Model =
{ count : Int }
model =
{ count = 0 }
type Msg
= CountChanged String
view : Model -> Html Msg
view model =
let
nums =
List.range 0 model.count
showNum n =
li [] [ text (toString n) ]
in
div []
[ input [ onInput CountChanged ] []
, ul [] (nums |> List.map showNum)
]
update : Msg -> Model -> Model
update msg model =
case msg of
CountChanged str ->
{ model | count = str |> String.toInt |> Result.withDefault 0 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment