Skip to content

Instantly share code, notes, and snippets.

@robdodson
Created November 3, 2016 21:56
Show Gist options
  • Select an option

  • Save robdodson/12ee1ae2bb7e051790038b86d4fe3b23 to your computer and use it in GitHub Desktop.

Select an option

Save robdodson/12ee1ae2bb7e051790038b86d4fe3b23 to your computer and use it in GitHub Desktop.
export default class XFoo extends HTMLElement {
message: string;
constructor() {
super();
}
connectedCallback() {
this.innerHTML = `<p>${this.message}</p>`;
this.addEventListener('click', this.onClick);
}
onClick(e: Event) {
this.innerHTML = `<p>I was clicked!</p>`;
this.dispatchEvent(new CustomEvent('x-foo-changed', { detail: { foo: 'bar' } }));
}
}
window.customElements.define('x-foo', XFoo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment