1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-21 02:33:46 +00:00

Combined State (#7383)

* Introduce Combined State

* Cleanup Test

* Update Fakes

* Address PR Feedback

* Update libs/common/src/platform/state/implementations/default-active-user-state.ts

Co-authored-by: Matt Gibson <mgibson@bitwarden.com>

* Prettier

* Get rid of ReplaySubject reference

---------

Co-authored-by: Matt Gibson <mgibson@bitwarden.com>
This commit is contained in:
Justin Baur
2024-01-04 16:30:20 -05:00
committed by GitHub
parent 312197b8c7
commit 5e11cb212d
13 changed files with 280 additions and 339 deletions

View File

@@ -4,12 +4,22 @@ import { UserId } from "../../types/guid";
import { StateUpdateOptions } from "./state-update-options";
export type CombinedState<T> = readonly [userId: UserId, state: T];
/**
* A helper object for interacting with state that is scoped to a specific user.
*/
export interface UserState<T> {
/**
* Emits a stream of data.
*/
readonly state$: Observable<T>;
readonly getFromState: () => Promise<T>;
/**
* Emits a stream of data alongside the user id the data corresponds to.
*/
readonly combinedState$: Observable<CombinedState<T>>;
/**
* Updates backing stores for the active user.
* @param configureState function that takes the current state and returns the new state