Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/components/Sing/SequencerPitch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<script setup lang="ts">
import { ref, watch, computed, onUnmounted, onMounted } from "vue";
import { useMounted } from "@/composables/useMounted";

Check failure on line 9 in src/components/Sing/SequencerPitch.vue

View workflow job for this annotation

GitHub Actions / lint

`@/composables/useMounted` import should occur after import of `async-lock`
import * as PIXI from "pixi.js";
import AsyncLock from "async-lock";
import { useStore } from "@/store";
Expand Down Expand Up @@ -91,6 +92,8 @@
return store.getters.SELECTED_TRACK.singer != undefined;
});

const { mounted } = useMounted();

const canvasContainer = ref<HTMLElement | null>(null);
const canvas = ref<HTMLCanvasElement | null>(null);
let resizeObserver: ResizeObserver | undefined;
Expand Down Expand Up @@ -276,9 +279,6 @@
renderInNextFrame = true;
};

// onMountedのときにtrueになるだけのref
const mounted = ref(false);

const asyncLock = new AsyncLock({ maxPending: 1 });

// NOTE: mountedをwatchしているので、onMountedの直後に必ず1回実行される
Expand Down Expand Up @@ -332,8 +332,6 @@
);

onMounted(() => {
mounted.value = true;

const canvasContainerElement = canvasContainer.value;
const canvasElement = canvas.value;
if (!canvasContainerElement) {
Expand Down
6 changes: 3 additions & 3 deletions src/composables/useAutoScrollOnEdge.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComputedRef, onMounted, onUnmounted, ref, Ref, watch } from "vue";
import { ComputedRef, onMounted, onUnmounted, Ref, watch } from "vue";
import { useMounted } from "@/composables/useMounted";
import {
calcMinimumDistanceVectorRectAndPoint,
Rect,
Expand Down Expand Up @@ -64,7 +65,7 @@ export const useAutoScrollOnEdge = (
autoScrollState.animationId = requestAnimationFrame(autoScrollAnimation);
};

const mounted = ref(false);
const { mounted } = useMounted();

watch([enable, mounted], ([enableValue, mountedValue]) => {
if (!mountedValue) {
Expand Down Expand Up @@ -110,7 +111,6 @@ export const useAutoScrollOnEdge = (
};

onMounted(() => {
mounted.value = true;
window.addEventListener("mousemove", onMouseMove);
});

Expand Down
15 changes: 15 additions & 0 deletions src/composables/useMounted.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ref, onMounted } from "vue";

/**
* マウントしたときにtrueになるフラグを提供する。
* マウントしてすぐ一度だけ処理を実行したいときに便利。
*/
export function useMounted() {
const mounted = ref(false);

onMounted(() => {
mounted.value = true;
});

return { mounted };
}
Loading