mirror of
https://github.com/sim1222/misskey.git
synced 2025-08-07 01:04:03 +09:00
rename: client -> frontend
This commit is contained in:
24
packages/frontend/src/scripts/use-interval.ts
Normal file
24
packages/frontend/src/scripts/use-interval.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { onMounted, onUnmounted } from 'vue';
|
||||
|
||||
export function useInterval(fn: () => void, interval: number, options: {
|
||||
immediate: boolean;
|
||||
afterMounted: boolean;
|
||||
}): void {
|
||||
if (Number.isNaN(interval)) return;
|
||||
|
||||
let intervalId: number | null = null;
|
||||
|
||||
if (options.afterMounted) {
|
||||
onMounted(() => {
|
||||
if (options.immediate) fn();
|
||||
intervalId = window.setInterval(fn, interval);
|
||||
});
|
||||
} else {
|
||||
if (options.immediate) fn();
|
||||
intervalId = window.setInterval(fn, interval);
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
if (intervalId) window.clearInterval(intervalId);
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user