Skip to content

Instantly share code, notes, and snippets.

@merryt
Created October 20, 2021 20:00
Show Gist options
  • Select an option

  • Save merryt/63052b5658ce53a53890737ca385f0ec to your computer and use it in GitHub Desktop.

Select an option

Save merryt/63052b5658ce53a53890737ca385f0ec to your computer and use it in GitHub Desktop.
Trying to build some front end stuff with limited frameworks
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