Closed nelsonic closed 6 years ago
Code to make this test pass:
/**
* `render_item` creates an DOM "tree" with a single Todo List Item
* using the "elmish" DOM functions (`li`, `div`, `input`, `label` and `button`)
* returns an `<li>` HTML element with a nested `<div>` which in turn has the:
* + `<input type=checkbox>` which lets users to "Toggle" the status of the item
* + `<label>` which displays the Todo item text (`title`) in a `<text>` node
* + `<button class="destroy">` lets people "delete" a todo item.
* see: https://github.com/dwyl/learn-elm-architecture-in-javascript/issues/52
* @param {Object} item the todo item object
* @return {Object} <li> DOM Tree which is nested in the <ul>.
* @example
* // returns <li> DOM element with <div>, <input>. <label> & <button> nested
* var DOM = render_item({id: 1, title: "Build Todo List App", done: false});
*/
function render_item(item) {
return (
li([
"data-id=" + item.id,
"id=" + item.id,
item.done ? "class=completed" : ""
], [
div(["class=view"], [
input(["class=toggle", "type=checkbox",
(item.done ? "checked=true" : "")], []),
label([], [text(item.title)]),
button(["class=destroy"])
]) // </div>
]) // </li>
)
}
Add the render_item
to the module.exports
at the end of the file:
if (typeof module !== 'undefined' && module.exports) {
module.exports = {
model: initial_model,
update: update,
render_item: render_item, // export so that we can unit test
}
}
Given the following HTML:
Use
Elm
(ish) DOM functions (li
,div
,input
,label
andbutton
) to render a single Todo List item.Acceptance Criteria
<li>
should contain a<div>
with aclass="view"
which "wraps":<input class="toggle" type="checkbox">
- the "checkbox" that people can "Toggle" to change the "state" of the Todo item from "active" to "done" (_which updates the model From:model.todos[id].done=false
To:model.todos[id].done=true
<label>
- the text content of the todo list item<button class="destroy">
- the button the person can click/tap todelete
a Todo item.Sample Test: