From c2b3cbef20ed8e6ea53e463ef32c02c6e50de1d7 Mon Sep 17 00:00:00 2001 From: Peter Savchenko Date: Tue, 17 Oct 2023 22:23:40 +0300 Subject: [PATCH] fix(types): app state types improved --- package.json | 5 +++-- src/application/services/useAppState.ts | 4 +--- src/domain/index.ts | 3 ++- src/infrastructure/repository.ts | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 280873a2..fc3c82ea 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,12 @@ "author": "CodeX (https://codex.so)", "type": "module", "scripts": { - "dev": "vite", + "dev": "vite & yarn watch-ts", "build": "vue-tsc && vite build", "preview": "vite preview", "lint": "eslint . --ext .ts,.vue", - "lint:fix": "yarn lint --fix" + "lint:fix": "yarn lint --fix", + "watch-ts": "vue-tsc --noEmit --watch" }, "dependencies": { "@codexteam/icons": "^0.3.0", diff --git a/src/application/services/useAppState.ts b/src/application/services/useAppState.ts index 1bbc28ba..fb37d479 100644 --- a/src/application/services/useAppState.ts +++ b/src/application/services/useAppState.ts @@ -24,10 +24,8 @@ export const useAppState = createSharedComposable((): UseAppStateComposable => { /** * Subscribe to user changes in the App State - * - * @todo create better type definition for params */ - AppStateController.user((prop: 'user', value: User) => { + AppStateController.user((prop: 'user', value: User | null) => { if (prop === 'user') { user.value = value; } diff --git a/src/domain/index.ts b/src/domain/index.ts index 6d7b91f8..7cbee217 100644 --- a/src/domain/index.ts +++ b/src/domain/index.ts @@ -33,7 +33,8 @@ const userService = new UserService(eventBus, repositories.user); * Allows to subscribe to store data changes */ export const AppStateController = { - user: (callback) => repositories.user.onStoreChange(callback), + // eslint-disable-next-line @typescript-eslint/no-magic-numbers + user: (callback: Parameters[0]) => repositories.user.setStoreChangeCallback(callback), }; export { diff --git a/src/infrastructure/repository.ts b/src/infrastructure/repository.ts index 2dbfffd8..1bb3597a 100644 --- a/src/infrastructure/repository.ts +++ b/src/infrastructure/repository.ts @@ -1,4 +1,4 @@ -import { SubscribableStore, type PropChangeCallback } from './storage/abstract/subscribable'; +import { SubscribableStore, type PropChangeCallback } from './storage/abstract/subscribable'; /** * Base class for repositories @@ -17,7 +17,7 @@ export default abstract class Repository { * * @param callback - callback that will be called on store change. Accepts new store data */ - public onStoreChange(callback: PropChangeCallback ): void { + public setStoreChangeCallback(callback: PropChangeCallback ): void { if (this.store instanceof SubscribableStore) { this.store.subscribe(callback); } else {