refactor: move observers and streamers to separate methods, code cleanup
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user