mapcomplete/UI/Base/LazyElement.ts

32 lines
769 B
TypeScript
Raw Normal View History

2020-12-05 02:22:17 +00:00
import {UIElement} from "../UIElement";
export default class LazyElement extends UIElement {
private _content: UIElement = undefined;
public Activate: () => void;
private _loadingContent: string;
2020-12-05 02:22:17 +00:00
constructor(content: (() => UIElement), loadingContent = "Rendering...") {
2020-12-05 02:22:17 +00:00
super();
this._loadingContent = loadingContent;
2020-12-05 02:22:17 +00:00
this.dumbMode = false;
const self = this;
this.Activate = () => {
if (this._content === undefined) {
self._content = content();
}
self.Update();
}
}
InnerRender(): string {
if (this._content === undefined) {
return this._loadingContent;
2020-12-05 02:22:17 +00:00
}
return this._content.InnerRender();
}
}