martijnversluis/ChordFiddle

View on GitHub
src/js/component.js

Summary

Maintainability
A
0 mins
Test Coverage
class Component {
  constructor(containerID) {
    this.containerID = containerID;
    this.container = document.getElementById(containerID);
    this.setup();
  }

  setup() {}

  onClick(elementID, listener) {
    this.bindEvent(elementID, 'click', listener);
  }

  onChange(elementID, listener) {
    this.bindEvent(elementID, 'change', listener);
  }

  bindEvent(elementID, event, listener) {
    this.element(elementID).addEventListener(event, listener);
  }

  element(elementID) {
    return document.getElementById(`${this.containerID}__${elementID}`);
  }
}

export default Component;