Skip to content

Instantly share code, notes, and snippets.

@josedaniel
Last active August 4, 2020 23:11
Show Gist options
  • Save josedaniel/ae46bf7e8e94e0fb34e8d5a9fd8e83a5 to your computer and use it in GitHub Desktop.
Save josedaniel/ae46bf7e8e94e0fb34e8d5a9fd8e83a5 to your computer and use it in GitHub Desktop.
<div class="todo-list"></div>
<script>
async function data(){
const src = 'http://my-data.com/data.json';
const response = await fetch(src);
return response.json();
}
class TodoItem{
constructor({title, description, completed}) {
this.title = title;
this.description = description;
this.completed = completed;
}
render() {
const { title, description, completed} = this;
return /* html */`
<div>${ title } ${ description } ${ completed }</div>
`;
}
}
data().then((todos) => {
let output = ``;
todos.forEach(element => {
output += new TodoItem(element).render();
});
document.querySelector('.todo-list').innerHTML(output);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment