feat(lazy): created to handle lazy loading

This commit is contained in:
2025-09-19 10:36:14 +02:00
parent 6622442d95
commit 451e7e7daa
5 changed files with 31 additions and 1 deletions

View File

@@ -20,7 +20,7 @@ const url = {
get envKey() {
if (!this.__envKey) {
this.__envKey =
this.__envKey =
typeof envKey !== "undefined"
? envKey
: document.querySelector('meta[name="env-key"]').getAttribute('content');

View File

@@ -0,0 +1,22 @@
class Lazy {
#factory;
#initialized = false;
#value;
constructor(factory) {
this.#factory = factory;
}
get initialized() {
return this.#initialized;
}
get value() {
if (!this.#initialized) {
this.#initialized = true;
this.#value = this.#factory();
this.#factory = null;
}
return this.#value;
}
}

View File

@@ -0,0 +1 @@
class Lazy{#factory;#initialized=false;#value;constructor(n){this.#factory=n}get initialized(){return this.#initialized}get value(){return this.#initialized||(this.#initialized=!0,this.#value=this.#factory(),this.#factory=null),this.#value}}