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.
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.
2 When to Use Nanoflows
2.1 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.
2.2 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:
Therefore, the best practice is to use nanoflows in online applications when they do not contain the above actions.
Changing objects without committing is not a database-related action, as changes are applied on the device or in the browser.
2.2.1 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.
3 Differences from Microflows
There are five main differences between nanoflows and microflows:
- When a nanoflow steps through its actions, client actions are directly executed. For example, an open page action immediately opens a page instead of at the end of the nanoflow. This is different from client actions in a microflow, which only run when the client receives the result from the microflow.
- When used in nanoflow activities, expressions do not support the following objects and variables:
- Nanoflows are not run inside a transaction so, if an error occurs in a nanoflow, it will not roll back any previous changes.
- Nanoflows and microflows do not provide the same actions. Some actions available in microflows are not available in nanoflows, and vice versa.
4 Notation & 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 microflow.
- Annotation is an element that can be used to put comments in a microflow.
Events represent the start and endpoints of a nanoflow and special operations in a loop.
|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.|
|Error Event||An error event defines a location where the nanoflow will stop and throw an error that occurred earlier. If you call a nanoflow, you may want to know whether any errors occurred within the nanoflow or not.|
|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 form the connection between elements.
|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 deal with making choices and merging different paths.
|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 are the actions that are executed in a microflow:
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 microflows, with the exception of start and end events.
A parameter is data that serves as input for the microflow.
Parameters are filled at the location from where the microflow is triggered.
An annotation is an element that can be used to put comments in a microflow:
4.8 Item Usages
Studio Pro visualizes which items are used by the selected element(s). It does this by showing the used items in white text on a blue background. Conversely, elements that use the item(s) returned by the selected element(s) 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.
5 Keyboard Support
The nanoflow editor offers keyboard support for navigating and manipulating the nanoflows. The following table shows the keys that can be used.
|Arrow keys||Selects the nearby element (activity, event, loop, or parameter) in the direction of the arrow.|
|Enter||Edits the properties of the selected element.|
|F2||Renames the item returned by the selected element.|
|Shift + F2 or just starting to type||Edits the caption of the selected element.|
|Ctrl + arrow keys||Moves the selected element in the direction of the arrow.|
|Tab||If a loop is selected, the first element inside the loop is selected.|
|Shift + Tab||If an element inside a loop is selected, the loop itself is selected.|
|Home||Selects the start event.|
|End||Cycles through the end events.|
|Context-menu key or Shift + F10||Opens the context menu for the currently selected element.|
6 Nanoflow Debugging
Step-by-step debugging is not supported yet. For now, we recommend using a log message activity, which is shown in the console log of Studio Pro.
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.