From 7f1fed6f8cf3e9479380fdfc8bbc4d1fbb016ffb Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 17 Feb 2022 09:24:18 +0100 Subject: [PATCH] always pass options to ViewModel constructor --- src/domain/AccountSetupViewModel.js | 8 ++++---- src/domain/SessionLoadViewModel.js | 2 +- src/domain/ViewModel.ts | 4 +++- src/domain/session/room/ComposerViewModel.js | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/domain/AccountSetupViewModel.js b/src/domain/AccountSetupViewModel.js index 74d680d0..e7c1301f 100644 --- a/src/domain/AccountSetupViewModel.js +++ b/src/domain/AccountSetupViewModel.js @@ -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; diff --git a/src/domain/SessionLoadViewModel.js b/src/domain/SessionLoadViewModel.js index b23b54bc..abc16299 100644 --- a/src/domain/SessionLoadViewModel.js +++ b/src/domain/SessionLoadViewModel.js @@ -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; } diff --git a/src/domain/ViewModel.ts b/src/domain/ViewModel.ts index f3e141dc..458b2840 100644 --- a/src/domain/ViewModel.ts +++ b/src/domain/ViewModel.ts @@ -51,6 +51,8 @@ export class ViewModel 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(name: N): O[N] { return this._options[name]; @@ -110,7 +112,7 @@ export class ViewModel extends EventEmitter<{change } emitChange(changedProps: any): void { - if (this._options?.emitChange) { + if (this._options.emitChange) { this._options.emitChange(changedProps); } else { this.emit("change", changedProps); diff --git a/src/domain/session/room/ComposerViewModel.js b/src/domain/session/room/ComposerViewModel.js index 833b17f5..c20f6e86 100644 --- a/src/domain/session/room/ComposerViewModel.js +++ b/src/domain/session/room/ComposerViewModel.js @@ -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;