this.preAppliedList
这是一系列
IResFilter
.
不是那个形状的
IResFilter过滤器
所以我的问题是;
给定的输出
includesFilter
RifElse
函数I将移除或添加筛选器。
这意味着,首先遍历数组以确定项是否已在数组中,然后遍历同一数组以添加或删除项。
数组的最大长度可以是200,但用户不太可能应用这么多同一类型的过滤器。
出于可伸缩性的考虑,我如何在Ramda中编写相同的逻辑,通过只遍历一次数组来提高性能。
P、 我知道我可以使用for循环来确保单数组遍历和短路,但我想知道Ramda的方法。
export interface IResFilter {
DisplayKeyItem: string;
DisplayKeyValue: string;
KeyItem: string;
Countor: string;
FilterName: string;
selected?: boolean;
}
export const areFiltersSame = (f1: IResFilter, f2: IResFilter) =>
ReqBy(Rpick(['DisplayKeyValue', 'KeyItem']), f1, f2);
updatePreAppliedList(filter: IResFilter): void {
const areFiltersSameCurried = Rcurry(areFiltersSame)(filter);
const includesFilter = Rany(areFiltersSameCurried);
const removeFilter = Rreject(areFiltersSameCurried);
this.preAppliedList = RifElse(
includesFilter,
removeFilter,
Rappend(filter)
)(this.preAppliedList);
}