mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2025-01-25 19:51:39 +01:00
37 lines
735 B
JavaScript
37 lines
735 B
JavaScript
|
export default class SwitchView {
|
||
|
constructor(defaultView) {
|
||
|
this._childView = defaultView;
|
||
|
}
|
||
|
|
||
|
mount() {
|
||
|
return this._childView.mount();
|
||
|
}
|
||
|
|
||
|
unmount() {
|
||
|
return this._childView.unmount();
|
||
|
}
|
||
|
|
||
|
root() {
|
||
|
return this._childView.root();
|
||
|
}
|
||
|
|
||
|
update() {
|
||
|
return this._childView.update();
|
||
|
}
|
||
|
|
||
|
switch(newView) {
|
||
|
const oldRoot = this.root();
|
||
|
this._childView.unmount();
|
||
|
this._childView = newView;
|
||
|
const newRoot = this._childView.mount();
|
||
|
const parent = oldRoot.parentElement;
|
||
|
if (parent) {
|
||
|
parent.replaceChild(newRoot, oldRoot);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
get childView() {
|
||
|
return this._childView;
|
||
|
}
|
||
|
}
|