1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-05 09:10:53 +01:00

state service

This commit is contained in:
Kyle Spearrin 2018-02-12 15:06:18 -05:00
parent 4960fa18c0
commit 56d941a754
4 changed files with 35 additions and 0 deletions

View File

@ -13,6 +13,7 @@ export { PasswordGenerationService } from './passwordGeneration.service';
export { PlatformUtilsService } from './platformUtils.service';
export { SettingsService } from './settings.service';
export { StorageService } from './storage.service';
export { StateService } from './state.service';
export { SyncService } from './sync.service';
export { TokenService } from './token.service';
export { TotpService } from './totp.service';

View File

@ -0,0 +1,6 @@
export abstract class StateService {
get: <T>(key: string) => Promise<T>;
save: (key: string, obj: any) => Promise<any>;
remove: (key: string) => Promise<any>;
purge: () => Promise<any>;
}

View File

@ -11,6 +11,7 @@ export { FolderService } from './folder.service';
export { LockService } from './lock.service';
export { PasswordGenerationService } from './passwordGeneration.service';
export { SettingsService } from './settings.service';
export { StateService } from './state.service';
export { SyncService } from './sync.service';
export { TokenService } from './token.service';
export { TotpService } from './totp.service';

View File

@ -0,0 +1,27 @@
import { StateService as StateServiceAbstraction } from '../abstractions/state.service';
export class StateService implements StateServiceAbstraction {
private state: any = {};
get<T>(key: string): Promise<T> {
if (this.state.hasOwnProperty(key)) {
return Promise.resolve(this.state[key]);
}
return Promise.resolve(null);
}
save(key: string, obj: any): Promise<any> {
this.state[key] = obj;
return Promise.resolve();
}
remove(key: string): Promise<any> {
delete this.state[key];
return Promise.resolve();
}
purge(): Promise<any> {
this.state = {};
return Promise.resolve();
}
}