enhance: RSSウィジェット / RSSティッカーウィジェットをいい感じにする (#9469)

* ✌️

* use useInterval

* ✌️

* rawItems.value.length !== 0

* fix

* https://github.com/misskey-dev/misskey/pull/9469#discussion_r1061763613
This commit is contained in:
tamaina
2023-01-05 03:28:25 +09:00
committed by GitHub
parent f51220a5bf
commit b1a75177a0
3 changed files with 159 additions and 97 deletions

View File

@ -3,7 +3,7 @@ import { onMounted, onUnmounted } from 'vue';
export function useInterval(fn: () => void, interval: number, options: {
immediate: boolean;
afterMounted: boolean;
}): void {
}): (() => void) | undefined {
if (Number.isNaN(interval)) return;
let intervalId: number | null = null;
@ -18,7 +18,14 @@ export function useInterval(fn: () => void, interval: number, options: {
intervalId = window.setInterval(fn, interval);
}
onUnmounted(() => {
const clear = () => {
if (intervalId) window.clearInterval(intervalId);
intervalId = null;
};
onUnmounted(() => {
clear();
});
return clear;
}