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