1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-08 20:50:28 +00:00

eliminate repeat algorithm emissions

This commit is contained in:
✨ Audrey ✨
2025-04-28 16:14:15 -04:00
parent 09b63448bb
commit ba895bc347
2 changed files with 9 additions and 12 deletions

View File

@@ -171,13 +171,13 @@ export class CredentialGeneratorComponent implements OnInit, OnChanges, OnDestro
// construct options for username and email algorithms; replace forwarder
// entry with a virtual entry for drill-down
const usernames = algorithms.filter((a) => !isForwarderExtensionId(a.id));
usernames.sort((un) => un.weight);
usernames.sort((username) => username.weight);
const usernameOptions = this.toOptions(usernames);
usernameOptions.push({ value: FORWARDER, label: this.i18nService.t("forwardedEmail") });
// construct options for forwarder algorithms; they get their own selection box
const forwarders = algorithms.filter((a) => isForwarderExtensionId(a.id));
forwarders.sort((fwd) => fwd.weight);
forwarders.sort((forwarder) => forwarder.weight);
const forwarderOptions = this.toOptions(forwarders);
forwarderOptions.unshift({ value: NONE_SELECTED, label: this.i18nService.t("select") });
@@ -475,14 +475,10 @@ export class CredentialGeneratorComponent implements OnInit, OnChanges, OnDestro
this.username.setValue(username.selection, { emitEvent: false });
this.forwarder.setValue(forwarder.selection, { emitEvent: false });
// update subjects within the angular zone so that the
// template bindings refresh immediately
this.zone.run(() => {
// update cascade visibility
activeRoot$.next(root.active);
activeIdentifier$.next(username.active);
activeForwarder$.next(forwarder.active);
});
// update cascade visibility
activeRoot$.next(root.active);
activeIdentifier$.next(username.active);
activeForwarder$.next(forwarder.active);
});
// automatically regenerate when the algorithm switches if the algorithm

View File

@@ -14,7 +14,7 @@ import { BoundDependency } from "@bitwarden/common/tools/dependencies";
import { ExtensionSite } from "@bitwarden/common/tools/extension";
import { SemanticLogger } from "@bitwarden/common/tools/log";
import { SystemServiceProvider } from "@bitwarden/common/tools/providers";
import { anyComplete, pin } from "@bitwarden/common/tools/rx";
import { anyComplete, memoizedMap, pin } from "@bitwarden/common/tools/rx";
import { UserStateSubject } from "@bitwarden/common/tools/state/user-state-subject";
import { UserStateSubjectDependencyProvider } from "@bitwarden/common/tools/state/user-state-subject-dependency-provider";
@@ -149,7 +149,8 @@ export class GeneratorMetadataProvider {
.policiesByType$(PolicyType.PasswordGenerator, id)
.pipe(
map((p) => availableAlgorithms(p).filter((a) => this._metadata.has(a))),
map((p) => new Set(p)),
memoizedMap((p) => new Set(p), { key: (p) => JSON.stringify(p) }),
distinctUntilChanged(),
// complete policy emissions otherwise `switchMap` holds `available$` open indefinitely
takeUntil(anyComplete(id$)),
);