From e741c2b913b0dd0a7a5be809ac0b283a8d453b30 Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Fri, 27 Aug 2021 18:11:25 +0300 Subject: [PATCH] refactor: ui store events --- src/stores/AuthStore.ts | 12 ++++++++++-- src/stores/UIStore.ts | 27 +++++++++++++++++++++------ src/stores/UserStore.ts | 7 +++++++ 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/stores/AuthStore.ts b/src/stores/AuthStore.ts index 4f389b6..dea9ad4 100644 --- a/src/stores/AuthStore.ts +++ b/src/stores/AuthStore.ts @@ -1,10 +1,18 @@ import { makeAutoObservable } from 'mobx'; import Cookies from 'js-cookie'; -import RootStore from './RootStore'; -import AuthService from 'services/AuthService'; import { AxiosInstance } from 'axios'; import { IDataResult, ILoginResult } from 'interfaces'; +/** + * Services + */ +import AuthService from 'services/AuthService'; + +/** + * Stores + */ +import RootStore from './RootStore'; + export default class AuthStore { public root: RootStore; diff --git a/src/stores/UIStore.ts b/src/stores/UIStore.ts index c34b068..6bb18bf 100644 --- a/src/stores/UIStore.ts +++ b/src/stores/UIStore.ts @@ -1,8 +1,12 @@ import { makeAutoObservable, observable } from 'mobx'; import { createBrowserHistory } from 'history'; -import RootStore from './RootStore'; import { IWindowDimensions } from 'interfaces'; +/** + * Stores + */ +import RootStore from './RootStore'; + export default class UIStore { public root: RootStore; @@ -20,22 +24,33 @@ export default class UIStore { windowDimensions: observable.struct, }); + this.setupListeners(); + } + + /** + * Initialize some listeners + */ + private setupListeners(): void { + /** + * Pathname changed + */ this.history.listen(({ pathname }) => { console.log(`[history]: pathname changed to "${pathname}"`); this.location = pathname; }); - window.onresize = () => { - this.windowDimensions = this.getWindowDimensions(); - }; + /** + * Window dimensions updated + */ + window.onresize = () => this.updateWindowDimensions(); } public setLocation(location: string): void { this.location = location; } - private getWindowDimensions(): IWindowDimensions { - return { width: window.innerWidth, height: window.innerHeight }; + private updateWindowDimensions(): void { + this.windowDimensions = { width: window.innerWidth, height: window.innerHeight }; } get isDesktop() { diff --git a/src/stores/UserStore.ts b/src/stores/UserStore.ts index 64d2f39..e3b3a8a 100644 --- a/src/stores/UserStore.ts +++ b/src/stores/UserStore.ts @@ -2,7 +2,14 @@ import { AxiosInstance } from 'axios'; import { makeAutoObservable, runInAction } from 'mobx'; import { IUserResult, IUser } from 'interfaces'; +/** + * Services + */ import UserService from 'services/UserService'; + +/** + * Stores + */ import RootStore from './RootStore'; export default class UserStore {