From d084f579c5c66108f637c97efa717207f5ebe847 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Thu, 27 Jun 2024 02:39:59 +0200 Subject: [PATCH] Refactor Popup with private and readonly modifiers --- public/scripts/popup.js | 49 ++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/public/scripts/popup.js b/public/scripts/popup.js index 83c4cc8b5..031d547b6 100644 --- a/public/scripts/popup.js +++ b/public/scripts/popup.js @@ -102,24 +102,24 @@ const showPopupHelper = { }; export class Popup { - /** @type {POPUP_TYPE} */ type; + /** @readonly @type {POPUP_TYPE} */ type; - /** @type {string} */ id; + /** @readonly @type {string} */ id; - /** @type {HTMLDialogElement} */ dlg; - /** @type {HTMLDivElement} */ body; - /** @type {HTMLDivElement} */ content; - /** @type {HTMLTextAreaElement} */ mainInput; - /** @type {HTMLDivElement} */ inputControls; - /** @type {HTMLDivElement} */ buttonControls; - /** @type {HTMLDivElement} */ okButton; - /** @type {HTMLDivElement} */ cancelButton; - /** @type {HTMLDivElement} */ closeButton; - /** @type {HTMLDivElement} */ cropWrap; - /** @type {HTMLImageElement} */ cropImage; - /** @type {POPUP_RESULT|number?} */ defaultResult; - /** @type {CustomPopupButton[]|string[]?} */ customButtons; - /** @type {CustomPopupInput[]} */ customInputs; + /** @readonly @type {HTMLDialogElement} */ dlg; + /** @readonly @type {HTMLDivElement} */ body; + /** @readonly @type {HTMLDivElement} */ content; + /** @readonly @type {HTMLTextAreaElement} */ mainInput; + /** @readonly @type {HTMLDivElement} */ inputControls; + /** @readonly @type {HTMLDivElement} */ buttonControls; + /** @readonly @type {HTMLDivElement} */ okButton; + /** @readonly @type {HTMLDivElement} */ cancelButton; + /** @readonly @type {HTMLDivElement} */ closeButton; + /** @readonly @type {HTMLDivElement} */ cropWrap; + /** @readonly @type {HTMLImageElement} */ cropImage; + /** @readonly @type {POPUP_RESULT|number?} */ defaultResult; + /** @readonly @type {CustomPopupButton[]|string[]?} */ customButtons; + /** @readonly @type {CustomPopupInput[]} */ customInputs; /** @type {(popup: Popup) => boolean?} */ onClosing; /** @type {(popup: Popup) => void?} */ onClose; @@ -131,8 +131,8 @@ export class Popup { /** @type {HTMLElement} */ lastFocus; - /** @type {Promise} */ promise; - /** @type {(result: any) => any} */ resolver; + /** @type {Promise} */ #promise; + /** @type {(result: any) => any} */ #resolver; /** * Constructs a new Popup object with the given text content, type, inputValue, and options @@ -378,10 +378,10 @@ export class Popup { this.dlg.removeAttribute('opening'); }); - this.promise = new Promise((resolve) => { - this.resolver = resolve; + this.#promise = new Promise((resolve) => { + this.#resolver = resolve; }); - return this.promise; + return this.#promise; } setAutoFocus({ applyAutoFocus = false } = {}) { @@ -462,14 +462,13 @@ export class Popup { } Popup.util.lastResult = { value, result }; - this.hide(); + this.#hide(); } /** * Hides the popup, using the internal resolver to return the value to the original show promise - * @private */ - hide() { + #hide() { // We close the dialog, first running the animation this.dlg.setAttribute('closing', ''); @@ -503,7 +502,7 @@ export class Popup { } } - this.resolver(this.value); + this.#resolver(this.value); }); }