Skip to content

Commit

Permalink
refactor: injectの書き方をより良い形に (#2497)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshiba authored Jan 25, 2025
1 parent 39d2948 commit af114ee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
9 changes: 2 additions & 7 deletions src/components/Dialog/DictionaryEditWordDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,7 @@
<script setup lang="ts">
import { inject, ref } from "vue";
import { QInput } from "quasar";
import {
DictionaryManageDialogContext,
dictionaryManageDialogContextKey,
} from "./DictionaryManageDialog.vue";
import { dictionaryManageDialogContextKey } from "./DictionaryManageDialog.vue";
import AudioAccent from "@/components/Talk/AudioAccent.vue";
import ContextMenu from "@/components/Menu/ContextMenu/Container.vue";
import { useRightClickContextMenu } from "@/composables/useRightClickContextMenu";
Expand All @@ -175,9 +172,7 @@ import type { FetchAudioResult } from "@/store/type";
const store = useStore();
const context = inject<DictionaryManageDialogContext>(
dictionaryManageDialogContextKey,
);
const context = inject(dictionaryManageDialogContextKey);
if (context == undefined)
throw new Error(`dictionaryManageDialogContext == undefined`);
const {
Expand Down
10 changes: 4 additions & 6 deletions src/components/Dialog/DictionaryManageDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,9 @@
</template>

<script lang="ts">
import { Ref, ComputedRef } from "vue";
import { Ref, ComputedRef, type InjectionKey } from "vue";
export const dictionaryManageDialogContextKey = "dictionaryManageDialogContext";
export interface DictionaryManageDialogContext {
export const dictionaryManageDialogContextKey: InjectionKey<{
wordEditing: Ref<boolean>;
surfaceInput: Ref<QInput | undefined>;
selectedId: Ref<string>;
Expand All @@ -153,7 +151,7 @@ export interface DictionaryManageDialogContext {
toInitialState: () => void;
toWordEditingState: () => void;
cancel: () => void;
}
}> = Symbol("dictionaryManageDialogContextKey");
</script>

<script setup lang="ts">
Expand Down Expand Up @@ -426,7 +424,7 @@ const toDialogClosedState = () => {
dictionaryManageDialogOpenedComputed.value = false;
};
provide<DictionaryManageDialogContext>(dictionaryManageDialogContextKey, {
provide(dictionaryManageDialogContextKey, {
wordEditing,
surfaceInput,
selectedId,
Expand Down

0 comments on commit af114ee

Please sign in to comment.