Merge pull request #679 from vector-im/bwindels/fix-vm-ctor-default-options

always pass options to ViewModel constructor
This commit is contained in:
Bruno Windels 2022-02-17 10:10:19 +01:00 committed by GitHub
commit 49f6a2c2eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 7 deletions

View file

@ -19,9 +19,9 @@ import {KeyType} from "../matrix/ssss/index";
import {Status} from "./session/settings/KeyBackupViewModel.js";
export class AccountSetupViewModel extends ViewModel {
constructor(accountSetup) {
super();
this._accountSetup = accountSetup;
constructor(options) {
super(options);
this._accountSetup = options.accountSetup;
this._dehydratedDevice = undefined;
this._decryptDehydratedDeviceViewModel = undefined;
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.
class DecryptDehydratedDeviceViewModel extends ViewModel {
constructor(accountSetupViewModel, decryptedCallback) {
super();
super(accountSetupViewModel.options);
this._accountSetupViewModel = accountSetupViewModel;
this._isBusy = false;
this._status = Status.SetupKey;

View file

@ -43,7 +43,7 @@ export class SessionLoadViewModel extends ViewModel {
this.emitChange("loading");
this._waitHandle = this._client.loadStatus.waitFor(s => {
if (s === LoadStatus.AccountSetup) {
this._accountSetupViewModel = new AccountSetupViewModel(this._client.accountSetup);
this._accountSetupViewModel = new AccountSetupViewModel(this.childOptions({accountSetup: this._client.accountSetup}));
} else {
this._accountSetupViewModel = undefined;
}

View file

@ -51,6 +51,8 @@ export class ViewModel<O extends Options = Options> extends EventEmitter<{change
return Object.assign({}, this._options, explicitOptions);
}
get options(): O { return this._options; }
// makes it easier to pass through dependencies of a sub-view model
getOption<N extends keyof O>(name: N): O[N] {
return this._options[name];
@ -110,7 +112,7 @@ export class ViewModel<O extends Options = Options> extends EventEmitter<{change
}
emitChange(changedProps: any): void {
if (this._options?.emitChange) {
if (this._options.emitChange) {
this._options.emitChange(changedProps);
} else {
this.emit("change", changedProps);

View file

@ -18,7 +18,7 @@ import {ViewModel} from "../../ViewModel";
export class ComposerViewModel extends ViewModel {
constructor(roomVM) {
super();
super(roomVM.options);
this._roomVM = roomVM;
this._isEmpty = true;
this._replyVM = null;