state service
This commit is contained in:
parent
4960fa18c0
commit
56d941a754
|
@ -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';
|
||||
|
|
|
@ -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>;
|
||||
}
|
|
@ -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';
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue