Instead of using onDestroy, return a function from onMount

This commit is contained in:
Oliver Akins 2022-03-15 22:38:09 -06:00
parent 018ae4fe06
commit b0e2a9e6d4
No known key found for this signature in database
GPG key ID: 3C2014AF9457AF99
3 changed files with 21 additions and 13 deletions

View file

@ -6,8 +6,8 @@ import SciFiButton from "../../components/SciFi-Button.svelte";
import { ILobbyInfo, Status, gameOptions } from "common";
import Player from "../../components/Player.svelte";
import { isHost, players } from "../../stores";
import { onMount, onDestroy } from "svelte"
import { socket } from "../../main";
import { onMount } from "svelte";
function handleLobbyInfo(data: ILobbyInfo) {
if (data.status == Status.Success) {
@ -19,6 +19,9 @@ function handleLobbyInfo(data: ILobbyInfo) {
onMount(() => {
socket.on(`res:lobby.info`, handleLobbyInfo);
return () => {
socket.off(`res:lobby.info`);
};
});
function tempButtonHandler() {};
@ -41,10 +44,6 @@ function toggleOption(e: CustomEvent<string>) {
// TODO: Send websocket event to server
};
onDestroy(() => {
socket.off(`res:lobby.info`);
});
</script>
<OptionInfo