You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/resources/control-flow/functions/action-blocks.md
+87-9Lines changed: 87 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,16 +6,94 @@ title: Action Blocks
6
6
An Action Block is a set of actions that perform a specific task and can be reused in different parts of the app. If you find yourself repeatedly performing a particular set of operations in your app, it may be helpful to create an Action Block. This allows you to break down complex actions into smaller, more manageable units, making them easier to understand and modify in the future.
7
7
8
8
Action Blocks have different scopes, which determine their availability:
|**App Level Action Blocks**| Usable across the entire app. You can create an App Level Action Block from any page or component, and it will be accessible for viewing or editing from any page or component as well. | Internally, an App Level Action Block can only access the state variables available in its scope (e.g., app state variables). |
12
+
|**Page Level Action Blocks**| Restricted to the page in which they were created. These can access the state variables available in their scope, such as page state variables, as well as variables above their scope, such as App State variables. | Page Level Action Blocks can access page state variables and App State variables. |
13
+
|**Component Level Action Blocks**| Restricted to the component in which they were created. These can access the state variables available in their scope, such as component state variables, as well as variables from higher scopes, like page and App State variables. | Component Level Action Blocks can access component state variables, page state variables, and App State variables. |
9
14
10
-
-**App Level Action Blocks:** Usable across the entire app.
11
-
-**Page Level Action Blocks:** Restricted to the page in which they were created.
12
-
-**Component Level Action Blocks:** Restricted to the component in which they were created.
13
15
14
-
## App Level Action Blocks
16
+
## Action Blocks Structure
17
+
When creating an action block, the process of defining the flow is similar to defining Actions.
18
+
The main difference is in choosing the scope and defining the input & output values of the
19
+
Action Block.
20
+
21
+
### Choosing the Scope of Action Block
22
+
23
+
As discussed, Action Blocks can be **App Level, Page Level**, or **Component Level**. App Level Action Blocks can be created from any widget's action properties throughout the app. However, Page Level or Component Level Action Blocks are only available in the Page or Component where they were created.
24
+
25
+
Usually, you will see a dropdown to choose between App Level, Page Level, or Component Level. Choose the scope based on your Action Block's use case.
26
+
27
+

28
+
29
+
30
+
### Input Parameters
31
+
32
+
Action Blocks have access to the state variables available in the same scope as the Action Block
33
+
(for e.g Page State variables can be accessed from Page Level Action Blocks). However, there
34
+
will be times when you may need to input some parameters for the Action Block to perform its logic. These are called **Action Parameters**, and they can be added from the Action Flow Editor when you create a new Action.
35
+
36
+
For example, here is a small demo where we create an Action Block with an input parameter.
37
+
38
+
n this example, we add an item to the wishlist of an e-commerce app. Let's say our local wishlist is saved in an App State variable called `localWishlist`, and we have a reusable Action Block called `addToWishlist` that takes an input parameter called productId and performs the actions to add it to the `localWishlist` object.
Often, your Action Block may return a value. For example, in our Product Cart Page, we have a reusable Component Level Action Block called `getTotalCost` that returns the final cost of all the products. You can define such an Action Block that returns a value (e.g., a double for this example) or a value related to your use case. You can define the return value in the Action Flow Editor. Let's see one example.
71
+
72
+
<div style={{
73
+
position: 'relative',
74
+
paddingBottom: 'calc(56.67989417989418% + 41px)', // Keeps the aspect ratio and additional padding
0 commit comments