Skip to content

Instantly share code, notes, and snippets.

@KaiWedekind
Last active August 13, 2018 06:35
Show Gist options
  • Save KaiWedekind/7a2f418bf7e8b55741f3e97fcbbfd925 to your computer and use it in GitHub Desktop.
Save KaiWedekind/7a2f418bf7e8b55741f3e97fcbbfd925 to your computer and use it in GitHub Desktop.
Lifecycle callbacks
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>`;
}
// called when the element is removed from the DOM.
disconnectedCallback() {
}
// called when an attribute was added, removed, or updated
attributeChangedCallback(attributeName, oldValue, newValue) {
}
// called if the element has been moved into a new document
adoptedCallback() {
}
}
// 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