refactor: set initial value of server on Application.Launched event

This commit is contained in:
VardanHakobyan
2021-06-17 17:51:45 +04:00
parent 72eb2c1e42
commit bba1d089bf
2 changed files with 12 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
import { action, computed, makeObservable, observable, runInAction } from 'mobx';
import { ContentType } from '@standardnotes/snjs';
import { ApplicationEvent, ContentType } from '@standardnotes/snjs';
import { WebApplication } from '@/ui_models/application';
import { SNItem } from '@standardnotes/snjs/dist/@types/models/core/item';
@@ -16,6 +16,7 @@ export class AccountMenuState {
constructor(
private application: WebApplication,
appObservers: (() => void)[],
appEventListeners: (() => void)[]
) {
makeObservable(this, {
@@ -39,16 +40,20 @@ export class AccountMenuState {
notesAndTagsCount: computed
});
appObservers.push(
application.addEventObserver(async () => {
runInAction(() => {
this.setServer(this.application.getHost());
});
}, ApplicationEvent.Launched)
);
appEventListeners.push(
this.application.streamItems(
[
ContentType.Note, ContentType.Tag,
ContentType.Component // TODO: is this correct for streaming `server`?
],
[ContentType.Note, ContentType.Tag],
() => {
runInAction(() => {
this.notesAndTags = this.application.getItems([ContentType.Note, ContentType.Tag]);
this.setServer(this.application.getHost());
});
}
)

View File

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