Created
October 4, 2016 08:40
-
-
Save gaku-sei/6f67daedf5e6fcffa66e9b51878db20f to your computer and use it in GitHub Desktop.
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.Attributes exposing (..) | |
import Html.Events exposing (..) | |
import Html.App exposing (..) | |
import Json.Decode exposing (..) | |
import Http | |
import Task | |
type alias Todo = | |
{ id : Int | |
, text : String | |
, done : Bool } | |
type alias Model = | |
List Todo | |
type Msg = | |
Check Int | |
update : Msg -> Model -> Model | |
update msg model = | |
case msg of | |
Check id -> | |
let | |
update todo = | |
if todo.id /= id then todo else { todo | done = not todo.done } | |
in | |
List.map update (Debug.log "model" model) | |
view : Model -> Html Msg | |
view model = | |
model |> List.map (renderTodo Check) |> div [] | |
renderTodo : (Int -> Msg) -> Todo -> Html Msg | |
renderTodo msg todo = | |
div [] | |
[ label [] | |
[ text todo.text | |
, input [ type' "checkbox", onClick (msg todo.id) ] [] ] ] | |
main = beginnerProgram | |
{ model = List.map (\i -> Todo i (toString i) False) [1..10000] | |
, update = update | |
, view = view } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment