forked from mystiq/hydrogen-web
implement root view as template view
This commit is contained in:
parent
0f8f558889
commit
1289f065d6
1 changed files with 20 additions and 50 deletions
|
@ -20,58 +20,28 @@ import {SessionLoadView} from "./login/SessionLoadView.js";
|
||||||
import {SessionPickerView} from "./login/SessionPickerView.js";
|
import {SessionPickerView} from "./login/SessionPickerView.js";
|
||||||
import {TemplateView} from "./general/TemplateView.js";
|
import {TemplateView} from "./general/TemplateView.js";
|
||||||
import {StaticView} from "./general/StaticView.js";
|
import {StaticView} from "./general/StaticView.js";
|
||||||
import {SwitchView} from "./general/SwitchView.js";
|
|
||||||
|
|
||||||
export class RootView {
|
export class RootView extends TemplateView {
|
||||||
constructor(vm) {
|
render(t, vm) {
|
||||||
this._vm = vm;
|
return t.mapView(vm => vm.activeSection, activeSection => {
|
||||||
this._switcher = null;
|
switch (activeSection) {
|
||||||
this._root = null;
|
|
||||||
this._onViewModelChange = this._onViewModelChange.bind(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
_getView() {
|
|
||||||
switch (this._vm.activeSection) {
|
|
||||||
case "error":
|
case "error":
|
||||||
return new StatusView({header: "Something went wrong", message: this._vm.errorText});
|
return new StatusView({header: "Something went wrong", message: vm.errorText});
|
||||||
case "session":
|
case "session":
|
||||||
return new SessionView(this._vm.sessionViewModel);
|
return new SessionView(vm.sessionViewModel);
|
||||||
case "login":
|
case "login":
|
||||||
return new LoginView(this._vm.loginViewModel);
|
return new LoginView(vm.loginViewModel);
|
||||||
case "picker":
|
case "picker":
|
||||||
return new SessionPickerView(this._vm.sessionPickerViewModel);
|
return new SessionPickerView(vm.sessionPickerViewModel);
|
||||||
case "redirecting":
|
case "redirecting":
|
||||||
return new StaticView(t => t.p("Redirecting..."));
|
return new StaticView(t => t.p("Redirecting..."));
|
||||||
case "loading":
|
case "loading":
|
||||||
return new SessionLoadView(this._vm.sessionLoadViewModel);
|
return new SessionLoadView(vm.sessionLoadViewModel);
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unknown section: ${this._vm.activeSection}`);
|
throw new Error(`Unknown section: ${vm.activeSection}`);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_onViewModelChange(prop) {
|
|
||||||
if (prop === "activeSection") {
|
|
||||||
this._switcher.switch(this._getView());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mount() {
|
|
||||||
this._switcher = new SwitchView(this._getView());
|
|
||||||
this._root = this._switcher.mount();
|
|
||||||
this._vm.on("change", this._onViewModelChange);
|
|
||||||
return this._root;
|
|
||||||
}
|
|
||||||
|
|
||||||
unmount() {
|
|
||||||
this._vm.off("change", this._onViewModelChange);
|
|
||||||
this._switcher.unmount();
|
|
||||||
}
|
|
||||||
|
|
||||||
root() {
|
|
||||||
return this._root;
|
|
||||||
}
|
|
||||||
|
|
||||||
update() {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class StatusView extends TemplateView {
|
class StatusView extends TemplateView {
|
||||||
|
|
Loading…
Reference in a new issue