simplify filter rule comparison

This commit is contained in:
Michael Shamoon 2022-07-08 13:55:27 -07:00
parent ffb903841b
commit 5c9ad3068b

View File

@ -29,28 +29,19 @@ export function filterRulesDiffer(
filterRulesA: FilterRule[], filterRulesA: FilterRule[],
filterRulesB: FilterRule[] filterRulesB: FilterRule[]
): boolean { ): boolean {
let modified = false let differ = false
if (filterRulesA.length != filterRulesB.length) { if (filterRulesA.length != filterRulesB.length) {
modified = true differ = true
} else { } else {
modified = filterRulesA.some((rule) => { differ = filterRulesA.some((rule) => {
return ( return (
filterRulesB.find( filterRulesB.find(
(fri) => fri.rule_type == rule.rule_type && fri.value == rule.value (fri) => fri.rule_type == rule.rule_type && fri.value == rule.value
) == undefined ) == undefined
) )
}) })
if (!modified) {
// only check other direction if we havent already determined is modified
modified = filterRulesB.some((rule) => {
filterRulesA.find(
(fr) => fr.rule_type == rule.rule_type && fr.value == rule.value
) == undefined
})
}
} }
return modified return differ
} }
export interface FilterRule { export interface FilterRule {