1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 17:23:37 +00:00

null check optimizations

This commit is contained in:
Kyle Spearrin
2019-04-10 15:40:40 -04:00
parent 3ec0b7fb5d
commit 2fa1270f0b

View File

@@ -45,47 +45,37 @@ export class UserService implements UserServiceAbstraction {
} }
async getUserId(): Promise<string> { async getUserId(): Promise<string> {
if (this.userId != null) { if (this.userId == null) {
return this.userId;
}
this.userId = await this.storageService.get<string>(Keys.userId); this.userId = await this.storageService.get<string>(Keys.userId);
}
return this.userId; return this.userId;
} }
async getEmail(): Promise<string> { async getEmail(): Promise<string> {
if (this.email != null) { if (this.email == null) {
return this.email;
}
this.email = await this.storageService.get<string>(Keys.userEmail); this.email = await this.storageService.get<string>(Keys.userEmail);
}
return this.email; return this.email;
} }
async getSecurityStamp(): Promise<string> { async getSecurityStamp(): Promise<string> {
if (this.stamp != null) { if (this.stamp == null) {
return this.stamp;
}
this.stamp = await this.storageService.get<string>(Keys.stamp); this.stamp = await this.storageService.get<string>(Keys.stamp);
}
return this.stamp; return this.stamp;
} }
async getKdf(): Promise<KdfType> { async getKdf(): Promise<KdfType> {
if (this.kdf != null) { if (this.kdf == null) {
return this.kdf;
}
this.kdf = await this.storageService.get<KdfType>(Keys.kdf); this.kdf = await this.storageService.get<KdfType>(Keys.kdf);
}
return this.kdf; return this.kdf;
} }
async getKdfIterations(): Promise<number> { async getKdfIterations(): Promise<number> {
if (this.kdfIterations != null) { if (this.kdfIterations == null) {
return this.kdfIterations;
}
this.kdfIterations = await this.storageService.get<number>(Keys.kdfIterations); this.kdfIterations = await this.storageService.get<number>(Keys.kdfIterations);
}
return this.kdfIterations; return this.kdfIterations;
} }
@@ -117,7 +107,7 @@ export class UserService implements UserServiceAbstraction {
} }
async canAccessPremium(): Promise<boolean> { async canAccessPremium(): Promise<boolean> {
const tokenPremium = await this.tokenService.getPremium(); const tokenPremium = this.tokenService.getPremium();
if (tokenPremium) { if (tokenPremium) {
return true; return true;
} }