Skip to content

Commit

Permalink
Merge pull request #53 from codex-team/fix/app-state-types
Browse files Browse the repository at this point in the history
fix(types): app state types improved
  • Loading branch information
neSpecc authored Oct 18, 2023
2 parents 54beec5 + c2b3cbe commit c069fd8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"author": "CodeX <[email protected]> (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",
Expand Down
4 changes: 1 addition & 3 deletions src/application/services/useAppState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/domain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof repositories.user.setStoreChangeCallback>[0]) => repositories.user.setStoreChangeCallback(callback),
};

export {
Expand Down
4 changes: 2 additions & 2 deletions src/infrastructure/repository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SubscribableStore, type PropChangeCallback } from './storage/abstract/subscribable';
import { SubscribableStore, type PropChangeCallback } from './storage/abstract/subscribable';

/**
* Base class for repositories
Expand All @@ -17,7 +17,7 @@ export default abstract class Repository<Store, StoreData> {
*
* @param callback - callback that will be called on store change. Accepts new store data
*/
public onStoreChange(callback: PropChangeCallback<StoreData> ): void {
public setStoreChangeCallback(callback: PropChangeCallback<StoreData> ): void {
if (this.store instanceof SubscribableStore) {
this.store.subscribe(callback);
} else {
Expand Down

0 comments on commit c069fd8

Please sign in to comment.