From 7e8d76a95ee17623a08034b06c50733b609c0284 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Fri, 6 Aug 2021 16:21:31 +0530 Subject: [PATCH] Refactor map into switch-case Signed-off-by: RMidhunSuresh --- .../ui/session/rightpanel/RightPanelView.js | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/platform/web/ui/session/rightpanel/RightPanelView.js b/src/platform/web/ui/session/rightpanel/RightPanelView.js index 69b81f49..645cc22f 100644 --- a/src/platform/web/ui/session/rightpanel/RightPanelView.js +++ b/src/platform/web/ui/session/rightpanel/RightPanelView.js @@ -6,18 +6,27 @@ import {MemberDetailsView} from "./MemberDetailsView.js"; export class RightPanelView extends TemplateView { render(t) { - const viewFromType = { - "room-details": RoomDetailsView, - "member-list": MemberListView, - "member-details": MemberDetailsView - }; return t.div({ className: "RightPanelView" }, [ 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 {