feat(lazy): created to handle lazy loading
This commit is contained in:
22
EnvelopeGenerator.Web/wwwroot/js/lazy.js
Normal file
22
EnvelopeGenerator.Web/wwwroot/js/lazy.js
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user