mirror of
https://github.com/bitwarden/browser
synced 2025-12-21 10:43:35 +00:00
Ps/pm 2910/state framework improvements (#6860)
* Allow for update logic in state update callbacks * Prefer reading updates to sending in stream * Inform state providers when they must deserialize * Update DefaultGlobalState to act more like DefaultUserState * Fully Implement AbstractStorageService * Add KeyDefinitionOptions * Address PR feedback * More Descriptive Error --------- Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>
This commit is contained in:
@@ -4,6 +4,8 @@ import { UserId } from "../../types/guid";
|
||||
import { EncryptService } from "../abstractions/encrypt.service";
|
||||
import { UserKey } from "../models/domain/symmetric-crypto-key";
|
||||
|
||||
import { StateUpdateOptions } from "./state-update-options";
|
||||
|
||||
import { DerivedUserState } from ".";
|
||||
|
||||
export class DeriveContext {
|
||||
@@ -21,16 +23,33 @@ export interface UserState<T> {
|
||||
/**
|
||||
* Updates backing stores for the active user.
|
||||
* @param configureState function that takes the current state and returns the new state
|
||||
* @param options Defaults to @see {module:state-update-options#DEFAULT_OPTIONS}
|
||||
* @param options.shouldUpdate A callback for determining if you want to update state. Defaults to () => true
|
||||
* @param options.combineLatestWith An observable that you want to combine with the current state for callbacks. Defaults to null
|
||||
* @param options.msTimeout A timeout for how long you are willing to wait for a `combineLatestWith` option to complete. Defaults to 1000ms. Only applies if `combineLatestWith` is set.
|
||||
|
||||
* @returns The new state
|
||||
*/
|
||||
readonly update: (configureState: (state: T) => T) => Promise<T>;
|
||||
readonly update: <TCombine>(
|
||||
configureState: (state: T, dependencies: TCombine) => T,
|
||||
options?: StateUpdateOptions<T, TCombine>
|
||||
) => Promise<T>;
|
||||
/**
|
||||
* Updates backing stores for the given userId, which may or may not be active.
|
||||
* @param userId the UserId to target the update for
|
||||
* @param configureState function that takes the current state for the targeted user and returns the new state
|
||||
* @param options Defaults given by @see {module:state-update-options#DEFAULT_OPTIONS}
|
||||
* @param options.shouldUpdate A callback for determining if you want to update state. Defaults to () => true
|
||||
* @param options.combineLatestWith An observable that you want to combine with the current state for callbacks. Defaults to null
|
||||
* @param options.msTimeout A timeout for how long you are willing to wait for a `combineLatestWith` option to complete. Defaults to 1000ms. Only applies if `combineLatestWith` is set.
|
||||
|
||||
* @returns The new state
|
||||
*/
|
||||
readonly updateFor: (userId: UserId, configureState: (state: T) => T) => Promise<T>;
|
||||
readonly updateFor: <TCombine>(
|
||||
userId: UserId,
|
||||
configureState: (state: T, dependencies: TCombine) => T,
|
||||
options?: StateUpdateOptions<T, TCombine>
|
||||
) => Promise<T>;
|
||||
|
||||
/**
|
||||
* Creates a derives state from the current state. Derived states are always tied to the active user.
|
||||
|
||||
Reference in New Issue
Block a user