Created
August 12, 2019 19:25
-
-
Save justinbmeyer/3b4dc0a1b682556ac397bc9f9a9dab94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body> | |
<script> | |
class HelloWorld extends HTMLElement { | |
constructor() { | |
super(); | |
this.rendered = false; | |
this.depth = 0; | |
} | |
connectedCallback(){ | |
this.render(); | |
} | |
render(){ | |
if(this.rendered) { return; } | |
this.rendered = true; | |
if(this.depth < 10) { | |
var ul = document.createElement("ul"); | |
var li = document.createElement("li"); | |
li.innerHTML = ""+ this.depth; | |
ul.appendChild(li); | |
for(let i = 0; i < 2; i++) { | |
var li = document.createElement("li"); | |
var hw = document.createElement("hello-world"); | |
hw.depth = this.depth + 1; | |
hw.render(); // FAST | |
li.appendChild(hw); | |
ul.appendChild(li); | |
} | |
this.appendChild(ul); | |
//this.offsetHeight; | |
} else { | |
this.innerHTML = "leaf" | |
} | |
} | |
} | |
customElements.define("hello-world", HelloWorld); | |
var hw = document.createElement("hello-world"); | |
var now = new Date(); | |
hw.render(); // FAST | |
document.body.appendChild(hw); | |
console.log(new Date() - now); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment