From c4b17e4be63105cdaad207cf8f448910eed3abbe Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 5 May 2020 23:17:27 +0200 Subject: [PATCH] cleanup SessionViewModel, use ViewModel dispose infrastructure --- src/domain/session/SessionViewModel.js | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/domain/session/SessionViewModel.js b/src/domain/session/SessionViewModel.js index 900e2965..fb80edb8 100644 --- a/src/domain/session/SessionViewModel.js +++ b/src/domain/session/SessionViewModel.js @@ -1,12 +1,12 @@ import {RoomTileViewModel} from "./roomlist/RoomTileViewModel.js"; import {RoomViewModel} from "./room/RoomViewModel.js"; -import {SyncStatusViewModel} from "./SyncStatusViewModel.js"; +import {SessionStatusViewModel} from "./SessionStatusViewModel.js"; import {ViewModel} from "../ViewModel.js"; export class SessionViewModel extends ViewModel { constructor(options) { super(options); - const sessionContainer = options.sessionContainer; + const {sessionContainer} = options; this._session = sessionContainer.session; this._sessionStatusViewModel = this.track(new SessionStatusViewModel(this.childOptions({ syncStatus: sessionContainer.sync.status, @@ -39,30 +39,22 @@ export class SessionViewModel extends ViewModel { return this._currentRoomViewModel; } - dispose() { - if (this._currentRoomViewModel) { - this._currentRoomViewModel.dispose(); - this._currentRoomViewModel = null; - } - } - _closeCurrentRoom() { if (this._currentRoomViewModel) { - this._currentRoomViewModel.dispose(); - this._currentRoomViewModel = null; + this._currentRoomViewModel = this.disposeTracked(this._currentRoomViewModel); this.emitChange("currentRoom"); } } _openRoom(room) { if (this._currentRoomViewModel) { - this._currentRoomViewModel.dispose(); + this._currentRoomViewModel = this.disposeTracked(this._currentRoomViewModel); } - this._currentRoomViewModel = new RoomViewModel(this.childOptions({ + this._currentRoomViewModel = this.track(new RoomViewModel(this.childOptions({ room, ownUserId: this._session.user.id, closeCallback: () => this._closeCurrentRoom(), - })); + }))); this._currentRoomViewModel.load(); this.emitChange("currentRoom"); }