-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcomponent.js
More file actions
32 lines (24 loc) · 731 Bytes
/
component.js
File metadata and controls
32 lines (24 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Component {
constructor(containerID) {
this.containerID = containerID;
this.container = document.getElementById(containerID);
if (!this.container) {
throw new Error(`Could not find ${this.constructor.name} container with ID: ${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;