Last active
August 13, 2018 06:35
-
-
Save KaiWedekind/7a2f418bf7e8b55741f3e97fcbbfd925 to your computer and use it in GitHub Desktop.
Lifecycle callbacks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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