This document describes the event mechanism for logic development. It covers the event types supported by the platform and explains how to configure and execute event handlers. When an event is triggered, it executes a bound action, which is similar to a callback function in programming.
Event types
In the Mobi platform, events are categorized into application events, page events, page component events, frontend function events, and integration operation events. Each event type corresponds to different user actions or system state changes and can trigger the appropriate processing logic.
Application events
Application events are triggered at the application level. The following table lists all application events that the platform currently supports.
Event name |
Description |
Application initialized (inited) |
Triggered when the application finishes loading, but before the page loads successfully. Use this event to initialize data or set a state. |
Page events
Page events are triggered at the page level. The following table lists all page events that the platform currently supports.
Event name |
Description |
Mounted (mounted) |
Triggered when the page finishes loading successfully. Use this event to initialize data or set a state. During application development, press ⌘ (Mac) or Ctrl (Windows) when you switch pages from the page list. This action prevents the page `mounted` event from triggering. This is useful for editing transition pages that have a `mounted` event, as it stops the page from navigating away and becoming uneditable. |
Before unmount (willUnmount) |
Triggered just before a page unmounts, such as when you switch from the current page to another page in the page list. Use this event to save data, release resources, or manage global state. |
Page component events
Page component events are triggered when a user interacts with components on a page. The following table lists common page component events that the platform supports.
The supported event types vary by page component. For more information, see the documentation for each component.
Event name |
Description |
Click (click) |
Triggered when a user clicks a component. Common for components such as buttons and links. |
Change (change) |
Triggered when a user modifies the input content. Common for components such as input boxes and date pickers. |
Focus (focus) |
Triggered when a component gains focus. Common for components such as input boxes and date pickers. |
Blur (blur) |
Triggered when a component loses focus. Common for components such as input boxes and date pickers. |
Press enter (pressEnter) |
Triggered when the Enter key is pressed within a component. Common for components such as input boxes and multi-line input boxes. |
Frontend function events
Frontend function events are triggered by the execution of custom frontend functions. The following table lists all frontend function events that the platform currently supports.
Event name |
Description |
Success (success) |
Triggered after a frontend function executes successfully. |
Failure (failure) |
Triggered after a frontend function fails to execute. |
Integration operation events
Integration operation events are triggered when the application frontend interacts with backend services and external Application Programming Interfaces (APIs). The following table lists all integration operation events that the platform currently supports.
Event name |
Description |
Success (success) |
Triggered after an integration operation executes successfully. |
Failure (failure) |
Triggered after an integration operation fails to execute. |
Event handlers
To respond to specific runtime events, you can add and configure one or more event handlers in the designer. This is similar to the addEventListener mechanism in traditional JavaScript development.
Add and configure an event handler
In the designer, open a specific page, page component, frontend function, or integration operation. Then, add and configure an event handler in the corresponding section of the properties panel.
For example, to add an event handler for a page component, click the + button to the right of Interaction-Event in the properties panel. Click the new event handler entry to open the Configure Event Handler panel and complete the configuration. The following figure shows an example of how to configure an event handler for the click event of a page button component:
Note that event configurations do not always execute in the defined order. For operations that must follow a specific sequence, use the await keyword to ensure an asynchronous operation completes before the next one starts. For more information, see Frontend functions.
Execution of event handlers
When an event occurs, all its corresponding event handlers execute immediately in the frontend browser environment. Each event handler can be considered an independent JavaScript callback function. They are triggered in parallel, with no guaranteed order or timing dependency between them.
Additionally, responding to a single event can trigger new events. This creates an event handling chain, such as "Trigger → Respond → Trigger → Respond → ...". You can use this feature to orchestrate and implement complex, event-based logic flows.
Action types for event handlers
When you configure an event handler, you must select a specific operation, or "action", for the handler to perform when the event is triggered. The following table lists the action types for event handlers that the platform currently supports.
Action type |
Description |
Configuration parameters |
Control component |
Controls the behavior of components on a page, such as showing, hiding, enabling, or disabling a component. |
|
Integration operation |
Invokes an integration operation, such as executing a database SQL query or accessing an external HTTP API. |
|
Frontend function |
Invokes a frontend function. |
|
Manage timer |
Invokes a timer. |
|
Set variable |
Updates the value of a variable that is visible within the current scope. |
|
Execute script |
Executes a custom frontend JavaScript script. |
|
Show message |
Displays a message notification box on the page that disappears automatically after a short time. This provides immediate feedback to the user. |
|
Show notification |
Displays a notification box on the page to provide feedback on operation results or important information. |
|
Go to page |
Navigates to a specified page to implement in-app page navigation. |
|
Go to URL |
Navigates to a specified external URL. |
|
User logon |
Triggers the user logon process to guide users through identity authentication, such as when converting an anonymous user to a logged-on user. For more information, see Convert an anonymous user to a logged-on user. |
|
User logoff |
Logs off the currently logged-on user and clears the user session. |
|
Invoke user flow |
Triggers a user flow operation from within an event handler. Use this to invoke a configured user flow integration operation, such as retrieving an integration flow instance or completing a user task. For information about how to configure a user flow, see User flow operations. |
|
Trigger Tongyi Tingwu real-time stream |
Starts the Tongyi Tingwu real-time speech recognition stream ingest. This converts real-time speech input into text output. You must first create a real-time task and obtain an ingest URL through a Tongyi Tingwu integration operation before you can start. For information about how to configure a Tongyi Tingwu integration operation, see Tongyi Tingwu real-time stream. |
|
Stop Tongyi Tingwu real-time stream |
Stops the Tongyi Tingwu real-time speech recognition stream ingest, ending the real-time transmission of audio data. After your speech-related task is complete, you must stop the real-time stream first. Then, use the stop real-time task operation in the Tongyi Tingwu integration to stop the real-time task. For information about how to configure a Tongyi Tingwu integration operation, see Tongyi Tingwu real-time stream. |
|
Advanced configuration for event handlers
In addition to basic configurations, event handlers support the following advanced configuration options. These options provide more fine-grained control over the event handling logic.
Configuration option |
Description |
Configuration parameters |
Execution condition |
Allows you to specify that the event handler executes only under certain conditions. |
|
Debounce |
Used to limit the number of executions for frequently triggered event handlers. This reduces unnecessary operations. |
|