Skip to content

Commit 5ee723e

Browse files
committed
Branch Construct updated
1 parent dee2d10 commit 5ee723e

File tree

7 files changed

+229
-0
lines changed

7 files changed

+229
-0
lines changed
18.7 KB
Loading
40.3 KB
Loading
543 KB
Loading
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
[
2+
{
3+
"comment": "",
4+
"evaluate-labels": "true",
5+
"label": null,
6+
"nodes": [
7+
{
8+
"comment": "",
9+
"exit-on": "FAILURE",
10+
"label": "action == 'multiplication'",
11+
"nodes": [
12+
{
13+
"comment": "",
14+
"label": "Math",
15+
"nodes": [
16+
{
17+
"comment": "",
18+
"label": null,
19+
"mode": "INPUT",
20+
"type": "MAP",
21+
"nodeIndex": 0
22+
},
23+
{
24+
"comment": "",
25+
"label": null,
26+
"mode": "OUTPUT",
27+
"type": "MAP",
28+
"nodeIndex": 1
29+
}
30+
],
31+
"service": "pub.math:multiplyInts",
32+
"type": "INVOKE",
33+
"validate-in": null,
34+
"validate-out": null,
35+
"node_hints": {
36+
"name": null,
37+
"itemType": "SERVICES",
38+
"serviceInfo": {
39+
"groupDisplayName": "Math",
40+
"groupName": "math",
41+
"services": null
42+
},
43+
"serviceName": {
44+
"displayName": "multiplyInts",
45+
"serviceName": "pub.math:multiplyInts",
46+
"transformerSupport": "true"
47+
},
48+
"ui_step_index": 3,
49+
"nodeIndex": 0,
50+
"mapSet": null,
51+
"outputMapSet": null,
52+
"serviceReferenceResolved": true
53+
},
54+
"nodeIndex": 0
55+
}
56+
],
57+
"type": "SEQUENCE",
58+
"node_hints": {
59+
"name": "EXPRESSION",
60+
"itemType": "CONTROLS",
61+
"nodeIndex": 0
62+
},
63+
"nodeIndex": 0
64+
},
65+
{
66+
"comment": "",
67+
"exit-on": "FAILURE",
68+
"label": "action = /^add/",
69+
"nodes": [
70+
{
71+
"comment": "",
72+
"label": "Math",
73+
"service": "pub.math:addInts",
74+
"type": "INVOKE",
75+
"validate-in": null,
76+
"validate-out": null,
77+
"node_hints": {
78+
"name": null,
79+
"itemType": "SERVICES",
80+
"serviceInfo": {
81+
"groupDisplayName": "Math",
82+
"groupName": "math",
83+
"services": null
84+
},
85+
"serviceName": {
86+
"displayName": "addInts",
87+
"serviceName": "pub.math:addInts",
88+
"transformerSupport": "true"
89+
},
90+
"ui_step_index": 5,
91+
"nodeIndex": 0,
92+
"serviceReferenceResolved": true
93+
},
94+
"nodeIndex": 0
95+
}
96+
],
97+
"type": "SEQUENCE",
98+
"node_hints": {
99+
"name": "EXPRESSION",
100+
"itemType": "CONTROLS",
101+
"nodeIndex": 1
102+
},
103+
"nodeIndex": 1
104+
},
105+
{
106+
"comment": "",
107+
"exit-on": "FAILURE",
108+
"label": "action=='subtraction'",
109+
"nodes": [
110+
{
111+
"comment": "",
112+
"label": "Math",
113+
"service": "pub.math:subtractInts",
114+
"type": "INVOKE",
115+
"validate-in": null,
116+
"validate-out": null,
117+
"node_hints": {
118+
"name": null,
119+
"itemType": "SERVICES",
120+
"serviceInfo": {
121+
"groupDisplayName": "Math",
122+
"groupName": "math",
123+
"services": null
124+
},
125+
"serviceName": {
126+
"displayName": "subtractInts",
127+
"serviceName": "pub.math:subtractInts",
128+
"transformerSupport": "true"
129+
},
130+
"ui_step_index": 7,
131+
"nodeIndex": 0,
132+
"serviceReferenceResolved": true
133+
},
134+
"nodeIndex": 0
135+
}
136+
],
137+
"type": "SEQUENCE",
138+
"node_hints": {
139+
"name": "EXPRESSION",
140+
"itemType": "CONTROLS",
141+
"nodeIndex": 2
142+
},
143+
"nodeIndex": 2
144+
},
145+
{
146+
"comment": "",
147+
"exit-on": "FAILURE",
148+
"label": "$default",
149+
"nodes": [
150+
{
151+
"comment": "",
152+
"failure-message": "No Match Found",
153+
"from": "$flow",
154+
"label": null,
155+
"signal": "FAILURE",
156+
"type": "EXIT",
157+
"node_hints": {
158+
"itemType": "CONTROLS",
159+
"name": "EXIT",
160+
"nodeIndex": 1
161+
},
162+
"nodeIndex": 0
163+
}
164+
],
165+
"type": "SEQUENCE",
166+
"node_hints": {
167+
"name": "EXPRESSION",
168+
"itemType": "CONTROLS",
169+
"nodeIndex": 3
170+
},
171+
"nodeIndex": 3
172+
}
173+
],
174+
"type": "BRANCH",
175+
"node_hints": {
176+
"name": "BRANCH",
177+
"itemType": "CONTROLS",
178+
"nodeIndex": 0
179+
},
180+
"nodeIndex": 0
181+
}
182+
]

content/conditional-constructs.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ Conditional steps are those steps which performs different actions based on the
1010
* Else
1111
* ElseIf
1212
* Switch
13+
* Branch
1314
<Feature name="Conditional Constructs"/>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: "Conditions with Branch"
3+
metaTitle: "Syntax Highlighting is the meta title tag for this page"
4+
metaDescription: "This is the meta description for this page"
5+
---
6+
import branchJSON from '../assets/conditional-constructs/data/branch_example.json'
7+
8+
The `Branch` step contains one or many `Expression` steps and executes only one of the `Expression` step which is evaluated to true and comes sequentially first.
9+
All the other `Expression` steps under branch are ignored.
10+
11+
## Types of 'Expression' step
12+
There are mainly two kinds of `Expression` steps:
13+
* **'custom'** Expression
14+
This step executes when the condition/conditions given inside this step is evalated to true.
15+
The conditions can be any of the options mentioned in the conditional builder, in addition, user can specify a **regex** as well.
16+
17+
* Expression with **'$default'**
18+
This step executes when none of the `Expression` steps are evaluated to true.
19+
This step, if present, can be anywhere in the sequence and is executed at the last.
20+
21+
## Example - perform basic arithmetic operations based on user input
22+
23+
Lets write a FlowService which will perform arithmetic operations based on the action given by user.
24+
* `Expression 1`: If input is equal to 'multiplication', perform multiplication of two integers.
25+
* `Expression 2`: If input starts with 'add', perform addition of two integers.
26+
* `Expression 3`: If input is equal to 'subtraction', perform subtraction of two integers.
27+
* `Expression $default`: If the input doesn't match with any of the above expressions, the exit with failure message 'No match Found'
28+
29+
Add input from [I/O panel](/define-io/1_adding_fields)
30+
31+
![I/O panel](../assets/conditional-constructs/Branch-io.png)
32+
33+
* Add steps as shown
34+
35+
<FlowService
36+
textToCopy={branchJSON}>
37+
<FlowStep comment="Conditional execution of arithmetic operations" img="conditional-constructs/branch-example.png"/>
38+
</FlowService>
39+
40+
* Following is the demo of how the branch executes for a sample of inputs
41+
42+
![branch](../assets/conditional-constructs/branchexec_demo.gif)

src/components/mdxComponents/data.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@
7676
{
7777
"title": "The Switch Case",
7878
"link": "/conditional-constructs/4-using-switch"
79+
},
80+
{
81+
"title": "Evaluating Expressions with Branch",
82+
"link": "/conditional-constructs/5-using-branch"
7983
}
8084
]
8185
},

0 commit comments

Comments
 (0)