mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
SwitchView, to alternate between different views
This commit is contained in:
parent
c8910b55e0
commit
16fed27a8a
36
src/ui/web/SwitchView.js
Normal file
36
src/ui/web/SwitchView.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user