1+ /**
2+ * The template that is used for the shadow root for every copy of your element,
3+ * which houses the styles and layout for the element.
4+ */
15const template = document . createElement ( "template" ) ;
26template . innerHTML = `
37 <style>
@@ -7,7 +11,21 @@ template.innerHTML = `
711 </style>
812` ;
913
14+ /**
15+ * This is the class that controls each instance of your custom element.
16+ */
1017class /* {className} */ extends HTMLElement {
18+ /**
19+ * Part of the custom element spec. Returns an array of strings that are
20+ * the names of attributes that this element observes/listens to.
21+ *
22+ * @returns {Array } an array of strings, each of which representing an
23+ * attribute.
24+ */
25+ static get observedAttributes ( ) {
26+ return [ ] ;
27+ } ;
28+
1129 constructor ( ) {
1230 super ( ) ;
1331
@@ -18,8 +36,34 @@ class /* {className} */ extends HTMLElement {
1836 // add any initial variables here
1937 }
2038
39+ /**
40+ * Part of the custom element spec. Called after your element is attached to
41+ * the DOM. Do anything related to the element or its children here in most
42+ * cases.
43+ */
2144 connectedCallback ( ) {
22- // do something here on element init
45+
46+ }
47+
48+ /**
49+ * Part of the custom element spec. Called after your element is remove from
50+ * the DOM. Disconnect any listeners or anything else here.
51+ */
52+ disconnectedCallback ( ) {
53+
54+ }
55+
56+ /**
57+ * Part of the custom element spec. Called when one of the observed
58+ * attributes changes, either via setAttribute() or with the attribute being
59+ * manually set in the HTML.
60+ *
61+ * @param {String } name the name of the attribute that changed
62+ * @param {Mixed } oldValue the previous value of the attribute
63+ * @param {Mixed } newValue the new value of the attribute
64+ */
65+ attributeChangedCallback ( name , oldValue , newValue ) {
66+ // respond to a changed attribute here
2367 }
2468}
2569
0 commit comments