Refactor DI for simplicity and type safety
This commit improves the dependency injection mechanism by introducing a custom `injectKey` function. Key improvements are: - Enforced type consistency during dependency registration and instantiation. - Simplified injection process, abstracting away the complexity with a uniform API, regardless of the dependency's lifetime. - Eliminated the possibility of `undefined` returns during dependency injection, promoting fail-fast behavior. - Removed the necessity for type casting to `symbol` for injection keys in unit tests by using existing types. - Consalidated imports, combining keys and injection functions in one `import` statement.
This commit is contained in:
@@ -13,9 +13,9 @@
|
||||
|
||||
<script lang="ts">
|
||||
import {
|
||||
defineComponent, ref, computed, inject,
|
||||
defineComponent, ref, computed,
|
||||
} from 'vue';
|
||||
import { InjectionKeys } from '@/presentation/injectionSymbols';
|
||||
import { injectKey } from '@/presentation/injectionSymbols';
|
||||
import { SaveFileDialog, FileType } from '@/infrastructure/SaveFileDialog';
|
||||
import ModalDialog from '@/presentation/components/Shared/Modal/ModalDialog.vue';
|
||||
import { IReadOnlyCategoryCollectionState } from '@/application/Context/State/ICategoryCollectionState';
|
||||
@@ -34,8 +34,8 @@ export default defineComponent({
|
||||
ModalDialog,
|
||||
},
|
||||
setup() {
|
||||
const { currentState } = inject(InjectionKeys.useCollectionState)();
|
||||
const { isDesktop } = inject(InjectionKeys.useRuntimeEnvironment);
|
||||
const { currentState } = injectKey((keys) => keys.useCollectionState);
|
||||
const { isDesktop } = injectKey((keys) => keys.useRuntimeEnvironment);
|
||||
|
||||
const areInstructionsVisible = ref(false);
|
||||
const fileName = computed<string>(() => buildFileName(currentState.value.collection.scripting));
|
||||
|
||||
Reference in New Issue
Block a user