1
0
mirror of https://github.com/bitwarden/jslib synced 2026-01-05 18:13:14 +00:00

StateService InjectionTokens

This commit is contained in:
Thomas Rittson
2022-03-25 13:05:30 +10:00
parent eefcd5d22b
commit e8f2ae0a7b
3 changed files with 23 additions and 23 deletions

View File

@@ -0,0 +1,5 @@
import { InjectionToken } from '@angular/core';
import { StateFactory } from '../factories/stateFactory';
export const STATE_SERVICE_USE_CACHE = new InjectionToken<boolean>('STATE_SERVICE_USE_CACHE');
export const STATE_FACTORY = new InjectionToken<StateFactory>('STATE_FACTORY');

View File

@@ -1,3 +1,4 @@
import { Inject, Injectable } from '@angular/core';
import { BehaviorSubject } from "rxjs";
import { LogService } from "../abstractions/log.service";
@@ -33,6 +34,8 @@ import { CollectionView } from "../models/view/collectionView";
import { FolderView } from "../models/view/folderView";
import { SendView } from "../models/view/sendView";
import { STATE_FACTORY, STATE_SERVICE_USE_CACHE } from "../abstractions/injectionTokens";
const keys = {
global: "global",
authenticatedAccounts: "authenticatedAccounts",
@@ -47,6 +50,7 @@ const partialKeys = {
masterKey: "_masterkey",
};
@Injectable()
export class StateService<
TGlobalState extends GlobalState = GlobalState,
TAccount extends Account = Account
@@ -65,11 +69,11 @@ export class StateService<
constructor(
protected storageService: StorageService,
protected secureStorageService: StorageService,
@Inject("SECURE_STORAGE") protected secureStorageService: StorageService,
protected logService: LogService,
protected stateMigrationService: StateMigrationService,
protected stateFactory: StateFactory<TGlobalState, TAccount>,
protected useAccountCache: boolean = true
@Inject(STATE_FACTORY) protected stateFactory: StateFactory<TGlobalState, TAccount>,
@Inject(STATE_SERVICE_USE_CACHE) protected useAccountCache: boolean
) {
this.accountDiskCache = new Map<string, TAccount>();
}