refactor: move observers and streamers to separate methods, code cleanup

This commit is contained in:
VardanHakobyan
2021-06-19 19:05:29 +03:00
parent bba1d089bf
commit b74549bfc6
2 changed files with 12 additions and 7 deletions

View File

@@ -16,8 +16,7 @@ export class AccountMenuState {
constructor( constructor(
private application: WebApplication, private application: WebApplication,
appObservers: (() => void)[], private appEventListeners: (() => void)[]
appEventListeners: (() => void)[]
) { ) {
makeObservable(this, { makeObservable(this, {
show: observable, show: observable,
@@ -40,15 +39,22 @@ export class AccountMenuState {
notesAndTagsCount: computed notesAndTagsCount: computed
}); });
appObservers.push( this.addAppEventObserver();
application.addEventObserver(async () => { this.streamNotesAndTags();
}
addAppEventObserver = (): void => {
this.appEventListeners.push(
this.application.addEventObserver(async () => {
runInAction(() => { runInAction(() => {
this.setServer(this.application.getHost()); this.setServer(this.application.getHost());
}); });
}, ApplicationEvent.Launched) }, ApplicationEvent.Launched)
); );
};
appEventListeners.push( streamNotesAndTags = (): void => {
this.appEventListeners.push(
this.application.streamItems( this.application.streamItems(
[ContentType.Note, ContentType.Tag], [ContentType.Note, ContentType.Tag],
() => { () => {
@@ -58,7 +64,7 @@ export class AccountMenuState {
} }
) )
); );
} };
setShow = (show: boolean): void => { setShow = (show: boolean): void => {
this.show = show; this.show = show;

View File

@@ -107,7 +107,6 @@ export class AppState {
this.accountMenu = new AccountMenuState( this.accountMenu = new AccountMenuState(
application, application,
this.appEventObserverRemovers, this.appEventObserverRemovers,
this.appEventObserverRemovers
); );
this.searchOptions = new SearchOptionsState( this.searchOptions = new SearchOptionsState(
application, application,