Skip to content

Instantly share code, notes, and snippets.

@kylebuch8
Created March 15, 2019 18:47
Show Gist options
  • Save kylebuch8/787e3e7bb0122bb6ebaa2260d7783db7 to your computer and use it in GitHub Desktop.
Save kylebuch8/787e3e7bb0122bb6ebaa2260d7783db7 to your computer and use it in GitHub Desktop.
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