mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 00:33:44 +00:00
* Specify state provider for currently active user * Split active and single user States UserStateProvider is still the mechanism to build each State object. The SingleUserState is basically a repeat of GlobalState, but with additional scoping. * Fixup global state cache * fix fakers to new interface * Make userId available in single user state * Split providers by dependency requirements This allows usage of the single state provider in contexts that would otherwise form circular dependencies. * Offer convenience wrapper classes for common use * Import for docs * Bind wrapped methods
29 lines
1.2 KiB
TypeScript
29 lines
1.2 KiB
TypeScript
import { UserId } from "../../types/guid";
|
|
|
|
import { KeyDefinition } from "./key-definition";
|
|
import { ActiveUserState, SingleUserState } from "./user-state";
|
|
|
|
/** A provider for getting an implementation of state scoped to a given key and userId */
|
|
export abstract class SingleUserStateProvider {
|
|
/**
|
|
* Gets a {@link SingleUserState} scoped to the given {@link KeyDefinition} and {@link UserId}
|
|
*
|
|
* @param userId - The {@link UserId} for which you want the user state for.
|
|
* @param keyDefinition - The {@link KeyDefinition} for which you want the user state for.
|
|
*/
|
|
get: <T>(userId: UserId, keyDefinition: KeyDefinition<T>) => SingleUserState<T>;
|
|
}
|
|
|
|
/** A provider for getting an implementation of state scoped to a given key, but always pointing
|
|
* to the currently active user
|
|
*/
|
|
export abstract class ActiveUserStateProvider {
|
|
/**
|
|
* Gets a {@link ActiveUserState} scoped to the given {@link KeyDefinition}, but updates when active user changes such
|
|
* that the emitted values always represents the state for the currently active user.
|
|
*
|
|
* @param keyDefinition - The {@link KeyDefinition} for which you want the user state for.
|
|
*/
|
|
get: <T>(keyDefinition: KeyDefinition<T>) => ActiveUserState<T>;
|
|
}
|