Skip to content

Instantly share code, notes, and snippets.

@gaku-sei
Last active October 9, 2016 09:25
Show Gist options
  • Save gaku-sei/e873cd2e7555c88a775c5a511fa9daad to your computer and use it in GitHub Desktop.
Save gaku-sei/e873cd2e7555c88a775c5a511fa9daad to your computer and use it in GitHub Desktop.
Huge todolist with inputs
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Html.App exposing (..)
import Html.Lazy 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
| Change Int String
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 model
Change id text ->
let
update todo =
if todo.id /= id then todo else { todo | text = text }
in
List.map update model
view : Model -> Html Msg
view model =
model |> List.map (lazy3 renderTodo Check Change) |> div []
renderTodo : (Int -> Msg) -> (Int -> String -> Msg) -> Todo -> Html Msg
renderTodo check change todo =
div []
[ label []
[ input [ Html.Attributes.value todo.text, onInput (change todo.id) ] []
, input [ type' "checkbox", onClick (check 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