Skip to content

Instantly share code, notes, and snippets.

@bendc
Created January 6, 2017 10:57
Show Gist options
  • Save bendc/d32ad6f9afd55f16f99e869c832183e7 to your computer and use it in GitHub Desktop.
Save bendc/d32ad6f9afd55f16f99e869c832183e7 to your computer and use it in GitHub Desktop.
Web Components: todo-list-basic
const state = ["Buy milk", "Call Sarah", "Pay bills"];
customElements.define("todo-item", class extends HTMLElement {
constructor() {
super();
const root = this.attachShadow({mode: "open"});
root.innerHTML = `
<label>
<input type=checkbox>
<slot></slot>
</label>
`;
}
});
customElements.define("todo-list", class extends HTMLElement {
constructor() {
super();
const root = this.attachShadow({mode: "open"});
root.innerHTML = `
<ul>
${state.map(todo => `
<li>
<todo-item>${todo}</todo-item>
</li>
`).join("")}
</ul>
`;
}
});
document.body.innerHTML = "<todo-list></todo-list>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment