2020-12-05 03:22:17 +01:00
|
|
|
import {UIElement} from "../UIElement";
|
|
|
|
|
2021-02-05 18:58:06 +01:00
|
|
|
export default class LazyElement extends UIElement {
|
2020-12-05 03:22:17 +01:00
|
|
|
|
|
|
|
|
2021-02-05 18:58:06 +01:00
|
|
|
public Activate: () => void;
|
|
|
|
private _content: UIElement = undefined;
|
2021-01-25 03:12:09 +01:00
|
|
|
private readonly _loadingContent: string;
|
2020-12-05 03:22:17 +01:00
|
|
|
|
2021-02-05 18:58:06 +01:00
|
|
|
constructor(content: (() => UIElement), loadingContent = "Rendering...") {
|
2020-12-05 03:22:17 +01:00
|
|
|
super();
|
2021-01-07 20:11:07 +01:00
|
|
|
this._loadingContent = loadingContent;
|
2020-12-05 03:22:17 +01:00
|
|
|
this.dumbMode = false;
|
|
|
|
const self = this;
|
2021-02-05 18:58:06 +01:00
|
|
|
this.Activate = () => {
|
2020-12-05 03:22:17 +01:00
|
|
|
if (this._content === undefined) {
|
|
|
|
self._content = content();
|
|
|
|
}
|
|
|
|
self.Update();
|
2021-02-25 02:23:26 +01:00
|
|
|
// @ts-ignore
|
|
|
|
if(this._content.Activate){
|
|
|
|
// THis is ugly - I know
|
|
|
|
// @ts-ignore
|
|
|
|
this._content.Activate();
|
|
|
|
}
|
2020-12-05 03:22:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InnerRender(): string {
|
|
|
|
if (this._content === undefined) {
|
2021-01-07 20:11:07 +01:00
|
|
|
return this._loadingContent;
|
2020-12-05 03:22:17 +01:00
|
|
|
}
|
2021-01-25 04:21:22 +01:00
|
|
|
return this._content.Render();
|
2020-12-05 03:22:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|