Created
June 1, 2018 13:37
-
-
Save dandgerson/e448103f9c94950b6aece73533ea1392 to your computer and use it in GitHub Desktop.
using elem.addEventListener('event', this);
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
getElem() { | |
if (!this.elem) { | |
this.render(); | |
} | |
return this.elem; | |
} | |
render() { | |
let html = _.template('<div class="user-list"></div>')(); | |
this.elem = createElementFromHTML(html); | |
this.elem.addEventListener('click', this); | |
} | |
handleEvent(event) { | |
this[ | |
'on' + | |
event.type[0].toUpperCase() + | |
event.type.slice(1) | |
](event); | |
} | |
onClick(event) { | |
if (event.target.dataset.userId) { | |
this.elem.dispatchEvent(new CustomEvent('user-select', { | |
bubbles: true, | |
detail: event.target.dataset.userId | |
})); | |
event.preventDefault(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment