forked from gothinkster/realworld-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathexmple.comp.js
47 lines (38 loc) · 1.07 KB
/
exmple.comp.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"use strict";
export class CNavComponent extends HTMLElement {
constructor() {
super();
this.shadow = this.createShadowRoot();
this._complete = 0;
}
get complete() {
return this._complete;
}
set complete(val) {
this.setAttribute('complete', val);
}
static get observedAttributes() { return ["complete"]; }
attributeChangedCallback(name, oldValue, newValue) {
// name will always be "country" due to observedAttributes
switch (name) {
case 'complete': {
this._complete = newValue;
}
}
}
connectedCallback() {
var template = `
<h1>test ${this.complete}</h1>
<a>increment</a>
`;
this.shadow.innerHTML = template;
var btn = this.shadow.querySelector('a');
btn.addEventListener('click',() => {
this._complete = +this._complete + +1;
this.connectedCallback();
});
}
increment() {
}
}
window.customElements.define("c-nav", CNavComponent);