This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const startGame = () => { | |
let team = 'X'; | |
const board = [ | |
['-', '-', '-'], | |
['-', '-', '-'], | |
['-', '-', '-'], | |
]; | |
const updateBoard = (id) => { | |
switch (id) { | |
case 'tl': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h1 { | |
display: block; | |
text-align: center; | |
} | |
#board { | |
display: block; | |
width: 156px; | |
height: 156px; | |
border: 1px solid #000000; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const createElement = (tagName, { attrs, children }) => { | |
const vEl = Object.create(null); | |
Object.assign(vEl, { | |
tagName, | |
attrs, | |
children, | |
}); | |
return vEl; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const render = (vNode) => { | |
if (typeof vNode === 'string') { | |
return document.createTextNode(vNode); | |
} | |
const { tagName, attrs, children } = vNode; | |
const el = document.createElement(tagName); | |
for (const [k, v] of Object.entries(attrs)) { | |
if (/^on/.test(k)) { | |
const eventType = k.replace(/^on/, '').toLowerCase(); | |
el.addEventListener(eventType, v); |
OlderNewer