Skip to content

Instantly share code, notes, and snippets.

@Comandeer
Created July 7, 2018 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Comandeer/17e0cb7dc9a337ae951e0b0a2728f293 to your computer and use it in GitHub Desktop.
Save Comandeer/17e0cb7dc9a337ae951e0b0a2728f293 to your computer and use it in GitHub Desktop.
Binding event listeners
function registerComponent( { template, style, name, listeners } ) { // 1
class UnityComponent extends HTMLElement {
connectedCallback() {
this._upcast();
this._attachListeners(); // 2
}
[…]
_attachListeners() {
Object.entries( listeners ).forEach( ( [ event, listener ] ) => { // 3
this.addEventListener( event, listener, false ); // 4
} );
}
}
return customElements.define( name, UnityComponent );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment