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

@@ -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;
}
}