From 8322c908340fa720d4f1afc781ef34e9d16ae6b0 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 16 Jan 2022 10:14:14 +0900 Subject: [PATCH] refactor(client): specify global scope --- .../client/src/components/analog-clock.vue | 2 +- packages/client/src/components/captcha.vue | 2 +- packages/client/src/components/form/input.vue | 4 +-- .../client/src/components/form/select.vue | 4 +-- .../components/global/sticky-container.vue | 2 +- packages/client/src/components/mini-chart.vue | 4 +-- .../src/components/notification-toast.vue | 2 +- packages/client/src/components/ripple.vue | 2 +- packages/client/src/components/toast.vue | 2 +- packages/client/src/components/ui/button.vue | 6 ++-- packages/client/src/components/ui/modal.vue | 2 +- packages/client/src/directives/anim.ts | 2 +- packages/client/src/directives/tooltip.ts | 18 +++++------ .../client/src/directives/user-preview.ts | 30 +++++++++---------- packages/client/src/os.ts | 6 ++-- .../src/pages/messaging/messaging-room.vue | 6 ++-- packages/client/src/pages/share.vue | 2 +- packages/client/src/pizzax.ts | 2 +- packages/client/src/router.ts | 6 ++-- packages/client/src/scripts/physics.ts | 4 +-- packages/client/src/scripts/theme.ts | 4 +-- packages/client/src/ui/deck/column.vue | 2 +- packages/client/src/widgets/calendar.vue | 4 +-- packages/client/src/widgets/digital-clock.vue | 6 ++-- packages/client/src/widgets/federation.vue | 4 +-- packages/client/src/widgets/memo.vue | 4 +-- packages/client/src/widgets/online-users.vue | 4 +-- packages/client/src/widgets/rss.vue | 4 +-- packages/client/src/widgets/slideshow.vue | 6 ++-- packages/client/src/widgets/trends.vue | 4 +-- 30 files changed, 75 insertions(+), 75 deletions(-) diff --git a/packages/client/src/components/analog-clock.vue b/packages/client/src/components/analog-clock.vue index 9ca511b6e..59b8e9730 100644 --- a/packages/client/src/components/analog-clock.vue +++ b/packages/client/src/components/analog-clock.vue @@ -90,7 +90,7 @@ onMounted(() => { const update = () => { if (enabled.value) { tick(); - setTimeout(update, 1000); + window.setTimeout(update, 1000); } }; update(); diff --git a/packages/client/src/components/captcha.vue b/packages/client/src/components/captcha.vue index 2a4181255..7fe499dc8 100644 --- a/packages/client/src/components/captcha.vue +++ b/packages/client/src/components/captcha.vue @@ -90,7 +90,7 @@ function requestRender() { 'error-callback': callback, }); } else { - setTimeout(requestRender, 1); + window.setTimeout(requestRender, 1); } } diff --git a/packages/client/src/components/form/input.vue b/packages/client/src/components/form/input.vue index 3533f4f27..7165671af 100644 --- a/packages/client/src/components/form/input.vue +++ b/packages/client/src/components/form/input.vue @@ -167,7 +167,7 @@ export default defineComponent({ // このコンポーネントが作成された時、非表示状態である場合がある // 非表示状態だと要素の幅などは0になってしまうので、定期的に計算する - const clock = setInterval(() => { + const clock = window.setInterval(() => { if (prefixEl.value) { if (prefixEl.value.offsetWidth) { inputEl.value.style.paddingLeft = prefixEl.value.offsetWidth + 'px'; @@ -181,7 +181,7 @@ export default defineComponent({ }, 100); onUnmounted(() => { - clearInterval(clock); + window.clearInterval(clock); }); }); }); diff --git a/packages/client/src/components/form/select.vue b/packages/client/src/components/form/select.vue index afc53ca9c..87196027a 100644 --- a/packages/client/src/components/form/select.vue +++ b/packages/client/src/components/form/select.vue @@ -117,7 +117,7 @@ export default defineComponent({ // このコンポーネントが作成された時、非表示状態である場合がある // 非表示状態だと要素の幅などは0になってしまうので、定期的に計算する - const clock = setInterval(() => { + const clock = window.setInterval(() => { if (prefixEl.value) { if (prefixEl.value.offsetWidth) { inputEl.value.style.paddingLeft = prefixEl.value.offsetWidth + 'px'; @@ -131,7 +131,7 @@ export default defineComponent({ }, 100); onUnmounted(() => { - clearInterval(clock); + window.clearInterval(clock); }); }); }); diff --git a/packages/client/src/components/global/sticky-container.vue b/packages/client/src/components/global/sticky-container.vue index 859b2c1d7..89d397f08 100644 --- a/packages/client/src/components/global/sticky-container.vue +++ b/packages/client/src/components/global/sticky-container.vue @@ -45,7 +45,7 @@ export default defineComponent({ calc(); const observer = new MutationObserver(() => { - setTimeout(() => { + window.setTimeout(() => { calc(); }, 100); }); diff --git a/packages/client/src/components/mini-chart.vue b/packages/client/src/components/mini-chart.vue index 2eb9ae8cb..8c74eae87 100644 --- a/packages/client/src/components/mini-chart.vue +++ b/packages/client/src/components/mini-chart.vue @@ -63,10 +63,10 @@ export default defineComponent({ this.draw(); // Vueが何故かWatchを発動させない場合があるので - this.clock = setInterval(this.draw, 1000); + this.clock = window.setInterval(this.draw, 1000); }, beforeUnmount() { - clearInterval(this.clock); + window.clearInterval(this.clock); }, methods: { draw() { diff --git a/packages/client/src/components/notification-toast.vue b/packages/client/src/components/notification-toast.vue index 5449409cc..fbd8467a6 100644 --- a/packages/client/src/components/notification-toast.vue +++ b/packages/client/src/components/notification-toast.vue @@ -29,7 +29,7 @@ export default defineComponent({ }; }, mounted() { - setTimeout(() => { + window.setTimeout(() => { this.showing = false; }, 6000); } diff --git a/packages/client/src/components/ripple.vue b/packages/client/src/components/ripple.vue index 272eacbc6..401e78e30 100644 --- a/packages/client/src/components/ripple.vue +++ b/packages/client/src/components/ripple.vue @@ -94,7 +94,7 @@ export default defineComponent({ } onMounted(() => { - setTimeout(() => { + window.setTimeout(() => { context.emit('end'); }, 1100); }); diff --git a/packages/client/src/components/toast.vue b/packages/client/src/components/toast.vue index 869182d8e..031aa4563 100644 --- a/packages/client/src/components/toast.vue +++ b/packages/client/src/components/toast.vue @@ -26,7 +26,7 @@ const showing = ref(true); const zIndex = os.claimZIndex('high'); onMounted(() => { - setTimeout(() => { + window.setTimeout(() => { showing.value = false; }, 4000); }); diff --git a/packages/client/src/components/ui/button.vue b/packages/client/src/components/ui/button.vue index 804a2e272..c7b6c8ba9 100644 --- a/packages/client/src/components/ui/button.vue +++ b/packages/client/src/components/ui/button.vue @@ -117,14 +117,14 @@ export default defineComponent({ const scale = calcCircleScale(e.target.clientWidth, e.target.clientHeight, circleCenterX, circleCenterY); - setTimeout(() => { + window.setTimeout(() => { ripple.style.transform = 'scale(' + (scale / 2) + ')'; }, 1); - setTimeout(() => { + window.setTimeout(() => { ripple.style.transition = 'all 1s ease'; ripple.style.opacity = '0'; }, 1000); - setTimeout(() => { + window.setTimeout(() => { if (this.$refs.ripples) this.$refs.ripples.removeChild(ripple); }, 2000); } diff --git a/packages/client/src/components/ui/modal.vue b/packages/client/src/components/ui/modal.vue index 3e2e59b27..c691c8c6d 100644 --- a/packages/client/src/components/ui/modal.vue +++ b/packages/client/src/components/ui/modal.vue @@ -211,7 +211,7 @@ export default defineComponent({ contentClicking = true; window.addEventListener('mouseup', e => { // click イベントより先に mouseup イベントが発生するかもしれないのでちょっと待つ - setTimeout(() => { + window.setTimeout(() => { contentClicking = false; }, 100); }, { passive: true, once: true }); diff --git a/packages/client/src/directives/anim.ts b/packages/client/src/directives/anim.ts index 1ceef984d..04e1c6a40 100644 --- a/packages/client/src/directives/anim.ts +++ b/packages/client/src/directives/anim.ts @@ -10,7 +10,7 @@ export default { }, mounted(src, binding, vn) { - setTimeout(() => { + window.setTimeout(() => { src.style.opacity = '1'; src.style.transform = 'none'; }, 1); diff --git a/packages/client/src/directives/tooltip.ts b/packages/client/src/directives/tooltip.ts index e14ee81df..fffde1487 100644 --- a/packages/client/src/directives/tooltip.ts +++ b/packages/client/src/directives/tooltip.ts @@ -21,7 +21,7 @@ export default { self.close = () => { if (self._close) { - clearInterval(self.checkTimer); + window.clearInterval(self.checkTimer); self._close(); self._close = null; } @@ -61,19 +61,19 @@ export default { }); el.addEventListener(start, () => { - clearTimeout(self.showTimer); - clearTimeout(self.hideTimer); - self.showTimer = setTimeout(self.show, delay); + window.clearTimeout(self.showTimer); + window.clearTimeout(self.hideTimer); + self.showTimer = window.setTimeout(self.show, delay); }, { passive: true }); el.addEventListener(end, () => { - clearTimeout(self.showTimer); - clearTimeout(self.hideTimer); - self.hideTimer = setTimeout(self.close, delay); + window.clearTimeout(self.showTimer); + window.clearTimeout(self.hideTimer); + self.hideTimer = window.setTimeout(self.close, delay); }, { passive: true }); el.addEventListener('click', () => { - clearTimeout(self.showTimer); + window.clearTimeout(self.showTimer); self.close(); }); }, @@ -85,6 +85,6 @@ export default { unmounted(el, binding, vn) { const self = el._tooltipDirective_; - clearInterval(self.checkTimer); + window.clearInterval(self.checkTimer); }, } as Directive; diff --git a/packages/client/src/directives/user-preview.ts b/packages/client/src/directives/user-preview.ts index 68d9e2816..cdd2afa19 100644 --- a/packages/client/src/directives/user-preview.ts +++ b/packages/client/src/directives/user-preview.ts @@ -30,11 +30,11 @@ export class UserPreview { source: this.el }, { mouseover: () => { - clearTimeout(this.hideTimer); + window.clearTimeout(this.hideTimer); }, mouseleave: () => { - clearTimeout(this.showTimer); - this.hideTimer = setTimeout(this.close, 500); + window.clearTimeout(this.showTimer); + this.hideTimer = window.setTimeout(this.close, 500); }, }, 'closed'); @@ -44,10 +44,10 @@ export class UserPreview { } }; - this.checkTimer = setInterval(() => { + this.checkTimer = window.setInterval(() => { if (!document.body.contains(this.el)) { - clearTimeout(this.showTimer); - clearTimeout(this.hideTimer); + window.clearTimeout(this.showTimer); + window.clearTimeout(this.hideTimer); this.close(); } }, 1000); @@ -56,7 +56,7 @@ export class UserPreview { @autobind private close() { if (this.promise) { - clearInterval(this.checkTimer); + window.clearInterval(this.checkTimer); this.promise.cancel(); this.promise = null; } @@ -64,21 +64,21 @@ export class UserPreview { @autobind private onMouseover() { - clearTimeout(this.showTimer); - clearTimeout(this.hideTimer); - this.showTimer = setTimeout(this.show, 500); + window.clearTimeout(this.showTimer); + window.clearTimeout(this.hideTimer); + this.showTimer = window.setTimeout(this.show, 500); } @autobind private onMouseleave() { - clearTimeout(this.showTimer); - clearTimeout(this.hideTimer); - this.hideTimer = setTimeout(this.close, 500); + window.clearTimeout(this.showTimer); + window.clearTimeout(this.hideTimer); + this.hideTimer = window.setTimeout(this.close, 500); } @autobind private onClick() { - clearTimeout(this.showTimer); + window.clearTimeout(this.showTimer); this.close(); } @@ -94,7 +94,7 @@ export class UserPreview { this.el.removeEventListener('mouseover', this.onMouseover); this.el.removeEventListener('mouseleave', this.onMouseleave); this.el.removeEventListener('click', this.onClick); - clearInterval(this.checkTimer); + window.clearInterval(this.checkTimer); } } diff --git a/packages/client/src/os.ts b/packages/client/src/os.ts index e6dd4567f..dd7fdea4b 100644 --- a/packages/client/src/os.ts +++ b/packages/client/src/os.ts @@ -83,7 +83,7 @@ export function promiseDialog>( onSuccess(res); } else { success.value = true; - setTimeout(() => { + window.setTimeout(() => { showing.value = false; }, 1000); } @@ -139,7 +139,7 @@ export async function popup(component: Component | typeof import('*.vue') | Prom const id = ++popupIdCount; const dispose = () => { // このsetTimeoutが無いと挙動がおかしくなる(autocompleteが閉じなくなる)。Vueのバグ? - setTimeout(() => { + window.setTimeout(() => { popups.value = popups.value.filter(popup => popup.id !== id); }, 0); }; @@ -329,7 +329,7 @@ export function select(props: { export function success() { return new Promise((resolve, reject) => { const showing = ref(true); - setTimeout(() => { + window.setTimeout(() => { showing.value = false; }, 1000); popup(import('@/components/waiting-dialog.vue'), { diff --git a/packages/client/src/pages/messaging/messaging-room.vue b/packages/client/src/pages/messaging/messaging-room.vue index 1bcee01d2..9a34551dd 100644 --- a/packages/client/src/pages/messaging/messaging-room.vue +++ b/packages/client/src/pages/messaging/messaging-room.vue @@ -162,7 +162,7 @@ const Component = defineComponent({ // もっと見るの交差検知を発火させないためにfetchは // スクロールが終わるまでfalseにしておく // scrollendのようなイベントはないのでsetTimeoutで - setTimeout(() => this.fetching = false, 300); + window.setTimeout(() => this.fetching = false, 300); }); }, @@ -300,9 +300,9 @@ const Component = defineComponent({ this.showIndicator = false; }); - if (this.timer) clearTimeout(this.timer); + if (this.timer) window.clearTimeout(this.timer); - this.timer = setTimeout(() => { + this.timer = window.setTimeout(() => { this.showIndicator = false; }, 4000); }, diff --git a/packages/client/src/pages/share.vue b/packages/client/src/pages/share.vue index bdd8500ee..5df6256fb 100644 --- a/packages/client/src/pages/share.vue +++ b/packages/client/src/pages/share.vue @@ -169,7 +169,7 @@ export default defineComponent({ window.close(); // 閉じなければ100ms後タイムラインに - setTimeout(() => { + window.setTimeout(() => { this.$router.push('/'); }, 100); } diff --git a/packages/client/src/pizzax.ts b/packages/client/src/pizzax.ts index dbbbfc228..fa35df551 100644 --- a/packages/client/src/pizzax.ts +++ b/packages/client/src/pizzax.ts @@ -54,7 +54,7 @@ export class Storage { if ($i) { // なぜかsetTimeoutしないとapi関数内でエラーになる(おそらく循環参照してることに原因がありそう) - setTimeout(() => { + window.setTimeout(() => { api('i/registry/get-all', { scope: ['client', this.key] }).then(kvs => { const cache = {}; for (const [k, v] of Object.entries(def)) { diff --git a/packages/client/src/router.ts b/packages/client/src/router.ts index 499afefbf..ec48b76fd 100644 --- a/packages/client/src/router.ts +++ b/packages/client/src/router.ts @@ -115,11 +115,11 @@ export const router = createRouter({ window._scroll = () => { // さらにHacky if (to.name === 'index') { window.scroll({ top: indexScrollPos, behavior: 'instant' }); - const i = setInterval(() => { + const i = window.setInterval(() => { window.scroll({ top: indexScrollPos, behavior: 'instant' }); }, 10); - setTimeout(() => { - clearInterval(i); + window.setTimeout(() => { + window.clearInterval(i); }, 500); } else { window.scroll({ top: 0, behavior: 'instant' }); diff --git a/packages/client/src/scripts/physics.ts b/packages/client/src/scripts/physics.ts index 445b6296e..36e476b6f 100644 --- a/packages/client/src/scripts/physics.ts +++ b/packages/client/src/scripts/physics.ts @@ -136,7 +136,7 @@ export function physics(container: HTMLElement) { } // 奈落に落ちたオブジェクトは消す - const intervalId = setInterval(() => { + const intervalId = window.setInterval(() => { for (const obj of objs) { if (obj.position.y > (containerHeight + 1024)) Matter.World.remove(world, obj); } @@ -146,7 +146,7 @@ export function physics(container: HTMLElement) { stop: () => { stop = true; Matter.Runner.stop(runner); - clearInterval(intervalId); + window.clearInterval(intervalId); } }; } diff --git a/packages/client/src/scripts/theme.ts b/packages/client/src/scripts/theme.ts index 3b7f003d0..85c087331 100644 --- a/packages/client/src/scripts/theme.ts +++ b/packages/client/src/scripts/theme.ts @@ -34,11 +34,11 @@ export const builtinThemes = [ let timeout = null; export function applyTheme(theme: Theme, persist = true) { - if (timeout) clearTimeout(timeout); + if (timeout) window.clearTimeout(timeout); document.documentElement.classList.add('_themeChanging_'); - timeout = setTimeout(() => { + timeout = window.setTimeout(() => { document.documentElement.classList.remove('_themeChanging_'); }, 1000); diff --git a/packages/client/src/ui/deck/column.vue b/packages/client/src/ui/deck/column.vue index d3c7cf821..1982d92ad 100644 --- a/packages/client/src/ui/deck/column.vue +++ b/packages/client/src/ui/deck/column.vue @@ -224,7 +224,7 @@ export default defineComponent({ // Chromeのバグで、Dragstartハンドラ内ですぐにDOMを変更する(=リアクティブなプロパティを変更する)とDragが終了してしまう // SEE: https://stackoverflow.com/questions/19639969/html5-dragend-event-firing-immediately - setTimeout(() => { + window.setTimeout(() => { this.dragging = true; }, 10); }, diff --git a/packages/client/src/widgets/calendar.vue b/packages/client/src/widgets/calendar.vue index d16d3424b..b0e3edcb1 100644 --- a/packages/client/src/widgets/calendar.vue +++ b/packages/client/src/widgets/calendar.vue @@ -104,9 +104,9 @@ const tick = () => { tick(); -const intervalId = setInterval(tick, 1000); +const intervalId = window.setInterval(tick, 1000); onUnmounted(() => { - clearInterval(intervalId); + window.clearInterval(intervalId); }); defineExpose({ diff --git a/packages/client/src/widgets/digital-clock.vue b/packages/client/src/widgets/digital-clock.vue index 637b0368b..62f052a69 100644 --- a/packages/client/src/widgets/digital-clock.vue +++ b/packages/client/src/widgets/digital-clock.vue @@ -67,12 +67,12 @@ const tick = () => { tick(); watch(() => widgetProps.showMs, () => { - if (intervalId) clearInterval(intervalId); - intervalId = setInterval(tick, widgetProps.showMs ? 10 : 1000); + if (intervalId) window.clearInterval(intervalId); + intervalId = window.setInterval(tick, widgetProps.showMs ? 10 : 1000); }, { immediate: true }); onUnmounted(() => { - clearInterval(intervalId); + window.clearInterval(intervalId); }); defineExpose({ diff --git a/packages/client/src/widgets/federation.vue b/packages/client/src/widgets/federation.vue index 5d53b683b..ed7350188 100644 --- a/packages/client/src/widgets/federation.vue +++ b/packages/client/src/widgets/federation.vue @@ -66,9 +66,9 @@ const fetch = async () => { onMounted(() => { fetch(); - const intervalId = setInterval(fetch, 1000 * 60); + const intervalId = window.setInterval(fetch, 1000 * 60); onUnmounted(() => { - clearInterval(intervalId); + window.clearInterval(intervalId); }); }); diff --git a/packages/client/src/widgets/memo.vue b/packages/client/src/widgets/memo.vue index 3dfc6eb5f..450598f65 100644 --- a/packages/client/src/widgets/memo.vue +++ b/packages/client/src/widgets/memo.vue @@ -51,8 +51,8 @@ const saveMemo = () => { const onChange = () => { changed.value = true; - clearTimeout(timeoutId); - timeoutId = setTimeout(saveMemo, 1000); + window.clearTimeout(timeoutId); + timeoutId = window.setTimeout(saveMemo, 1000); }; watch(() => defaultStore.reactiveState.memo, newText => { diff --git a/packages/client/src/widgets/online-users.vue b/packages/client/src/widgets/online-users.vue index 2d4768869..1746a8314 100644 --- a/packages/client/src/widgets/online-users.vue +++ b/packages/client/src/widgets/online-users.vue @@ -45,9 +45,9 @@ const tick = () => { onMounted(() => { tick(); - const intervalId = setInterval(tick, 1000 * 15); + const intervalId = window.setInterval(tick, 1000 * 15); onUnmounted(() => { - clearInterval(intervalId); + window.clearInterval(intervalId); }); }); diff --git a/packages/client/src/widgets/rss.vue b/packages/client/src/widgets/rss.vue index 7a2272d74..9e2e50360 100644 --- a/packages/client/src/widgets/rss.vue +++ b/packages/client/src/widgets/rss.vue @@ -62,9 +62,9 @@ watch(() => widgetProps.url, tick); onMounted(() => { tick(); - const intervalId = setInterval(tick, 60000); + const intervalId = window.setInterval(tick, 60000); onUnmounted(() => { - clearInterval(intervalId); + window.clearInterval(intervalId); }); }); diff --git a/packages/client/src/widgets/slideshow.vue b/packages/client/src/widgets/slideshow.vue index ac0c6c9e0..7b2e53968 100644 --- a/packages/client/src/widgets/slideshow.vue +++ b/packages/client/src/widgets/slideshow.vue @@ -59,7 +59,7 @@ const change = () => { slideB.value.style.backgroundImage = img; slideB.value.classList.add('anime'); - setTimeout(() => { + window.setTimeout(() => { // 既にこのウィジェットがunmountされていたら要素がない if (slideA.value == null) return; @@ -101,9 +101,9 @@ onMounted(() => { fetch(); } - const intervalId = setInterval(change, 10000); + const intervalId = window.setInterval(change, 10000); onUnmounted(() => { - clearInterval(intervalId); + window.clearInterval(intervalId); }); }); diff --git a/packages/client/src/widgets/trends.vue b/packages/client/src/widgets/trends.vue index 3905daa67..5768a8d5d 100644 --- a/packages/client/src/widgets/trends.vue +++ b/packages/client/src/widgets/trends.vue @@ -60,9 +60,9 @@ const fetch = () => { onMounted(() => { fetch(); - const intervalId = setInterval(fetch, 1000 * 60); + const intervalId = window.setInterval(fetch, 1000 * 60); onUnmounted(() => { - clearInterval(intervalId); + window.clearInterval(intervalId); }); });