-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparts.html
55 lines (45 loc) · 1.26 KB
/
parts.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>LISS Example (Parts)</title>
<script type="module">
import LISS from '../index.js';
class MyComponentA extends LISS() {
constructor(htmltag) {
super(htmltag)
const span = document.createElement('span');
span.setAttribute('part', 'foo');
this.content.append(span);
}
}
class MyComponentB extends LISS(HTMLTableRowElement) {
constructor(htmltag) {
super(htmltag);
const td = document.createElement('td');
td.setAttribute('part', 'foo');
this.content.append( td );
}
}
LISS.define('my-component-a', MyComponentA);
LISS.define('my-component-b', MyComponentB);
await LISS.whenDefined('my-component-a');
let elem = document.querySelector(`my-component-a`);
let part = elem.getPart("foo");
part.textContent = "Hello";
console.log("A", elem.getParts("foo"));
await LISS.whenDefined('my-component-b');
elem = document.querySelector(`tr[is="my-component-b"]`);
part = elem.getPart("foo");
part.textContent = "World";
console.log("B", elem.getParts("foo"));
</script>
</head>
<body>
<my-component-a></my-component-a>
<table>
<tr is="my-component-b"></tr>
</table>
</body>
</html>