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(
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;

View File

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