forked from MapComplete/MapComplete
Make question generation laze, huge performance boost
This commit is contained in:
parent
8b870474d7
commit
4c2beb5334
2 changed files with 19 additions and 2 deletions
16
UI/Base/Lazy.ts
Normal file
16
UI/Base/Lazy.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import BaseUIElement from "../BaseUIElement";
|
||||||
|
|
||||||
|
export default class Lazy extends BaseUIElement{
|
||||||
|
private readonly _f: () => BaseUIElement;
|
||||||
|
|
||||||
|
constructor(f: () => BaseUIElement) {
|
||||||
|
super();
|
||||||
|
this._f = f;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected InnerConstructElement(): HTMLElement {
|
||||||
|
// The caching of the BaseUIElement will guarantee that _f will only be called once
|
||||||
|
return this._f().ConstructElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import Toggle from "../Input/Toggle";
|
||||||
import BaseUIElement from "../BaseUIElement";
|
import BaseUIElement from "../BaseUIElement";
|
||||||
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig";
|
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig";
|
||||||
import {Unit} from "../../Models/Unit";
|
import {Unit} from "../../Models/Unit";
|
||||||
|
import Lazy from "../Base/Lazy";
|
||||||
|
|
||||||
export default class EditableTagRendering extends Toggle {
|
export default class EditableTagRendering extends Toggle {
|
||||||
|
|
||||||
|
@ -44,14 +45,14 @@ export default class EditableTagRendering extends Toggle {
|
||||||
editMode.setData(false)
|
editMode.setData(false)
|
||||||
});
|
});
|
||||||
|
|
||||||
const question = new TagRenderingQuestion(tags, configuration,
|
const question = new Lazy(() => new TagRenderingQuestion(tags, configuration,
|
||||||
{
|
{
|
||||||
units: units,
|
units: units,
|
||||||
cancelButton: cancelbutton,
|
cancelButton: cancelbutton,
|
||||||
afterSave: () => {
|
afterSave: () => {
|
||||||
editMode.setData(false)
|
editMode.setData(false)
|
||||||
}
|
}
|
||||||
})
|
}))
|
||||||
|
|
||||||
|
|
||||||
rendering = new Toggle(
|
rendering = new Toggle(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue