Skip to content

Commit

Permalink
refactor(hub-common): re-use getPredicateValuesByKey
Browse files Browse the repository at this point in the history
affects: @esri/hub-common
  • Loading branch information
velveetachef committed Jan 30, 2025
1 parent fa81971 commit 202324d
Showing 1 changed file with 2 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import { unique } from "../../../util";
import { IFilter } from "../../types/IHubCatalog";
import { getPredicateValuesByKey } from "./getPredicateValuesByKey";

export const getUniquePredicateValuesByKey = <T>(
filters: IFilter[],
predicateKey: string
): T[] => {
const toPredicateValuesByKey = (a1: T[], filter: IFilter): T[] =>
filter.predicates.reduce<T[]>(
(a2, predicate) =>
Object.entries(predicate).reduce(
(a3, [key, val]) =>
key === predicateKey
? [...a3, ...(Array.isArray(val) ? val : [val])]
: a3,
a2
),
a1
);
return filters.reduce<T[]>(toPredicateValuesByKey, []).filter(unique);
return getPredicateValuesByKey<T>(filters, predicateKey).filter(unique);
};

0 comments on commit 202324d

Please sign in to comment.