Skip to content

Instantly share code, notes, and snippets.



Last active May 7, 2016
What would you like to do?
Modern JS event handling mixin
const Handler = Base => class extends Base {
handleEvent (evt) {
return this[`on${evt.type.replace(/^./, c => c.toUpperCase())}`](evt)

This comment has been minimized.

Copy link
Owner Author

@raggi raggi commented May 7, 2016

Usage example:

class ExampleElement extends Handler(HTMLElement) {
  attachedCallback () {
    this.addEventListener('click', this)
  detachedCallback () {
    this.removeEventListener('click', this)
  onClick (evt) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment