Instead of using onDestroy, return a function from onMount
This commit is contained in:
parent
018ae4fe06
commit
b0e2a9e6d4
3 changed files with 21 additions and 13 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue