cleanup SessionViewModel, use ViewModel dispose infrastructure

This commit is contained in:
Bruno Windels 2020-05-05 23:17:27 +02:00
parent 3adc609e07
commit c4b17e4be6

View File

@ -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");
}