CompoundCondition
CompoundConditon allow conditions to be combined into more complex logical statements. The logical operators allowed are or, and, and not.
or/and operators
or/and operatorsor & and operators require >= 2 operands to be specified.
Let's take a look at this abbreviated condition example:
import { conditions } from '@nucypher/taco';
const conditionA = ...
const conditionB = ...
const aAndB = new conditions.compound.CompoundCondition({
operator: 'and',
operands: [conditionA, conditionB],
});Here, we define two conditions conditionA and conditionB, and combine them into a single condition using and operator. So now, our new condition will "trigger" only when both conditionA and conditionB "trigger".
We can use two or more conditions when using and and or operators:
const allMustPass = new conditions.compound.CompoundCondition({
operator: 'and',
operands: [conditionA, conditionB, ..., conditionX],
});
const anyOneMustPass = new conditions.compound.CompoundCondition({
operator: 'or',
operands: [conditionA, conditionB, ..., conditionX],
});
Alternatively, we can use CompoundCondition.or and CompoundCondition.and short-hand methods
not operator
not operatorThe not operator only allows one operand.
For example:
Nested Combinations
CompoundCondition objects can be nested on itself i.e. you can create compound conditions of compound conditions.
For example:
Learn more
Last updated