mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
Ps/introduce single user state (#7053)
* 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
This commit is contained in:
@@ -129,8 +129,13 @@ export class KeyDefinition<T> {
|
||||
* Create a string that should be unique across the entire application.
|
||||
* @returns A string that can be used to cache instances created via this key.
|
||||
*/
|
||||
buildCacheKey(): string {
|
||||
return `${this.stateDefinition.storageLocation}_${this.stateDefinition.name}_${this.key}`;
|
||||
buildCacheKey(scope: "user" | "global", userId?: "active" | UserId): string {
|
||||
if (scope === "user" && userId == null) {
|
||||
throw new Error("You must provide a userId when building a user scoped cache key.");
|
||||
}
|
||||
return userId === null
|
||||
? `${scope}_${userId}_${this.stateDefinition.name}_${this.key}`
|
||||
: `${scope}_${this.stateDefinition.name}_${this.key}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user