mirror of
https://github.com/bitwarden/browser
synced 2026-02-10 05:30:01 +00:00
improve type specificity and clarity
This commit is contained in:
@@ -10,6 +10,8 @@ function active(
|
||||
status$: Observable<AchievementEvent[]>,
|
||||
): OperatorFunction<AchievementValidator[], AchievementValidator[]> {
|
||||
return pipe(
|
||||
// TODO: accept a configuration observable that completes without
|
||||
// emission when the user has opted out of achievements
|
||||
withLatestFrom(status$),
|
||||
map(([monitors, log]) => {
|
||||
// partition the log into progress and earned achievements
|
||||
@@ -23,7 +25,7 @@ function active(
|
||||
// 🧠 the filters could be lifted into a function argument & delivered
|
||||
// as a `Map<FilterType, (monitor) => bool>
|
||||
|
||||
if (m.trigger === "once") {
|
||||
if (m.trigger === "until-earned") {
|
||||
// monitor disabled if already achieved
|
||||
return !earnedByName.has(m.achievement);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ const TotallyAttachedValidator = {
|
||||
description: "Attached a file to a send or item",
|
||||
metric: ItemCreatedProgress,
|
||||
validator: Type.HasTag,
|
||||
trigger: "once",
|
||||
trigger: "until-earned",
|
||||
hidden: false,
|
||||
filter(item) {
|
||||
return item.tags?.includes("with-attachment") ?? false;
|
||||
|
||||
@@ -38,7 +38,7 @@ export type Achievement = {
|
||||
validator: ValidatorId;
|
||||
|
||||
// pre-filter that disables the rule if it's met
|
||||
trigger: "once" | RequireAtLeastOne<{ low: number; high: number }>;
|
||||
trigger: "until-earned" | RequireAtLeastOne<{ low: number; high: number }>;
|
||||
|
||||
// whether or not the achievement is hidden until it is earned
|
||||
hidden: boolean;
|
||||
@@ -47,10 +47,10 @@ export type Achievement = {
|
||||
// consumed by validator
|
||||
export type AchievementValidator = Achievement & {
|
||||
// when the watch triggers on incoming user events
|
||||
filter: (item: EventFormat) => boolean;
|
||||
filter: (item: UserActionEvent) => boolean;
|
||||
|
||||
// observe data from the event stream and produces measurements
|
||||
measure?: (item: EventFormat, metrics: Map<MetricId, number>) => AchievementProgressEvent[];
|
||||
measure?: (item: UserActionEvent, metrics: Map<MetricId, number>) => AchievementProgressEvent[];
|
||||
|
||||
// monitors achievement progress and emits earned achievements
|
||||
award?: (
|
||||
|
||||
Reference in New Issue
Block a user