The IfThenElseCondition
allows for conditional branching, where different conditions are executed based on the outcome of an initial "if" condition. It operates with a simple "if-then-else" structure and provides flexibility in determining the behaviour when a condition is true or false.
A condition that allows for if-then-else branching based on underlying conditions
i.e. IF CONDITION_A
THEN CONDITION_B
ELSE CONDITION_C
.
It is composed of:
ifCondition
: A required field that specifies the condition to be evaluated first. If the condition evaluates totrue
, thethenCondition
is executed; if it evaluates tofalse
, theelseCondition
is executed.thenCondition
: A required field that specifies the action or condition to execute if theifCondition
evaluates totrue
.elseCondition
: A required field that specifies the action or condition to execute if theifCondition
evaluates tofalse
. This can be aCONDITION
or a boolean value (true
orfalse
), specifying the result when theifCondition
isfalse
. This gives users control over what the overall condition returns when theifCondition
is false.
When combined with other conditions (e.g., SequentialCondition
, CompoundCondition
), the IfThenElseCondition
allows for complex, branching workflows.
import { conditions } from '@nucypher/taco';
const conditionA = ...
const conditionB = ...
const conditionC = ...
const condition = new conditions.ifThenElse.IfThenElseCondition({
ifCondition: conditionA,
thenCondition: conditionB,
elseCondition: conditionC,
});
import { conditions } from '@nucypher/taco';
const conditionA = ...
const conditionB = ...
const condition = new conditions.ifThenElse.IfThenElseCondition({
ifCondition: conditionA,
thenCondition: conditionB,
elseCondition: true,
});
import { conditions } from '@nucypher/taco';
const conditionA = ...
const conditionB = ...
const conditionC = ...
const conditionD = ...
const nestedIfThenElseCondition = new conditions.ifThenElse.IfThenElseCondition({
ifCondition: conditionA,
thenCondition: conditionB,
elseCondition: false,
});
const condition = new conditions.ifThenElse.IfThenElseCondition({
ifCondition: conditionC,
thenCondition: conditionD,
elseCondition: nestedIfThenElseCondition,
});
{% hint style="info" %}
Individual conditions within the IfThenElseCondition
can use different chain IDs as long as the chain IDs are supported by the domain
network being used.
{% endhint %}
- Client-side: nucypher/taco-web#593
- Server-side: nucypher/nucypher#3558