refactor(client): specify global scope

This commit is contained in:
syuilo 2022-01-16 10:14:14 +09:00
parent b312846ff6
commit 8322c90834
30 changed files with 75 additions and 75 deletions

View File

@ -90,7 +90,7 @@ onMounted(() => {
const update = () => { const update = () => {
if (enabled.value) { if (enabled.value) {
tick(); tick();
setTimeout(update, 1000); window.setTimeout(update, 1000);
} }
}; };
update(); update();

View File

@ -90,7 +90,7 @@ function requestRender() {
'error-callback': callback, 'error-callback': callback,
}); });
} else { } else {
setTimeout(requestRender, 1); window.setTimeout(requestRender, 1);
} }
} }

View File

@ -167,7 +167,7 @@ export default defineComponent({
// //
// 0 // 0
const clock = setInterval(() => { const clock = window.setInterval(() => {
if (prefixEl.value) { if (prefixEl.value) {
if (prefixEl.value.offsetWidth) { if (prefixEl.value.offsetWidth) {
inputEl.value.style.paddingLeft = prefixEl.value.offsetWidth + 'px'; inputEl.value.style.paddingLeft = prefixEl.value.offsetWidth + 'px';
@ -181,7 +181,7 @@ export default defineComponent({
}, 100); }, 100);
onUnmounted(() => { onUnmounted(() => {
clearInterval(clock); window.clearInterval(clock);
}); });
}); });
}); });

View File

@ -117,7 +117,7 @@ export default defineComponent({
// //
// 0 // 0
const clock = setInterval(() => { const clock = window.setInterval(() => {
if (prefixEl.value) { if (prefixEl.value) {
if (prefixEl.value.offsetWidth) { if (prefixEl.value.offsetWidth) {
inputEl.value.style.paddingLeft = prefixEl.value.offsetWidth + 'px'; inputEl.value.style.paddingLeft = prefixEl.value.offsetWidth + 'px';
@ -131,7 +131,7 @@ export default defineComponent({
}, 100); }, 100);
onUnmounted(() => { onUnmounted(() => {
clearInterval(clock); window.clearInterval(clock);
}); });
}); });
}); });

View File

@ -45,7 +45,7 @@ export default defineComponent({
calc(); calc();
const observer = new MutationObserver(() => { const observer = new MutationObserver(() => {
setTimeout(() => { window.setTimeout(() => {
calc(); calc();
}, 100); }, 100);
}); });

View File

@ -63,10 +63,10 @@ export default defineComponent({
this.draw(); this.draw();
// VueWatch // VueWatch
this.clock = setInterval(this.draw, 1000); this.clock = window.setInterval(this.draw, 1000);
}, },
beforeUnmount() { beforeUnmount() {
clearInterval(this.clock); window.clearInterval(this.clock);
}, },
methods: { methods: {
draw() { draw() {

View File

@ -29,7 +29,7 @@ export default defineComponent({
}; };
}, },
mounted() { mounted() {
setTimeout(() => { window.setTimeout(() => {
this.showing = false; this.showing = false;
}, 6000); }, 6000);
} }

View File

@ -94,7 +94,7 @@ export default defineComponent({
} }
onMounted(() => { onMounted(() => {
setTimeout(() => { window.setTimeout(() => {
context.emit('end'); context.emit('end');
}, 1100); }, 1100);
}); });

View File

@ -26,7 +26,7 @@ const showing = ref(true);
const zIndex = os.claimZIndex('high'); const zIndex = os.claimZIndex('high');
onMounted(() => { onMounted(() => {
setTimeout(() => { window.setTimeout(() => {
showing.value = false; showing.value = false;
}, 4000); }, 4000);
}); });

View File

@ -117,14 +117,14 @@ export default defineComponent({
const scale = calcCircleScale(e.target.clientWidth, e.target.clientHeight, circleCenterX, circleCenterY); const scale = calcCircleScale(e.target.clientWidth, e.target.clientHeight, circleCenterX, circleCenterY);
setTimeout(() => { window.setTimeout(() => {
ripple.style.transform = 'scale(' + (scale / 2) + ')'; ripple.style.transform = 'scale(' + (scale / 2) + ')';
}, 1); }, 1);
setTimeout(() => { window.setTimeout(() => {
ripple.style.transition = 'all 1s ease'; ripple.style.transition = 'all 1s ease';
ripple.style.opacity = '0'; ripple.style.opacity = '0';
}, 1000); }, 1000);
setTimeout(() => { window.setTimeout(() => {
if (this.$refs.ripples) this.$refs.ripples.removeChild(ripple); if (this.$refs.ripples) this.$refs.ripples.removeChild(ripple);
}, 2000); }, 2000);
} }

View File

@ -211,7 +211,7 @@ export default defineComponent({
contentClicking = true; contentClicking = true;
window.addEventListener('mouseup', e => { window.addEventListener('mouseup', e => {
// click mouseup // click mouseup
setTimeout(() => { window.setTimeout(() => {
contentClicking = false; contentClicking = false;
}, 100); }, 100);
}, { passive: true, once: true }); }, { passive: true, once: true });

View File

@ -10,7 +10,7 @@ export default {
}, },
mounted(src, binding, vn) { mounted(src, binding, vn) {
setTimeout(() => { window.setTimeout(() => {
src.style.opacity = '1'; src.style.opacity = '1';
src.style.transform = 'none'; src.style.transform = 'none';
}, 1); }, 1);

View File

@ -21,7 +21,7 @@ export default {
self.close = () => { self.close = () => {
if (self._close) { if (self._close) {
clearInterval(self.checkTimer); window.clearInterval(self.checkTimer);
self._close(); self._close();
self._close = null; self._close = null;
} }
@ -61,19 +61,19 @@ export default {
}); });
el.addEventListener(start, () => { el.addEventListener(start, () => {
clearTimeout(self.showTimer); window.clearTimeout(self.showTimer);
clearTimeout(self.hideTimer); window.clearTimeout(self.hideTimer);
self.showTimer = setTimeout(self.show, delay); self.showTimer = window.setTimeout(self.show, delay);
}, { passive: true }); }, { passive: true });
el.addEventListener(end, () => { el.addEventListener(end, () => {
clearTimeout(self.showTimer); window.clearTimeout(self.showTimer);
clearTimeout(self.hideTimer); window.clearTimeout(self.hideTimer);
self.hideTimer = setTimeout(self.close, delay); self.hideTimer = window.setTimeout(self.close, delay);
}, { passive: true }); }, { passive: true });
el.addEventListener('click', () => { el.addEventListener('click', () => {
clearTimeout(self.showTimer); window.clearTimeout(self.showTimer);
self.close(); self.close();
}); });
}, },
@ -85,6 +85,6 @@ export default {
unmounted(el, binding, vn) { unmounted(el, binding, vn) {
const self = el._tooltipDirective_; const self = el._tooltipDirective_;
clearInterval(self.checkTimer); window.clearInterval(self.checkTimer);
}, },
} as Directive; } as Directive;

View File

@ -30,11 +30,11 @@ export class UserPreview {
source: this.el source: this.el
}, { }, {
mouseover: () => { mouseover: () => {
clearTimeout(this.hideTimer); window.clearTimeout(this.hideTimer);
}, },
mouseleave: () => { mouseleave: () => {
clearTimeout(this.showTimer); window.clearTimeout(this.showTimer);
this.hideTimer = setTimeout(this.close, 500); this.hideTimer = window.setTimeout(this.close, 500);
}, },
}, 'closed'); }, 'closed');
@ -44,10 +44,10 @@ export class UserPreview {
} }
}; };
this.checkTimer = setInterval(() => { this.checkTimer = window.setInterval(() => {
if (!document.body.contains(this.el)) { if (!document.body.contains(this.el)) {
clearTimeout(this.showTimer); window.clearTimeout(this.showTimer);
clearTimeout(this.hideTimer); window.clearTimeout(this.hideTimer);
this.close(); this.close();
} }
}, 1000); }, 1000);
@ -56,7 +56,7 @@ export class UserPreview {
@autobind @autobind
private close() { private close() {
if (this.promise) { if (this.promise) {
clearInterval(this.checkTimer); window.clearInterval(this.checkTimer);
this.promise.cancel(); this.promise.cancel();
this.promise = null; this.promise = null;
} }
@ -64,21 +64,21 @@ export class UserPreview {
@autobind @autobind
private onMouseover() { private onMouseover() {
clearTimeout(this.showTimer); window.clearTimeout(this.showTimer);
clearTimeout(this.hideTimer); window.clearTimeout(this.hideTimer);
this.showTimer = setTimeout(this.show, 500); this.showTimer = window.setTimeout(this.show, 500);
} }
@autobind @autobind
private onMouseleave() { private onMouseleave() {
clearTimeout(this.showTimer); window.clearTimeout(this.showTimer);
clearTimeout(this.hideTimer); window.clearTimeout(this.hideTimer);
this.hideTimer = setTimeout(this.close, 500); this.hideTimer = window.setTimeout(this.close, 500);
} }
@autobind @autobind
private onClick() { private onClick() {
clearTimeout(this.showTimer); window.clearTimeout(this.showTimer);
this.close(); this.close();
} }
@ -94,7 +94,7 @@ export class UserPreview {
this.el.removeEventListener('mouseover', this.onMouseover); this.el.removeEventListener('mouseover', this.onMouseover);
this.el.removeEventListener('mouseleave', this.onMouseleave); this.el.removeEventListener('mouseleave', this.onMouseleave);
this.el.removeEventListener('click', this.onClick); this.el.removeEventListener('click', this.onClick);
clearInterval(this.checkTimer); window.clearInterval(this.checkTimer);
} }
} }

View File

@ -83,7 +83,7 @@ export function promiseDialog<T extends Promise<any>>(
onSuccess(res); onSuccess(res);
} else { } else {
success.value = true; success.value = true;
setTimeout(() => { window.setTimeout(() => {
showing.value = false; showing.value = false;
}, 1000); }, 1000);
} }
@ -139,7 +139,7 @@ export async function popup(component: Component | typeof import('*.vue') | Prom
const id = ++popupIdCount; const id = ++popupIdCount;
const dispose = () => { const dispose = () => {
// このsetTimeoutが無いと挙動がおかしくなる(autocompleteが閉じなくなる)。Vueのバグ // このsetTimeoutが無いと挙動がおかしくなる(autocompleteが閉じなくなる)。Vueのバグ
setTimeout(() => { window.setTimeout(() => {
popups.value = popups.value.filter(popup => popup.id !== id); popups.value = popups.value.filter(popup => popup.id !== id);
}, 0); }, 0);
}; };
@ -329,7 +329,7 @@ export function select(props: {
export function success() { export function success() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const showing = ref(true); const showing = ref(true);
setTimeout(() => { window.setTimeout(() => {
showing.value = false; showing.value = false;
}, 1000); }, 1000);
popup(import('@/components/waiting-dialog.vue'), { popup(import('@/components/waiting-dialog.vue'), {

View File

@ -162,7 +162,7 @@ const Component = defineComponent({
// fetch // fetch
// false // false
// scrollendsetTimeout // scrollendsetTimeout
setTimeout(() => this.fetching = false, 300); window.setTimeout(() => this.fetching = false, 300);
}); });
}, },
@ -300,9 +300,9 @@ const Component = defineComponent({
this.showIndicator = false; 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; this.showIndicator = false;
}, 4000); }, 4000);
}, },

View File

@ -169,7 +169,7 @@ export default defineComponent({
window.close(); window.close();
// 100ms // 100ms
setTimeout(() => { window.setTimeout(() => {
this.$router.push('/'); this.$router.push('/');
}, 100); }, 100);
} }

View File

@ -54,7 +54,7 @@ export class Storage<T extends StateDef> {
if ($i) { if ($i) {
// なぜかsetTimeoutしないとapi関数内でエラーになる(おそらく循環参照してることに原因がありそう) // なぜかsetTimeoutしないとapi関数内でエラーになる(おそらく循環参照してることに原因がありそう)
setTimeout(() => { window.setTimeout(() => {
api('i/registry/get-all', { scope: ['client', this.key] }).then(kvs => { api('i/registry/get-all', { scope: ['client', this.key] }).then(kvs => {
const cache = {}; const cache = {};
for (const [k, v] of Object.entries(def)) { for (const [k, v] of Object.entries(def)) {

View File

@ -115,11 +115,11 @@ export const router = createRouter({
window._scroll = () => { // さらにHacky window._scroll = () => { // さらにHacky
if (to.name === 'index') { if (to.name === 'index') {
window.scroll({ top: indexScrollPos, behavior: 'instant' }); window.scroll({ top: indexScrollPos, behavior: 'instant' });
const i = setInterval(() => { const i = window.setInterval(() => {
window.scroll({ top: indexScrollPos, behavior: 'instant' }); window.scroll({ top: indexScrollPos, behavior: 'instant' });
}, 10); }, 10);
setTimeout(() => { window.setTimeout(() => {
clearInterval(i); window.clearInterval(i);
}, 500); }, 500);
} else { } else {
window.scroll({ top: 0, behavior: 'instant' }); window.scroll({ top: 0, behavior: 'instant' });

View File

@ -136,7 +136,7 @@ export function physics(container: HTMLElement) {
} }
// 奈落に落ちたオブジェクトは消す // 奈落に落ちたオブジェクトは消す
const intervalId = setInterval(() => { const intervalId = window.setInterval(() => {
for (const obj of objs) { for (const obj of objs) {
if (obj.position.y > (containerHeight + 1024)) Matter.World.remove(world, obj); if (obj.position.y > (containerHeight + 1024)) Matter.World.remove(world, obj);
} }
@ -146,7 +146,7 @@ export function physics(container: HTMLElement) {
stop: () => { stop: () => {
stop = true; stop = true;
Matter.Runner.stop(runner); Matter.Runner.stop(runner);
clearInterval(intervalId); window.clearInterval(intervalId);
} }
}; };
} }

View File

@ -34,11 +34,11 @@ export const builtinThemes = [
let timeout = null; let timeout = null;
export function applyTheme(theme: Theme, persist = true) { export function applyTheme(theme: Theme, persist = true) {
if (timeout) clearTimeout(timeout); if (timeout) window.clearTimeout(timeout);
document.documentElement.classList.add('_themeChanging_'); document.documentElement.classList.add('_themeChanging_');
timeout = setTimeout(() => { timeout = window.setTimeout(() => {
document.documentElement.classList.remove('_themeChanging_'); document.documentElement.classList.remove('_themeChanging_');
}, 1000); }, 1000);

View File

@ -224,7 +224,7 @@ export default defineComponent({
// ChromeDragstartDOM(=)Drag // ChromeDragstartDOM(=)Drag
// SEE: https://stackoverflow.com/questions/19639969/html5-dragend-event-firing-immediately // SEE: https://stackoverflow.com/questions/19639969/html5-dragend-event-firing-immediately
setTimeout(() => { window.setTimeout(() => {
this.dragging = true; this.dragging = true;
}, 10); }, 10);
}, },

View File

@ -104,9 +104,9 @@ const tick = () => {
tick(); tick();
const intervalId = setInterval(tick, 1000); const intervalId = window.setInterval(tick, 1000);
onUnmounted(() => { onUnmounted(() => {
clearInterval(intervalId); window.clearInterval(intervalId);
}); });
defineExpose<WidgetComponentExpose>({ defineExpose<WidgetComponentExpose>({

View File

@ -67,12 +67,12 @@ const tick = () => {
tick(); tick();
watch(() => widgetProps.showMs, () => { watch(() => widgetProps.showMs, () => {
if (intervalId) clearInterval(intervalId); if (intervalId) window.clearInterval(intervalId);
intervalId = setInterval(tick, widgetProps.showMs ? 10 : 1000); intervalId = window.setInterval(tick, widgetProps.showMs ? 10 : 1000);
}, { immediate: true }); }, { immediate: true });
onUnmounted(() => { onUnmounted(() => {
clearInterval(intervalId); window.clearInterval(intervalId);
}); });
defineExpose<WidgetComponentExpose>({ defineExpose<WidgetComponentExpose>({

View File

@ -66,9 +66,9 @@ const fetch = async () => {
onMounted(() => { onMounted(() => {
fetch(); fetch();
const intervalId = setInterval(fetch, 1000 * 60); const intervalId = window.setInterval(fetch, 1000 * 60);
onUnmounted(() => { onUnmounted(() => {
clearInterval(intervalId); window.clearInterval(intervalId);
}); });
}); });

View File

@ -51,8 +51,8 @@ const saveMemo = () => {
const onChange = () => { const onChange = () => {
changed.value = true; changed.value = true;
clearTimeout(timeoutId); window.clearTimeout(timeoutId);
timeoutId = setTimeout(saveMemo, 1000); timeoutId = window.setTimeout(saveMemo, 1000);
}; };
watch(() => defaultStore.reactiveState.memo, newText => { watch(() => defaultStore.reactiveState.memo, newText => {

View File

@ -45,9 +45,9 @@ const tick = () => {
onMounted(() => { onMounted(() => {
tick(); tick();
const intervalId = setInterval(tick, 1000 * 15); const intervalId = window.setInterval(tick, 1000 * 15);
onUnmounted(() => { onUnmounted(() => {
clearInterval(intervalId); window.clearInterval(intervalId);
}); });
}); });

View File

@ -62,9 +62,9 @@ watch(() => widgetProps.url, tick);
onMounted(() => { onMounted(() => {
tick(); tick();
const intervalId = setInterval(tick, 60000); const intervalId = window.setInterval(tick, 60000);
onUnmounted(() => { onUnmounted(() => {
clearInterval(intervalId); window.clearInterval(intervalId);
}); });
}); });

View File

@ -59,7 +59,7 @@ const change = () => {
slideB.value.style.backgroundImage = img; slideB.value.style.backgroundImage = img;
slideB.value.classList.add('anime'); slideB.value.classList.add('anime');
setTimeout(() => { window.setTimeout(() => {
// unmount // unmount
if (slideA.value == null) return; if (slideA.value == null) return;
@ -101,9 +101,9 @@ onMounted(() => {
fetch(); fetch();
} }
const intervalId = setInterval(change, 10000); const intervalId = window.setInterval(change, 10000);
onUnmounted(() => { onUnmounted(() => {
clearInterval(intervalId); window.clearInterval(intervalId);
}); });
}); });

View File

@ -60,9 +60,9 @@ const fetch = () => {
onMounted(() => { onMounted(() => {
fetch(); fetch();
const intervalId = setInterval(fetch, 1000 * 60); const intervalId = window.setInterval(fetch, 1000 * 60);
onUnmounted(() => { onUnmounted(() => {
clearInterval(intervalId); window.clearInterval(intervalId);
}); });
}); });