mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 10:13:31 +00:00
[PM-6523] generator service tuning (#8155)
* rename policy$ to evaluator$ * replace `ActiveUserState` with `SingleUserState` * implement `SingleUserState<T>` on `SecretState`
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Observable, concatMap, of, zip } from "rxjs";
|
||||
import { Observable, concatMap, of, zip, map } from "rxjs";
|
||||
import { Jsonify } from "type-fest";
|
||||
|
||||
import { EncString } from "../../../platform/models/domain/enc-string";
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
SingleUserState,
|
||||
StateProvider,
|
||||
StateUpdateOptions,
|
||||
CombinedState,
|
||||
} from "../../../platform/state";
|
||||
import { UserId } from "../../../types/guid";
|
||||
|
||||
@@ -37,7 +38,9 @@ type ClassifiedFormat<Disclosed> = {
|
||||
*
|
||||
* DO NOT USE THIS for synchronized data.
|
||||
*/
|
||||
export class SecretState<Plaintext extends object, Disclosed> {
|
||||
export class SecretState<Plaintext extends object, Disclosed>
|
||||
implements SingleUserState<Plaintext>
|
||||
{
|
||||
// The constructor is private to avoid creating a circular dependency when
|
||||
// wiring the derived and secret states together.
|
||||
private constructor(
|
||||
@@ -46,8 +49,23 @@ export class SecretState<Plaintext extends object, Disclosed> {
|
||||
private readonly plaintext: DerivedState<Plaintext>,
|
||||
) {
|
||||
this.state$ = plaintext.state$;
|
||||
this.combinedState$ = plaintext.state$.pipe(map((state) => [this.encrypted.userId, state]));
|
||||
}
|
||||
|
||||
/** {@link SingleUserState.userId} */
|
||||
get userId() {
|
||||
return this.encrypted.userId;
|
||||
}
|
||||
|
||||
/** Observes changes to the decrypted secret state. The observer
|
||||
* updates after the secret has been recorded to state storage.
|
||||
* @returns `undefined` when the account is locked.
|
||||
*/
|
||||
readonly state$: Observable<Plaintext>;
|
||||
|
||||
/** {@link SingleUserState.combinedState$} */
|
||||
readonly combinedState$: Observable<CombinedState<Plaintext>>;
|
||||
|
||||
/** Creates a secret state bound to an account encryptor. The account must be unlocked
|
||||
* when this method is called.
|
||||
* @param userId: the user to which the secret state is bound.
|
||||
@@ -106,12 +124,6 @@ export class SecretState<Plaintext extends object, Disclosed> {
|
||||
return secretState;
|
||||
}
|
||||
|
||||
/** Observes changes to the decrypted secret state. The observer
|
||||
* updates after the secret has been recorded to state storage.
|
||||
* @returns `undefined` when the account is locked.
|
||||
*/
|
||||
readonly state$: Observable<Plaintext>;
|
||||
|
||||
/** Updates the secret stored by this state.
|
||||
* @param configureState a callback that returns an updated decrypted
|
||||
* secret state. The callback receives the state's present value as its
|
||||
|
||||
Reference in New Issue
Block a user