mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 07: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:
26
libs/common/src/platform/state/state-update-options.ts
Normal file
26
libs/common/src/platform/state/state-update-options.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Observable } from "rxjs";
|
||||
|
||||
export const DEFAULT_OPTIONS = {
|
||||
shouldUpdate: () => true,
|
||||
combineLatestWith: null as Observable<unknown>,
|
||||
msTimeout: 1000,
|
||||
};
|
||||
|
||||
type DefinitelyTypedDefault<T, TCombine> = Omit<
|
||||
typeof DEFAULT_OPTIONS,
|
||||
"shouldUpdate" | "combineLatestWith"
|
||||
> & {
|
||||
shouldUpdate: (state: T, dependency: TCombine) => boolean;
|
||||
combineLatestWith?: Observable<TCombine>;
|
||||
};
|
||||
|
||||
export type StateUpdateOptions<T, TCombine> = Partial<DefinitelyTypedDefault<T, TCombine>>;
|
||||
|
||||
export function populateOptionsWithDefault<T, TCombine>(
|
||||
options: StateUpdateOptions<T, TCombine>
|
||||
): StateUpdateOptions<T, TCombine> {
|
||||
return {
|
||||
...(DEFAULT_OPTIONS as StateUpdateOptions<T, TCombine>),
|
||||
...options,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user