-
Notifications
You must be signed in to change notification settings - Fork 0
/
lifecycle-standard.js
31 lines (26 loc) · 1.18 KB
/
lifecycle-standard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { LitElement, html } from 'lit';
class MyElement extends LitElement {
// Called when element is created
// Invoked when an existing element is upgraded (the definition for a custom element is loaded after the element is already in the DOM)
constructor() {
super(); // always call super first in the constructor
console.log('constructed');
this.opened = false; // default property value
}
// Invoked when a component is added to the document's DOM.
connectedCallback() {
super.connectedCallback(); // this is a standard Custom Element lifecycle event, so call super
console.log('connected');
// this is a good time to add event listeners that you don't add declaratively in the template
}
// Invoked when a component is removed from the document's DOM.
disconnectedCallback() {
super.disconnectedCallback(); // this is a standard Custom Element lifecycle event, so call super
console.log('disconnected');
// this is a good time to clean up event listeners you added in the connectedCallback
}
render() {
return html`<h1>Standard Custom Element Lifecycle events with Lit</h1>`;
}
}
customElements.define('my-element', MyElement);