mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-21 11:35:34 +01:00
Add UserKeyDefinition
to union (#8298)
This commit is contained in:
parent
31d37a817c
commit
3175b20ca5
@ -25,6 +25,7 @@ import {
|
||||
FakeGlobalState,
|
||||
FakeSingleUserState,
|
||||
} from "./fake-state";
|
||||
import { isUserKeyDefinition } from "../src/platform/state/user-key-definition";
|
||||
|
||||
export class FakeGlobalStateProvider implements GlobalStateProvider {
|
||||
mock = mock<GlobalStateProvider>();
|
||||
@ -95,7 +96,10 @@ export class FakeSingleUserStateProvider implements SingleUserStateProvider {
|
||||
return result as SingleUserState<T>;
|
||||
}
|
||||
|
||||
getFake<T>(userId: UserId, keyDefinition: KeyDefinition<T>): FakeSingleUserState<T> {
|
||||
getFake<T>(
|
||||
userId: UserId,
|
||||
keyDefinition: KeyDefinition<T> | UserKeyDefinition<T>,
|
||||
): FakeSingleUserState<T> {
|
||||
return this.get(userId, keyDefinition) as FakeSingleUserState<T>;
|
||||
}
|
||||
|
||||
@ -137,7 +141,7 @@ export class FakeActiveUserStateProvider implements ActiveUserStateProvider {
|
||||
return result as ActiveUserState<T>;
|
||||
}
|
||||
|
||||
getFake<T>(keyDefinition: KeyDefinition<T>): FakeActiveUserState<T> {
|
||||
getFake<T>(keyDefinition: KeyDefinition<T> | UserKeyDefinition<T>): FakeActiveUserState<T> {
|
||||
return this.get(keyDefinition) as FakeActiveUserState<T>;
|
||||
}
|
||||
|
||||
@ -154,8 +158,15 @@ export class FakeActiveUserStateProvider implements ActiveUserStateProvider {
|
||||
|
||||
export class FakeStateProvider implements StateProvider {
|
||||
mock = mock<StateProvider>();
|
||||
getUserState$<T>(keyDefinition: KeyDefinition<T>, userId?: UserId): Observable<T> {
|
||||
this.mock.getUserState$(keyDefinition, userId);
|
||||
getUserState$<T>(
|
||||
keyDefinition: KeyDefinition<T> | UserKeyDefinition<T>,
|
||||
userId?: UserId,
|
||||
): Observable<T> {
|
||||
if (isUserKeyDefinition(keyDefinition)) {
|
||||
this.mock.getUserState$(keyDefinition, userId);
|
||||
} else {
|
||||
this.mock.getUserState$(keyDefinition, userId);
|
||||
}
|
||||
if (userId) {
|
||||
return this.getUser<T>(userId, keyDefinition).state$;
|
||||
}
|
||||
|
@ -18,8 +18,22 @@ import { ActiveUserStateProvider, SingleUserStateProvider } from "./user-state.p
|
||||
* and {@link GlobalStateProvider}.
|
||||
*/
|
||||
export abstract class StateProvider {
|
||||
/** @see{@link ActiveUserState.activeUserId$} */
|
||||
/** @see{@link ActiveUserStateProvider.activeUserId$} */
|
||||
activeUserId$: Observable<UserId | undefined>;
|
||||
|
||||
/**
|
||||
* Gets a state observable for a given key and userId.
|
||||
*
|
||||
* @remarks If userId is falsy the observable returned will point to the currently active user _and not update if the active user changes_.
|
||||
* This is different to how `getActive` works and more similar to `getUser` for whatever user happens to be active at the time of the call.
|
||||
*
|
||||
* @note consider converting your {@link KeyDefinition} to a {@link UserKeyDefinition} for additional features.
|
||||
*
|
||||
* @param keyDefinition - The key definition for the state you want to get.
|
||||
* @param userId - The userId for which you want the state for. If not provided, the state for the currently active user will be returned.
|
||||
*/
|
||||
abstract getUserState$<T>(keyDefinition: KeyDefinition<T>, userId?: UserId): Observable<T>;
|
||||
|
||||
/**
|
||||
* Gets a state observable for a given key and userId.
|
||||
*
|
||||
@ -29,7 +43,7 @@ export abstract class StateProvider {
|
||||
* @param keyDefinition - The key definition for the state you want to get.
|
||||
* @param userId - The userId for which you want the state for. If not provided, the state for the currently active user will be returned.
|
||||
*/
|
||||
getUserState$: <T>(keyDefinition: KeyDefinition<T>, userId?: UserId) => Observable<T>;
|
||||
abstract getUserState$<T>(keyDefinition: UserKeyDefinition<T>, userId?: UserId): Observable<T>;
|
||||
|
||||
/**
|
||||
* Sets the state for a given key and userId.
|
||||
|
Loading…
Reference in New Issue
Block a user