Skip to content

Instantly share code, notes, and snippets.

@KaiWedekind
Last active August 12, 2018 06:19
Show Gist options
  • Save KaiWedekind/16191a3a69c989a403da8a57b5361522 to your computer and use it in GitHub Desktop.
Save KaiWedekind/16191a3a69c989a403da8a57b5361522 to your computer and use it in GitHub Desktop.
Universal todo component built with custom elements v1 - Lifecycle methods
class MyTodos extends HTMLElement {
// called when the HTML parser sees the HTML tag
constructor () {
// always call super() first in your constructor to inherit from your parent class
super();
this.title = 'My todos';
}
// called when the element is inserted in the DOM
// immediately after constructor if the element is in the DOM already
connectedCallback () {
this.innerHTML = `<header>${ this.title }</header>`;
}
}
// register new tag and associate it with the class
customElements.define('my-todos', MyTodos);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment