-
-
Save Comandeer/17e0cb7dc9a337ae951e0b0a2728f293 to your computer and use it in GitHub Desktop.
Binding event listeners
This file contains 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
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