-
Notifications
You must be signed in to change notification settings - Fork 1
/
Grid.js
45 lines (35 loc) · 985 Bytes
/
Grid.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
class Grid {
constructor(root) {
this._root = document.getElementById(root);
this._squares = [];
}
get root() {
return this._root;
}
set root(root) {
return (this._root = root);
}
get squares() {
return this._squares;
}
renderSquare(wrapper, square, index) {
const elem = document.createElement("div");
elem.id = `sq-${index + 1}`;
elem.classList.add("game-square");
elem.dataset.value = square.value;
elem.dataset.order = square.order;
elem.dataset.isActive = square.isActive.toString();
elem.dataset.isMatched = square.isMatched.toString();
elem.style.backgroundColor = square.color;
// elem.textContent = square.value;
wrapper.appendChild(elem);
}
render(squares) {
this.root.innerHTML = "";
const wrapper = document.createDocumentFragment();
squares.forEach((square, index) => {
this.renderSquare(wrapper, square, index);
});
this.root.appendChild(wrapper);
}
}