Trigger

A function's Trigger is what initiates its action. It "listens" for specific events and, when one occurs, tells the function to execute its logic. These events can be triggered by user interactions, changes in data, or the application's lifecycle. A single function can be associated with multiple trigger events.

Trigger Sources & Events

The following events can be used to trigger a function:

Data-Driven Events

A function can be triggered automatically when data changes in your application logic. You can link an input, output, or modifier from another function to a trigger and set it to execute on change, on update, or when the value becomes true.

UI & App Lifecycle Events

Triggers can be initiated by user actions in the UI or by the app's state:

  • Click of a Button

  • Loading of a Page

  • App Start: Can be configured to run once or periodically (from every 0.1 seconds to once a day).

  • App Stop

Manual Execution

While in the App Builder (during build-time), you can manually execute any function for testing purposes by clicking its trigger icon.

Note on Execution Order: When a single event triggers multiple functions (e.g., on Page Load), there is no guaranteed order of execution. In this case, it's best to link the functions in a chain so they trigger one after the other.

Configuring a Trigger

You can configure a trigger in several ways:

  • By Linking: The most common method is to drag-and-drop a data source (like another function's output), a page, or a UI event (like a button's onClick) onto the trigger.

  • By Right-Clicking: Right-click the trigger to open its context menu. This is where you configure lifecycle events like on App Start (with options for 'once' or periodic intervals) and on App Stop.

To unlink an event from a trigger, click the x next to the event name listed on the trigger.

Sequential Processing (Looping)

To process an array of data item by item, you can configure a trigger to execute the function for each value within the array individually. This corresponds to a for loop in traditional programming.

To configure sequential processing:

  1. Right-click on the trigger to open the context menu.

  2. Hover over Process One By One.

  3. Select the input that contains the array you want to loop through. The trigger icon will change to a dotted line to indicate that sequential processing is active.

To switch back to regular processing, right-click the trigger and select Process Regularly.

Example: Merging an Element into an Array

A common use case for sequential processing is merging a single element into each sub-array of a larger array.

The image below illustrates a combine function where the trigger is configured to Process One By One on its first input (On arg 1). As a result, the function executes for each sub-array, and the singular element from the second input is merged into both.

Sequential processing of functions

Delayed Execution

You can add a short delay, from 0.1 to 2 seconds, to a function's trigger. This is useful for managing timing in your application, such as waiting for a UI animation to complete or preventing a function from firing too rapidly.

To configure a delay, right-click on the trigger to open its context menu and select the desired delay time.

Explainer video

Last updated