Created
October 20, 2021 20:00
-
-
Save merryt/63052b5658ce53a53890737ca385f0ec to your computer and use it in GitHub Desktop.
Trying to build some front end stuff with limited frameworks
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
| var socket = io(); | |
| class GameList extends HTMLElement { | |
| connectedCallback() { | |
| this.setInnerHTML("No Active Games", []); | |
| socket.on("list of games", (gamesStr) => { | |
| const gamesObj = JSON.parse(gamesStr); | |
| const games = gamesObj["games"]; | |
| this.setInnerHTML("Ongoing Games", games); | |
| }); | |
| } | |
| setInnerHTML(title, games) { | |
| let gameList = `<h3>${title}</h3>`; | |
| if (games.length > 0) { | |
| gameList += "<div>"; | |
| console.log(games); | |
| for (const game of games) { | |
| gameList += `<a href="#" data-id="${game.id}">${game.name}</a>`; | |
| } | |
| gameList += "</div>"; | |
| } | |
| this.innerHTML = gameList; | |
| } | |
| } | |
| customElements.define("game-list", GameList); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment