-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanual.html
78 lines (63 loc) · 1.93 KB
/
manual.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
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Increment/Decrement (manual, no templates)</title>
<script type="module">
// This example shows a component creating a TextContentUpdater
// directly, rather than using a template.
import { TextContentUpdater } from '../src/updaters.js';
class IncrementDecrement extends HTMLElement {
constructor() {
super();
this.value = 0;
}
connectedCallback() {
this.attachShadow({ mode: 'open' });
// Populate the shadow by hand.
const decrement = document.createElement('button');
decrement.textContent = '-';
decrement.addEventListener('click', () => {
this.value--;
});
const space1 = new Text(' ');
const text = new Text();
const space2 = new Text(' ');
const increment = document.createElement('button');
increment.textContent = '+';
increment.addEventListener('click', () => {
this.value++;
});
const elements = [
decrement,
space1,
text,
space2,
increment
];
elements.forEach(element => this.shadowRoot.appendChild(element));
// Create an updater by hand.
this._updater = new TextContentUpdater(text);
// Apply initial values.
this._updater.update(this.value);
}
get value() {
return this._value;
}
set value(value) {
this._value = value;
if (this._updater) {
this._updater.update(this.value);
}
}
}
customElements.define('increment-decrement', IncrementDecrement);
</script>
</head>
<body>
<increment-decrement></increment-decrement>
<increment-decrement></increment-decrement>
<increment-decrement></increment-decrement>
</body>
</html>