src/js/component.js
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;