A function that receives the instance of the class the property belongs in as a parameter and return a boolean.
Optional
then: Primitive<Target>Property type to read if the 'cond' function pass.
Optional
args: RelationParameters<This, Args>Optional arguments passed to the nested type definition if the 'cond' pass.
The property decorator function.
In the following example the data
property will be associated with a
unsigned 16 bit integer if the value of the property type is equal to
0x01
.
If the condition is not met the data
property will be left undefined.
class Protocol {
@Relation(PrimitiveSymbol.u8)
type: number
@IfThen(instance => instance.type === 0x01, PrimitiveSymbol.u16)
@Else()
data: number
}
The @IfThen
decorators are executed with a top-down direction. This means
the condition the further away from the property get executed first.
class Protocol {
@IfThen(_ => true, Foo) // This one get picked first.
@IfThen(_ => true, Bar)
@Else()
condition: Foo | Bar
}
The @IfThen
decorator is often used in conjunction with other conditional
decorators like Else.
@IfThen
decorator determine if a Primitive passed as argument should be read with the associated property based on a condition passed as argument.