forked from canjs/canjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo2.html
43 lines (35 loc) · 964 Bytes
/
demo2.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
<button id="add">Add one</button>
<script type=module>
var widths = [];
window.WIDTHS = widths;
let MyElement = class extends HTMLElement {
constructor() {
super();
}
set depth(newDepth) {
var depth = newDepth - 1;
var span = document.createElement('span');
span.textContent = depth;
this.appendChild(span);
if(depth > 0) {
for(var i = 0; i < 10; i++) {
let child = document.createElement('my-element');
child.depth = depth;
this.appendChild(child);
}
}
}
connectedCallback() {
widths.push(this.firstChild.offsetWidth);
}
}
customElements.define('my-element', MyElement);
add.addEventListener('click', () => {
var t0 = performance.now();
let el = new MyElement();
el.depth = 4;
document.body.appendChild(el);
var t1 = performance.now();
console.log("Call to doSomething took " + (t1 - t0) + " milliseconds.");
});
</script>