mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-22 11:45:59 +01:00
feat: simplify lazy.ts (#10951)
This commit is contained in:
parent
023912c53d
commit
a1aa9adb48
@ -1,6 +1,7 @@
|
||||
const NoValue = Symbol("NoValue");
|
||||
|
||||
export class Lazy<T> {
|
||||
private _value: T | undefined = undefined;
|
||||
private _isCreated = false;
|
||||
private _value: T | typeof NoValue = NoValue;
|
||||
|
||||
constructor(private readonly factory: () => T) {}
|
||||
|
||||
@ -10,11 +11,10 @@ export class Lazy<T> {
|
||||
* @returns The value produced by your factory.
|
||||
*/
|
||||
get(): T {
|
||||
if (!this._isCreated) {
|
||||
this._value = this.factory();
|
||||
this._isCreated = true;
|
||||
if (this._value === NoValue) {
|
||||
return (this._value = this.factory());
|
||||
}
|
||||
|
||||
return this._value as T;
|
||||
return this._value;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user