Created
April 7, 2019 10:48
-
-
Save mistyharsh/98f1c35a64250bd8903c0c9cdff43ed9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Create style node outside of WebComponent | |
const style = document.createElement('style'); | |
style.innerHTML = ` | |
p { color: blue; } | |
`; | |
class FancyComponent extends HTMLElement { | |
constructor() { | |
super(); | |
const shadowRoot = this.attachShadow({ mode: 'open' }); | |
shadowRoot.innerHTML = ` | |
<div> | |
<p>Hello World</p> | |
</div> | |
`; | |
// Let us try to optimize | |
// Deep cloning of style node | |
const clonedStyle = style.cloneNode(true); | |
shadowRoot.appendChild(clonedStyle); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment