This repository has been archived on 2022-08-19. You can view files and clone it, but cannot push or open issues or pull requests.
hydrogen-web/src/domain/session/SessionViewModel.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

import EventEmitter from "../../EventEmitter.js";
2019-03-09 00:28:54 +05:30
import RoomTileViewModel from "./roomlist/RoomTileViewModel.js";
import RoomViewModel from "./room/RoomViewModel.js";
export default class SessionViewModel extends EventEmitter {
constructor(session) {
super();
this._session = session;
this._currentRoomViewModel = null;
const roomTileVMs = this._session.rooms.mapValues((room, emitUpdate) => {
return new RoomTileViewModel({
room,
emitUpdate,
emitOpen: room => this._openRoom(room)
});
});
this._roomList = roomTileVMs.sortValues((a, b) => a.compare(b));
}
get roomList() {
return this._roomList;
}
get currentRoom() {
return this._currentRoomViewModel;
}
_openRoom(room) {
if (this._currentRoomViewModel) {
this._currentRoomViewModel.disable();
}
this._currentRoomViewModel = new RoomViewModel(room);
this._currentRoomViewModel.enable();
this.emit("change", "currentRoom");
}
}