mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 10:13:31 +00:00
* refactor: introduce @bitwarden/serialization * refactor: introduce @bitwarden/guid * refactor: introduce @bitwaren/client-type * refactor: introduce @bitwarden/core-test-utils * refactor: introduce @bitwarden/state and @bitwarden/state-test-utils Creates initial project structure for centralized application state management. Part of modularization effort to extract state code from common. * Added state provider documentation to README. * Changed callouts to Github format. * Fixed linting on file name. * Forced git to accept rename --------- Co-authored-by: Todd Martin <tmartin@bitwarden.com>
24 lines
804 B
TypeScript
24 lines
804 B
TypeScript
import { Observable } from "rxjs";
|
|
|
|
export type StateConverter<TFrom extends Array<unknown>, TTo> = (...args: TFrom) => TTo;
|
|
|
|
/**
|
|
* State derived from an observable and a converter function
|
|
*
|
|
* Derived state is cached and persisted to memory for sychronization across execution contexts.
|
|
* For clients with multiple execution contexts, the derived state will be executed only once in the background process.
|
|
*/
|
|
export interface DerivedState<T> {
|
|
/**
|
|
* The derived state observable
|
|
*/
|
|
state$: Observable<T>;
|
|
/**
|
|
* Forces the derived state to a given value.
|
|
*
|
|
* Useful for setting an in-memory value as a side effect of some event, such as emptying state as a result of a lock.
|
|
* @param value The value to force the derived state to
|
|
*/
|
|
forceValue(value: T): Promise<T>;
|
|
}
|