Refactor map into switch-case

Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
RMidhunSuresh 2021-08-06 16:21:31 +05:30
parent bc8e6237d6
commit 7e8d76a95e

View file

@ -6,18 +6,27 @@ import {MemberDetailsView} from "./MemberDetailsView.js";
export class RightPanelView extends TemplateView { export class RightPanelView extends TemplateView {
render(t) { render(t) {
const viewFromType = {
"room-details": RoomDetailsView,
"member-list": MemberListView,
"member-details": MemberDetailsView
};
return t.div({ className: "RightPanelView" }, return t.div({ className: "RightPanelView" },
[ [
t.ifView(vm => vm.activeViewModel, vm => new ButtonsView(vm)), t.ifView(vm => vm.activeViewModel, vm => new ButtonsView(vm)),
t.mapView(vm => vm.activeViewModel, vm => vm ? new viewFromType[vm.type](vm) : new LoadingView()) t.mapView(vm => vm.activeViewModel, vm => this._viewFromType(vm))
] ]
); );
} }
_viewFromType(vm) {
const type = vm?.type;
switch (type) {
case "room-details":
return new RoomDetailsView(vm);
case "member-list":
return new MemberListView(vm);
case "member-details":
return new MemberDetailsView(vm);
default:
return new LoadingView();
}
}
} }
class ButtonsView extends TemplateView { class ButtonsView extends TemplateView {