Skip to content

Instantly share code, notes, and snippets.

@rricard
Created December 12, 2016 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rricard/b54ecec510713d2a2c19c03bd0b7d9f6 to your computer and use it in GitHub Desktop.
Save rricard/b54ecec510713d2a2c19c03bd0b7d9f6 to your computer and use it in GitHub Desktop.
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