mirror of
https://github.com/bitwarden/jslib
synced 2025-12-23 11:43:51 +00:00
StateService InjectionTokens
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Injector, LOCALE_ID, NgModule } from "@angular/core";
|
||||
import { InjectionToken, Injector, LOCALE_ID, NgModule } from "@angular/core";
|
||||
|
||||
import { ApiService as ApiServiceAbstraction } from "jslib-common/abstractions/api.service";
|
||||
import { AppIdService as AppIdServiceAbstraction } from "jslib-common/abstractions/appId.service";
|
||||
@@ -15,6 +15,7 @@ import { ExportService as ExportServiceAbstraction } from "jslib-common/abstract
|
||||
import { FileUploadService as FileUploadServiceAbstraction } from "jslib-common/abstractions/fileUpload.service";
|
||||
import { FolderService as FolderServiceAbstraction } from "jslib-common/abstractions/folder.service";
|
||||
import { I18nService as I18nServiceAbstraction } from "jslib-common/abstractions/i18n.service";
|
||||
import { STATE_FACTORY, STATE_SERVICE_USE_CACHE } from 'jslib-common/abstractions/injectionTokens';
|
||||
import { KeyConnectorService as KeyConnectorServiceAbstraction } from "jslib-common/abstractions/keyConnector.service";
|
||||
import { LogService } from "jslib-common/abstractions/log.service";
|
||||
import { MessagingService as MessagingServiceAbstraction } from "jslib-common/abstractions/messaging.service";
|
||||
@@ -293,27 +294,17 @@ import { ValidationService } from "./validation.service";
|
||||
StateServiceAbstraction,
|
||||
],
|
||||
},
|
||||
{
|
||||
provide: STATE_SERVICE_USE_CACHE,
|
||||
useValue: true,
|
||||
},
|
||||
{
|
||||
provide: STATE_FACTORY,
|
||||
useFactory: () => new StateFactory(GlobalState, Account)
|
||||
},
|
||||
{
|
||||
provide: StateServiceAbstraction,
|
||||
useFactory: (
|
||||
storageService: StorageServiceAbstraction,
|
||||
secureStorageService: StorageServiceAbstraction,
|
||||
logService: LogService,
|
||||
stateMigrationService: StateMigrationServiceAbstraction
|
||||
) =>
|
||||
new StateService(
|
||||
storageService,
|
||||
secureStorageService,
|
||||
logService,
|
||||
stateMigrationService,
|
||||
new StateFactory(GlobalState, Account)
|
||||
),
|
||||
deps: [
|
||||
StorageServiceAbstraction,
|
||||
"SECURE_STORAGE",
|
||||
LogService,
|
||||
StateMigrationServiceAbstraction,
|
||||
],
|
||||
useClass: StateService
|
||||
},
|
||||
{
|
||||
provide: StateMigrationServiceAbstraction,
|
||||
|
||||
5
common/src/abstractions/injectionTokens.ts
Normal file
5
common/src/abstractions/injectionTokens.ts
Normal 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');
|
||||
@@ -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>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user