Skip to content

Commit be5fe45

Browse files
committed
Use Keyed in Gren implementation, to match Elm.
1 parent cb227cd commit be5fe45

File tree

2 files changed

+114
-97
lines changed

2 files changed

+114
-97
lines changed

implementations/gren-0.5.5/Todo.gren

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Browser
44
import Html exposing (..)
55
import Html.Attributes exposing (..)
66
import Html.Events exposing (..)
7+
import Html.Keyed as Keyed
78
import Json.Decode as Json
89
import String
910
import Platform
@@ -245,48 +246,58 @@ viewEntries visibility entries =
245246
, label
246247
[ for "toggle-all" ]
247248
[ text "Mark all as complete" ]
248-
, ul [ class "todo-list" ] <|
249-
Array.map viewEntry ( Array.keepIf isVisible entries)
249+
, Keyed.ul [ class "todo-list" ] <|
250+
Array.map viewEntry ( Array.keepIf isVisible entries )
250251
]
251252

252253

253254

254255
-- VIEW INDIVIDUAL ENTRIES
255256

256257

257-
viewEntry : Entry -> Html Msg
258+
viewEntry : Entry -> { key : String, node : Html Msg }
258259
viewEntry todo =
259-
li
260-
[ classList [ { class = "completed", enabled = todo.completed }, { class = "editing", enabled = todo.editing } ] ]
261-
[ div
262-
[ class "view" ]
263-
[ input
264-
[ class "toggle"
265-
, type_ "checkbox"
266-
, checked todo.completed
267-
, onClick (Check { id = todo.id, checked = (not todo.completed) })
268-
]
269-
[]
270-
, label
271-
[ onDoubleClick (EditingEntry { id = todo.id, checked = True }) ]
272-
[ text todo.description ]
273-
, button
274-
[ class "destroy"
275-
, onClick (Delete todo.id)
276-
]
277-
[]
278-
]
279-
, input
280-
[ class "edit"
281-
, value todo.description
282-
, name "title"
283-
, id ("todo-" ++ String.fromInt todo.id)
284-
, onInput (\value -> UpdateEntry { id = todo.id, value = value })
285-
, onBlur (EditingEntry { id = todo.id, checked = False })
286-
, onEnter (EditingEntry { id = todo.id, checked = False })
260+
let
261+
nodeId = "todo-" ++ String.fromInt todo.id
262+
in
263+
{ key = nodeId
264+
, node =
265+
li
266+
[ classList
267+
[ { class = "completed", enabled = todo.completed }
268+
, { class = "editing", enabled = todo.editing }
287269
]
288-
[]
289-
]
270+
]
271+
[ div
272+
[ class "view" ]
273+
[ input
274+
[ class "toggle"
275+
, type_ "checkbox"
276+
, checked todo.completed
277+
, onClick (Check { id = todo.id, checked = (not todo.completed) })
278+
]
279+
[]
280+
, label
281+
[ onDoubleClick (EditingEntry { id = todo.id, checked = True }) ]
282+
[ text todo.description ]
283+
, button
284+
[ class "destroy"
285+
, onClick (Delete todo.id)
286+
]
287+
[]
288+
]
289+
, input
290+
[ class "edit"
291+
, value todo.description
292+
, name "title"
293+
, id nodeId
294+
, onInput (\value -> UpdateEntry { id = todo.id, value = value })
295+
, onBlur (EditingEntry { id = todo.id, checked = False })
296+
, onEnter (EditingEntry { id = todo.id, checked = False })
297+
]
298+
[]
299+
]
300+
}
290301

291302

292303

0 commit comments

Comments
 (0)