Template
chore: formatting
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { subscribe } from "~/netcode";
|
||||
import type { GameResponseDTO } from "~/netcode/events/dto/gameresponse.dto";
|
||||
import type { ConceptEvent } from "~/netcode/events/events";
|
||||
import { handlers } from "~/netcode/handlers/lobby.handler";
|
||||
|
||||
export const useLobbyStore = defineStore("lobby", {
|
||||
@@ -9,17 +10,17 @@ export const useLobbyStore = defineStore("lobby", {
|
||||
eventSource: null as null | EventSource,
|
||||
}),
|
||||
actions: {
|
||||
async subscribe() {
|
||||
subscribe() {
|
||||
this.eventSource = subscribe(`/games/subscribe`);
|
||||
this.eventSource.addEventListener("message", async (message) => {
|
||||
const data = JSON.parse(message.data);
|
||||
const type = data.type as string;
|
||||
this.eventSource.addEventListener("message", (message) => {
|
||||
const data = JSON.parse(message.data as string) as ConceptEvent;
|
||||
const type = data.type;
|
||||
if (type in handlers) {
|
||||
handlers[type as keyof typeof handlers](data);
|
||||
}
|
||||
});
|
||||
},
|
||||
async close() {
|
||||
close() {
|
||||
this.eventSource?.close();
|
||||
},
|
||||
async fetchGames() {
|
||||
@@ -29,7 +30,7 @@ export const useLobbyStore = defineStore("lobby", {
|
||||
{
|
||||
credentials: "include",
|
||||
immediate: true,
|
||||
}
|
||||
},
|
||||
);
|
||||
if (data.data.value) {
|
||||
for (const game of data.data.value) {
|
||||
@@ -46,7 +47,7 @@ export const useLobbyStore = defineStore("lobby", {
|
||||
{
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
}
|
||||
},
|
||||
);
|
||||
// this.games[data.id] = data;
|
||||
return data;
|
||||
|
||||
Reference in New Issue
Block a user