mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 16:23:44 +00:00
* fix: always try to register clearOn events
`registerEvents` already checks for existing registered events so there is no
need to have a pre-check in `doStorageSave`. It causes issues because the
`newState` and `oldState` parameters come from the custom deserializer which
might never return `null` (e.g. transforming `null` to some default value).
Better to just use the list of registered events as a source of truth.
A performance check shows that most calls would only save a couple of
milliseconds (ranges from 0.8 ms to 18 ms) and the total amount of time
saved from application startup, to unlock, to showing the vault is about 100 ms.
I haven't been able to perceive the change.
* Revert "feat: add folder.clear warning (#16376)"
This reverts commit a2e36c4489.
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { Observable, combineLatest, of } from "rxjs";
|
|
|
|
import { LogService } from "@bitwarden/logging";
|
|
import {
|
|
CombinedState,
|
|
SingleUserState,
|
|
StateEventRegistrarService,
|
|
UserKeyDefinition,
|
|
} from "@bitwarden/state";
|
|
import { AbstractStorageService, ObservableStorageService } from "@bitwarden/storage-core";
|
|
import { UserId } from "@bitwarden/user-core";
|
|
|
|
import { StateBase } from "./state-base";
|
|
|
|
export class DefaultSingleUserState<T>
|
|
extends StateBase<T, UserKeyDefinition<T>>
|
|
implements SingleUserState<T>
|
|
{
|
|
readonly combinedState$: Observable<CombinedState<T | null>>;
|
|
|
|
constructor(
|
|
readonly userId: UserId,
|
|
keyDefinition: UserKeyDefinition<T>,
|
|
chosenLocation: AbstractStorageService & ObservableStorageService,
|
|
private stateEventRegistrarService: StateEventRegistrarService,
|
|
logService: LogService,
|
|
) {
|
|
super(keyDefinition.buildKey(userId), chosenLocation, keyDefinition, logService);
|
|
this.combinedState$ = combineLatest([of(userId), this.state$]);
|
|
}
|
|
|
|
protected override async doStorageSave(newState: T, oldState: T): Promise<void> {
|
|
await super.doStorageSave(newState, oldState);
|
|
await this.stateEventRegistrarService.registerEvents(this.keyDefinition);
|
|
}
|
|
}
|