generated from VLADIMIR/template_frontend
add pooling for game
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Vendored
+2
-2
@@ -5,8 +5,8 @@
|
|||||||
<link rel="icon" href="/favicon.ico">
|
<link rel="icon" href="/favicon.ico">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Вечерний детектив</title>
|
<title>Вечерний детектив</title>
|
||||||
<script type="module" crossorigin src="/assets/index-BHUjMe8A.js"></script>
|
<script type="module" crossorigin src="/assets/index-DZUsBN6M.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-BFjIFT0o.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-hPvau_ng.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { ref } from 'vue';
|
|||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
import PlaceBlock from '@/components/PlaceBlock.vue'
|
import PlaceBlock from '@/components/PlaceBlock.vue'
|
||||||
import GameInputForm from '@/components/GameInputForm.vue'
|
import GameInputForm from '@/components/GameInputForm.vue'
|
||||||
|
import { useSimplePolling } from '@/composables/useSimplePolling';
|
||||||
|
|
||||||
const client = getAuthClient()
|
const client = getAuthClient()
|
||||||
const message = useMessage()
|
const message = useMessage()
|
||||||
@@ -63,6 +64,10 @@ type AdvancedPlace = {
|
|||||||
place: Place;
|
place: Place;
|
||||||
mode: string;
|
mode: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useSimplePolling(() => {
|
||||||
|
getStory()
|
||||||
|
}, 2000);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { ref, onMounted, onUnmounted } from 'vue';
|
||||||
|
|
||||||
|
export function useSimplePolling(callback: () => void, interval = 5000) {
|
||||||
|
const isActive = ref(true);
|
||||||
|
let timerId: number | null = null;
|
||||||
|
|
||||||
|
const start = () => {
|
||||||
|
isActive.value = true;
|
||||||
|
callback();
|
||||||
|
timerId = window.setInterval(callback, interval);
|
||||||
|
};
|
||||||
|
|
||||||
|
const stop = () => {
|
||||||
|
isActive.value = false;
|
||||||
|
if (timerId) {
|
||||||
|
clearInterval(timerId);
|
||||||
|
timerId = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(start);
|
||||||
|
onUnmounted(stop);
|
||||||
|
|
||||||
|
return { isActive, start, stop };
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user