Skip to content

Commit 35d0445

Browse files
committed
Update Condition Nodes.md
1 parent 4f5ec65 commit 35d0445

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

darc-docs/docs/DARC Protocol/Condition Nodes.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ struct NodeParam {
2323

2424
There are three logical operators in the DARC protocol: `AND`, `OR`, and `NOT`. The `AND` operator returns true if all of its children are true. The `OR` operator returns true if any of its children are true. The `NOT` operator returns true if its child is false. There must be at least one child for the `AND` and `OR` operators, and only one child for the `NOT` operator.
2525

26-
In both By-law Script and darc.js SDK, you can use the `and()`, `or()`, and `not()` functions to create the logical operators, for example:
26+
In both By-law Script and darc.js SDK, you can use the `and()`, `or()`, and `not()` wrapper functions to create the logical operators, for example:
2727

2828
In darc.js SDK:
2929

3030
```ts
31-
import {and, or, not} from 'darcjs';
31+
import {and, or, not, AND, OR, NOT} from 'darcjs';
3232

3333
const conditionTree = and(
3434
or(
@@ -42,6 +42,20 @@ const conditionTree = and(
4242
expression4()
4343
)
4444
);
45+
46+
// or using the class constructor
47+
const conditionTree = new And(
48+
new OR(
49+
expression1(),
50+
expression2()
51+
),
52+
53+
expression3(),
54+
55+
new NOT(
56+
expression4()
57+
)
58+
);
4559
```
4660

4761
In By-law Script:
@@ -59,6 +73,20 @@ const conditionTree = and(
5973
expression4()
6074
)
6175
);
76+
77+
// or using the class constructor
78+
const conditionTree = new AND(
79+
new OR(
80+
expression1(),
81+
expression2()
82+
),
83+
84+
expression3(),
85+
86+
new NOT(
87+
expression4()
88+
)
89+
);
6290
```
6391

6492
Also you can use `|` for `OR`, `&` for `AND`, and `!` for `NOT` in By-law Script, and these operators will be parsed into the corresponding condition nodes. For example, the above By-law Script can be written as:
@@ -70,6 +98,10 @@ const conditionTree =
7098
( ! expression4() );
7199
```
72100

101+
### Boolean Values
102+
103+
There are two boolean values in the DARC protocol: class `TRUE` and clss `FALSE`, or wrapper function `boolean_true()` and `boolean_false()`. They are used to represent a boolean node in the condition tree.
104+
73105
### Condition Expression
74106

75107
1. There are multiple batch-operations, including:

0 commit comments

Comments
 (0)