refactor: share search history

This commit is contained in:
starknt
2024-01-08 10:41:18 +08:00
parent e99e9fa95b
commit 08146c4497
3 changed files with 106 additions and 26 deletions

View File

@@ -74,3 +74,21 @@ declare function cancelIdleCallback(handle: number): void;
}
}
})()
// TODO: handle error
export class LazyValue<T> {
private _value: T | undefined
private _didRun = false
constructor(
private executor: () => T,
) {}
get value(): T {
if (!this._didRun) {
this._value = this.executor()
this._didRun = true
}
return this._value!
}
}