From b74549bfc68e8e84c3f2b3ec107ca1bc1b7c6e6a Mon Sep 17 00:00:00 2001 From: VardanHakobyan Date: Sat, 19 Jun 2021 19:05:29 +0300 Subject: [PATCH] refactor: move observers and streamers to separate methods, code cleanup --- .../ui_models/app_state/account_menu_state.ts | 18 ++++++++++++------ .../ui_models/app_state/app_state.ts | 1 - 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/ui_models/app_state/account_menu_state.ts b/app/assets/javascripts/ui_models/app_state/account_menu_state.ts index cf354e884..2d215a53c 100644 --- a/app/assets/javascripts/ui_models/app_state/account_menu_state.ts +++ b/app/assets/javascripts/ui_models/app_state/account_menu_state.ts @@ -16,8 +16,7 @@ export class AccountMenuState { constructor( private application: WebApplication, - appObservers: (() => void)[], - appEventListeners: (() => void)[] + private appEventListeners: (() => void)[] ) { makeObservable(this, { show: observable, @@ -40,15 +39,22 @@ export class AccountMenuState { notesAndTagsCount: computed }); - appObservers.push( - application.addEventObserver(async () => { + this.addAppEventObserver(); + this.streamNotesAndTags(); + } + + addAppEventObserver = (): void => { + this.appEventListeners.push( + this.application.addEventObserver(async () => { runInAction(() => { this.setServer(this.application.getHost()); }); }, ApplicationEvent.Launched) ); + }; - appEventListeners.push( + streamNotesAndTags = (): void => { + this.appEventListeners.push( this.application.streamItems( [ContentType.Note, ContentType.Tag], () => { @@ -58,7 +64,7 @@ export class AccountMenuState { } ) ); - } + }; setShow = (show: boolean): void => { this.show = show; diff --git a/app/assets/javascripts/ui_models/app_state/app_state.ts b/app/assets/javascripts/ui_models/app_state/app_state.ts index 5818fe1c2..fd98a276b 100644 --- a/app/assets/javascripts/ui_models/app_state/app_state.ts +++ b/app/assets/javascripts/ui_models/app_state/app_state.ts @@ -107,7 +107,6 @@ export class AppState { this.accountMenu = new AccountMenuState( application, this.appEventObserverRemovers, - this.appEventObserverRemovers ); this.searchOptions = new SearchOptionsState( application,