From 4c2beb5334773fcc3ec9dfb425e9f863462eae48 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Fri, 1 Oct 2021 03:14:36 +0200 Subject: [PATCH] Make question generation laze, huge performance boost --- UI/Base/Lazy.ts | 16 ++++++++++++++++ UI/Popup/EditableTagRendering.ts | 5 +++-- 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 UI/Base/Lazy.ts diff --git a/UI/Base/Lazy.ts b/UI/Base/Lazy.ts new file mode 100644 index 0000000000..e2b846cd8b --- /dev/null +++ b/UI/Base/Lazy.ts @@ -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(); + } + +} \ No newline at end of file diff --git a/UI/Popup/EditableTagRendering.ts b/UI/Popup/EditableTagRendering.ts index 4c5a13ea51..f40118a05e 100644 --- a/UI/Popup/EditableTagRendering.ts +++ b/UI/Popup/EditableTagRendering.ts @@ -9,6 +9,7 @@ import Toggle from "../Input/Toggle"; import BaseUIElement from "../BaseUIElement"; import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig"; import {Unit} from "../../Models/Unit"; +import Lazy from "../Base/Lazy"; export default class EditableTagRendering extends Toggle { @@ -44,14 +45,14 @@ export default class EditableTagRendering extends Toggle { editMode.setData(false) }); - const question = new TagRenderingQuestion(tags, configuration, + const question = new Lazy(() => new TagRenderingQuestion(tags, configuration, { units: units, cancelButton: cancelbutton, afterSave: () => { editMode.setData(false) } - }) + })) rendering = new Toggle(