Created
December 15, 2016 12:16
-
-
Save groz/e9f7ef5aedc6090a84e76135f919b8d7 to your computer and use it in GitHub Desktop.
Lunch and learn demo on Elm
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
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