-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathincrementDecrement.html
65 lines (52 loc) · 1.59 KB
/
incrementDecrement.html
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Increment/Decrement</title>
<template id="template">
<button id="decrement">-</button>
{{value}}
<button id="increment">+</button>
</template>
<script type="module">
import ElementFactory from '../src/ElementFactory.js';
// Component template only needs to be parsed once.
const factory = new ElementFactory(template);
class IncrementDecrement extends HTMLElement {
constructor() {
super();
this.value = 0;
}
connectedCallback() {
this.attachShadow({ mode: 'open' });
// Create a new instance, and an updater that can update it with data.
const { instance, updater } = factory.instantiate(this);
this._updater = updater;
instance.querySelector('#decrement').addEventListener('click', () => {
this.value--;
});
instance.querySelector('#increment').addEventListener('click', () => {
this.value++;
});
this.shadowRoot.appendChild(instance);
}
get value() {
return this._value;
}
set value(value) {
this._value = value;
if (this._updater) {
this._updater.update(this);
}
}
}
customElements.define('increment-decrement', IncrementDecrement);
</script>
</head>
<body>
<increment-decrement></increment-decrement>
<increment-decrement></increment-decrement>
<increment-decrement></increment-decrement>
</body>
</html>