Functions

Functions are self-contained blocks of code that can be invoked at any point to compute and retrieve specific data or results. Supernova comes with dozens of pre-defined functions that help you to obtain the data from the Universal Data Model and some that help with additional tasks, such as comparing values to other values, generating random test data, and many more.

Syntax

Each function call starts with @ symbol and is invoked using () brackets. For example, this is how you obtain all the data about all the screens in the current project:

{[ let screens @project.allScreens() /]}

This creates a new variable screens that is filled with data about all the screens in the current project. Function allScreens doesn't take any input parameters, so its invoked only with ().

Input parameters

In some cases, functions require input parameters to be provided. For example, this is how you obtain data about a specific screen in the current project:

{[ let screen @project.screenById(screenId) /]}

This again creates a new variable screen that is filled with data about a specific screen. We have specified the screen by providing screenId to the function call.

Multiple input parameters

Some functions also require more than just one input parameter. In this case, you separate them with , . Note that spaces between parameters are ignored, so we recommend writing them after each separator, which helps readability a lot:

{[ let component @project.componentById(componentId, screenId)

Variadic functions

Some functions you'll encounter are variadic. This means that they take any number of input parameters and they all contribute to the output of the function. A good example is @and function used for boolean operations:

{[ let isPartialSuccess @and(result1, result2) /]}
{[ let isSuccess @and(result1, result2, result3, result4) /]}

@and is a variadic function and you can use it to test whether all parameters are true - be it 2 in the first definition, or 4 in the second one.

Custom functions

Custom functions are currently not supported. However, if you need to reuse some pieces of code, you can achieve the same thing using inject flow.

We understand the need for custom functions, ideally with a full range and capability of a full programming language such as javascript, typescript, or similar. We are currently working on a solution that will enable just that.

Available functions

There are two types of functions - core functions such as @and, @or, and similar, and functions that directly access the Universal Data Model and allow you to get or compute data from opened projects.