@@ -13,19 +13,19 @@ import { ILogService } from 'vs/platform/log/common/log';
1313
1414export class FileStorage {
1515
16- private database : object | null = null ;
16+ private _lazyDatabase : object | null = null ;
1717
1818 constructor ( private dbPath : string , private onError : ( error ) => void ) { }
1919
20- private ensureLoaded ( ) : void {
21- if ( ! this . database ) {
22- this . database = this . loadSync ( ) ;
20+ private get database ( ) : object {
21+ if ( ! this . _lazyDatabase ) {
22+ this . _lazyDatabase = this . loadSync ( ) ;
2323 }
24+ return this . _lazyDatabase ;
2425 }
2526
26- getItem < T > ( key : string , defaultValue ?: T ) : T {
27- this . ensureLoaded ( ) ;
28-
27+ getItem < T > ( key : string , defaultValue : T ) : T ;
28+ getItem < T > ( key : string , defaultValue ?: T ) : T | undefined {
2929 const res = this . database [ key ] ;
3030 if ( isUndefinedOrNull ( res ) ) {
3131 return defaultValue ;
@@ -35,8 +35,6 @@ export class FileStorage {
3535 }
3636
3737 setItem ( key : string , data : any ) : void {
38- this . ensureLoaded ( ) ;
39-
4038 // Remove an item when it is undefined or null
4139 if ( isUndefinedOrNull ( data ) ) {
4240 return this . removeItem ( key ) ;
@@ -54,8 +52,6 @@ export class FileStorage {
5452 }
5553
5654 removeItem ( key : string ) : void {
57- this . ensureLoaded ( ) ;
58-
5955 // Only update if the key is actually present (not undefined)
6056 if ( ! isUndefined ( this . database [ key ] ) ) {
6157 this . database [ key ] = void 0 ;
@@ -94,7 +90,8 @@ export class StateService implements IStateService {
9490 this . fileStorage = new FileStorage ( path . join ( environmentService . userDataPath , 'storage.json' ) , error => logService . error ( error ) ) ;
9591 }
9692
97- getItem < T > ( key : string , defaultValue ?: T ) : T {
93+ getItem < T > ( key : string , defaultValue : T ) : T ;
94+ getItem < T > ( key : string , defaultValue ?: T ) : T | undefined {
9895 return this . fileStorage . getItem ( key , defaultValue ) ;
9996 }
10097
0 commit comments