1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-12 06:13:38 +00:00

add clarification around null in state provider (#8567)

* add clarification around null in state provider

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

Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>

---------

Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>
This commit is contained in:
Jake Fink
2024-04-01 15:32:11 -04:00
committed by GitHub
parent 45f9f5695e
commit bd7c10705d

View File

@@ -6,24 +6,25 @@ import { StateUpdateOptions } from "./state-update-options";
export type CombinedState<T> = readonly [userId: UserId, state: T]; export type CombinedState<T> = readonly [userId: UserId, state: T];
/** /** A helper object for interacting with state that is scoped to a specific user. */
* A helper object for interacting with state that is scoped to a specific user.
*/
export interface UserState<T> { export interface UserState<T> {
/** /** Emits a stream of data. Emits null if the user does not have specified state. */
* Emits a stream of data. readonly state$: Observable<T | null>;
*/
readonly state$: Observable<T>;
/** /** Emits a stream of tuples, with the first element being a user id and the second element being the data for that user. */
* Emits a stream of data alongside the user id the data corresponds to.
*/
readonly combinedState$: Observable<CombinedState<T>>; readonly combinedState$: Observable<CombinedState<T>>;
} }
export const activeMarker: unique symbol = Symbol("active"); export const activeMarker: unique symbol = Symbol("active");
export interface ActiveUserState<T> extends UserState<T> { export interface ActiveUserState<T> extends UserState<T> {
readonly [activeMarker]: true; readonly [activeMarker]: true;
/**
* Emits a stream of data. Emits null if the user does not have specified state.
* Note: Will not emit if there is no active user.
*/
readonly state$: Observable<T | null>;
/** /**
* Updates backing stores for the active user. * Updates backing stores for the active user.
* @param configureState function that takes the current state and returns the new state * @param configureState function that takes the current state and returns the new state