Created
December 12, 2016 10:27
-
-
Save rricard/b54ecec510713d2a2c19c03bd0b7d9f6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function Todo({todo, key, onToggle}) { | |
const onToggleEvent = `__Todo_${key}_onCheckEvent`; | |
window[onToggleEvent] = onToggle; | |
return ` | |
<li> | |
<input | |
type="checkbox" | |
onclick="${onToggleEvent}()" | |
${todo.done ? 'checked' : ''} | |
/> | |
${todo.done ? | |
`<span style="text-decoration: line-through">${todo.title}</span>` : | |
todo.title} | |
</li> | |
`; | |
} | |
function TodoApplication() { | |
return ` | |
<ul> | |
${todos.map((todo, key) => | |
Todo({ | |
todo, | |
key, | |
onToggle: () => { | |
todos[key].done = !todos[key].done; | |
render(); | |
} | |
})).join('') | |
} | |
</ul> | |
`; | |
} | |
let todos = [ | |
{title: 'Write a TODO app without React', done: true}, | |
{title: 'Write the rest of the article', done: false}, | |
]; | |
function render() { | |
document.getElementById('app').innerHTML = TodoApplication(); | |
} | |
render(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment