Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: injectの書き方をより良い形に #2497

Merged
merged 2 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
Loading