Skip to content

Instantly share code, notes, and snippets.

@Comandeer
Created July 7, 2018 20:55
Embed
What would you like to do?
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