Created
March 15, 2019 18:47
-
-
Save kylebuch8/787e3e7bb0122bb6ebaa2260d7783db7 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
class SimpleComponent extends HTMLElement { | |
constructor() { | |
// calling super first | |
super(); | |
// setting some initial state | |
this.counter = 0; | |
this.active = false; | |
// adding an event listener | |
this.addEventListener("click", this._clickHandler); | |
// bind the context of "this" to our _clickHandler method that we'll set up later | |
this._clickHandler = this._clickHandler.bind(this); | |
// attaching a shadow root and adding some style and markup | |
this.attachShadow({ mode: "open" }); | |
this.shadowRoot.innerHTML = ` | |
<style> | |
:host { | |
display: inline-block; | |
} | |
</style> | |
<div>This is a really awesome component!</div> | |
`; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment