forked from mystiq/hydrogen-web
Refactor map into switch-case
Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
parent
bc8e6237d6
commit
7e8d76a95e
1 changed files with 15 additions and 6 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue