mirror of
https://github.com/psforever/PSFPortal.git
synced 2026-01-19 18:14:45 +00:00
Cleanup setInterval on Home page
This commit is contained in:
parent
e5fadd5891
commit
f2be2504b9
9
app/util/index.js
Normal file
9
app/util/index.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { onDestroy } from 'svelte';
|
||||
|
||||
export function onInterval(callback, milliseconds) {
|
||||
const interval = setInterval(callback, milliseconds);
|
||||
|
||||
onDestroy(() => {
|
||||
clearInterval(interval);
|
||||
});
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
import { onMount } from 'svelte';
|
||||
import axios from 'axios'
|
||||
import moment from 'moment'
|
||||
import { onInterval } from '../util'
|
||||
|
||||
import { loggedIn } from '../UserState'
|
||||
import Alert from '../components/Alert'
|
||||
|
|
@ -25,7 +26,10 @@
|
|||
onMount(async () => {
|
||||
await update_stats()
|
||||
update_stats_label()
|
||||
setInterval(update_stats_label, 1000)
|
||||
|
||||
// we must use this wrapper to ensure setIntervals are cleaned
|
||||
// up on view change
|
||||
onInterval(update_stats_label, 1000)
|
||||
|
||||
ready = true
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue