always pass options to ViewModel constructor
This commit is contained in:
parent
d971fd1a47
commit
7f1fed6f8c
4 changed files with 9 additions and 7 deletions
|
@ -19,9 +19,9 @@ import {KeyType} from "../matrix/ssss/index";
|
||||||
import {Status} from "./session/settings/KeyBackupViewModel.js";
|
import {Status} from "./session/settings/KeyBackupViewModel.js";
|
||||||
|
|
||||||
export class AccountSetupViewModel extends ViewModel {
|
export class AccountSetupViewModel extends ViewModel {
|
||||||
constructor(accountSetup) {
|
constructor(options) {
|
||||||
super();
|
super(options);
|
||||||
this._accountSetup = accountSetup;
|
this._accountSetup = options.accountSetup;
|
||||||
this._dehydratedDevice = undefined;
|
this._dehydratedDevice = undefined;
|
||||||
this._decryptDehydratedDeviceViewModel = undefined;
|
this._decryptDehydratedDeviceViewModel = undefined;
|
||||||
if (this._accountSetup.encryptedDehydratedDevice) {
|
if (this._accountSetup.encryptedDehydratedDevice) {
|
||||||
|
@ -53,7 +53,7 @@ export class AccountSetupViewModel extends ViewModel {
|
||||||
// this vm adopts the same shape as KeyBackupViewModel so the same view can be reused.
|
// this vm adopts the same shape as KeyBackupViewModel so the same view can be reused.
|
||||||
class DecryptDehydratedDeviceViewModel extends ViewModel {
|
class DecryptDehydratedDeviceViewModel extends ViewModel {
|
||||||
constructor(accountSetupViewModel, decryptedCallback) {
|
constructor(accountSetupViewModel, decryptedCallback) {
|
||||||
super();
|
super(accountSetupViewModel.options);
|
||||||
this._accountSetupViewModel = accountSetupViewModel;
|
this._accountSetupViewModel = accountSetupViewModel;
|
||||||
this._isBusy = false;
|
this._isBusy = false;
|
||||||
this._status = Status.SetupKey;
|
this._status = Status.SetupKey;
|
||||||
|
|
|
@ -43,7 +43,7 @@ export class SessionLoadViewModel extends ViewModel {
|
||||||
this.emitChange("loading");
|
this.emitChange("loading");
|
||||||
this._waitHandle = this._client.loadStatus.waitFor(s => {
|
this._waitHandle = this._client.loadStatus.waitFor(s => {
|
||||||
if (s === LoadStatus.AccountSetup) {
|
if (s === LoadStatus.AccountSetup) {
|
||||||
this._accountSetupViewModel = new AccountSetupViewModel(this._client.accountSetup);
|
this._accountSetupViewModel = new AccountSetupViewModel(this.childOptions({accountSetup: this._client.accountSetup}));
|
||||||
} else {
|
} else {
|
||||||
this._accountSetupViewModel = undefined;
|
this._accountSetupViewModel = undefined;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,8 @@ export class ViewModel<O extends Options = Options> extends EventEmitter<{change
|
||||||
return Object.assign({}, this._options, explicitOptions);
|
return Object.assign({}, this._options, explicitOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get options(): O { return this._options; }
|
||||||
|
|
||||||
// makes it easier to pass through dependencies of a sub-view model
|
// makes it easier to pass through dependencies of a sub-view model
|
||||||
getOption<N extends keyof O>(name: N): O[N] {
|
getOption<N extends keyof O>(name: N): O[N] {
|
||||||
return this._options[name];
|
return this._options[name];
|
||||||
|
@ -110,7 +112,7 @@ export class ViewModel<O extends Options = Options> extends EventEmitter<{change
|
||||||
}
|
}
|
||||||
|
|
||||||
emitChange(changedProps: any): void {
|
emitChange(changedProps: any): void {
|
||||||
if (this._options?.emitChange) {
|
if (this._options.emitChange) {
|
||||||
this._options.emitChange(changedProps);
|
this._options.emitChange(changedProps);
|
||||||
} else {
|
} else {
|
||||||
this.emit("change", changedProps);
|
this.emit("change", changedProps);
|
||||||
|
|
|
@ -18,7 +18,7 @@ import {ViewModel} from "../../ViewModel";
|
||||||
|
|
||||||
export class ComposerViewModel extends ViewModel {
|
export class ComposerViewModel extends ViewModel {
|
||||||
constructor(roomVM) {
|
constructor(roomVM) {
|
||||||
super();
|
super(roomVM.options);
|
||||||
this._roomVM = roomVM;
|
this._roomVM = roomVM;
|
||||||
this._isEmpty = true;
|
this._isEmpty = true;
|
||||||
this._replyVM = null;
|
this._replyVM = null;
|
||||||
|
|
Reference in a new issue