Nanoflows
Introduction
Nanoflows are similar to microflows, in that they allow you to express the logic of your application. However, they do have some specific benefits (for example, they run directly on the browser/device and can be used in an offline app). Furthermore, most of the actions run directly on the device, so there is also a speed benefit for logic which does not need access to the server. For more information on how nanoflows and microflows differ, see the Differences between Microflows and Nanoflows section in Microflows and Nanoflows.
This page is an overview of all the elements that can be used in a nanoflow. For the properties of the nanoflow itself, see Nanoflow Properties.
For information on using nanoflows as data sources, see Nanoflow Source.
When to Use Nanoflows
Offline Mobile Apps
Nanoflows are designed with offline-first applications in mind, as they allow you to model application logic that works in offline apps. Since all database-related actions will be executed on the local offline database, nanoflows in offline apps will be fast.
Logic Where No Connection Is Needed
Nanoflows also offer great value to online applications (for example, for UI logic, validations, calculations, and navigation). However, please keep in mind that, when you perform database-related actions, each action will create a separate network request to the Mendix Runtime.
The following actions interact with the database:
- Create
- Commit
- Retrieve
- Rollback
Therefore, the best practice is to use nanoflows in online applications when they do not contain the above actions.
Other Cases
Although nanoflows perform best in online applications when no database-related actions are used, and these are generally the best cases, nanoflows that contain at most one database-related action can also still perform well. Because such nanoflows only require one network call, they perform as well as a microflow. An example of such a use case is performing validation logic on an object and committing the object in the same nanoflow.
Notation and Categories
The graphical notation of nanoflows is based on the Business Process Model and Notation (BPMN). BPMN is a standardized graphical notation for drawing business processes in a workflow.
A nanoflow is composed of elements. The following categories are used:
- Events represent the start and endpoints of a nanoflow and special operations in a loop
- Flows form the connection between elements
- Decisions deal with making choices and merging different paths again
- Activities are the actions that are executed in a nanoflow
- Loop is used to iterate over a list of objects
- Parameter is data that serves as input for the nanoflow.
- Annotation is an element that can be used to put comments in a nanoflow.
Events
Events represent the start and endpoints of a nanoflow and special operations in a loop.
Graphic | Name | Description |
---|---|---|
Start event | The starting point of the nanoflow. A nanoflow can only have one start event. | |
End event | Defines the location where the nanoflow will stop. Depending on the return type of the nanoflow, in some cases a value must be specified. There can be more than one end event. | |
Continue event | Used to stop the current iteration of a loop and continue with the next iteration. Continue events can only be used inside a loop. | |
Break Event | Used to stop iterating over the list of objects and to continue with the rest of the flow after the loop. Break events can only be used inside a loop. |
Flows
Flows form the connection between elements.
Graphic | Name | Description |
---|---|---|
Sequence flow | An arrow that links events, activities, decisions, and merges with each other. Together they define the order of execution within a nanoflow. | |
Annotation flow | A connection that can be used to connect an annotation to another element. |
Decisions
Decisions deal with making choices and merging different paths.
Graphic | Name | Description |
---|---|---|
Decision | Makes a decision based on a condition and follows one and only one of the outgoing flows. Note: there is no parallel execution in nanoflows. | |
Merge | Can be used to combine multiple sequence flows into one. If a choice is made in a nanoflow and afterwards some common work needs to be done, you can combine the two (or more) paths using a merge. |
Activities
Activities are the actions that are executed in a nanoflow:
Loop
A loop is used to iterate over a list of objects:
For every object the flow inside the loop is executed. A loop activity can contain all elements used in nanoflow, with the exception of start and end events.
Parameter
A parameter is data that serves as input for the nanoflow.
Parameters are filled at the location from where the nanoflow is triggered.
Annotation
An annotation is an element that can be used to put comments in a nanoflow:
Item Usages
Studio Pro visualizes which items are used by the selected element (or elements). It does this by showing the used items in white text on a blue background. Conversely, elements that use the item (or items) returned by the selected element (or elements) are marked with the word ‘Usage’ in white text on a green background.
In the example below, the parameter AccountPasswordData is highlighted because it is used in the selected activity (Retrieve Account). And the activity Save password has a Usage label because it uses the object returned by Retrieve Account.
Keyboard Support
For an overview of the shortcut keys that are supported in the nanoflow editor, see the Microflow, Nanoflow, and Rule Editor Shortcut Keys section in Keyboard Shortcuts.
Security
Nanoflows are executed in the context of the current user. Any operation for which the user is unauthorized will fail. For instance, when objects are retrieved in a nanoflow, only the ones for which the current user has read access will be returned. Committing an object only succeeds when the current user has write access for all changes.
Converting a Nanoflow to a Microflow
To convert a nanoflow to a microflow, you have two options. The first option is to right-click anywhere in the nanoflow editor and select Convert to microflow. Alternatively, in the App Explorer, right-click on the name of the nanoflow you want to convert, and select Convert to microflow.
A new microflow is created and added to the same directory, and you can get consistency errors if there are actions that are not supported by microflows.
Canvas Interaction
In the nanoflow editor from Studio Pro 10.6, you can use common patterns like unlimited canvas, enhanced zoom and scroll, and a snap-to-flow to make new activities from the toolbox and toolbar always well aligned in your flow.