-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
render_item renders the DOM for a Single Todo List item #52
Labels
Comments
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 if (typeof module !== 'undefined' && module.exports) {
module.exports = {
model: initial_model,
update: update,
render_item: render_item, // export so that we can unit test
}
} |
nelsonic
added a commit
that referenced
this issue
Aug 7, 2018
nelsonic
added a commit
that referenced
this issue
Aug 7, 2018
5 tasks
nelsonic
added a commit
that referenced
this issue
Sep 7, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
The text was updated successfully, but these errors were encountered: