Implementation:AGenUI AGenUI Component Action And Sync
| Knowledge Sources | |
|---|---|
| Domains | UI_Framework, Data_Binding |
| Last Updated | 2026-10-24 17:21 GMT |
Overview
Action execution and bidirectional data sync methods on `ComponentModel`, handling user interaction events, function-call actions, and data model synchronization, provided by the AGenUI C++ core.
Description
The `executeAction()` and `syncValue()` methods on `ComponentModel` handle the two directions of user interaction:
`executeAction(surfaceId, dispatcher, contextJson)`: triggered when a user interacts with a component (click, tap, etc.). The call chain is: `SurfaceManager::submitUIAction()` → `SurfaceCoordinator::handleAction()` → `Surface::handleUserAction()` → `ComponentModel::executeAction()`.
The method first checks for a caller-supplied context action (passed via `contextJson`). This is used by custom components whose sub-regions carry their own actions (e.g., `SpanText` spans): the platform layer passes `{"action": <A2UI action definition>}` as context. If the context action parses and executes successfully, the method returns. If parsing fails or the context doesn't contain an action, it falls through to the component's own `action` attribute.
The action `DataValue` is either:
- `EventActionData`: calls `eventAction->execute(surfaceId, rawId, dispatcher)` → `EventDispatcher::dispatchActionEventRouted()`.
- `FunctionCallActionData`: calls `functionCallAction->execute()` → resolves the function call via `FunctionCallManager`.
`syncValue(attributeName, value)`: triggered when user input changes a component's bound data (e.g., typing in a text field). The call chain is: `SurfaceManager::submitUIDataModel()` → `SurfaceCoordinator::handleSyncUIToData()` → `Surface::syncUIToData()` → `ComponentModel::syncValue()`.
Only `DataBindingData` attributes are synchronized. The method finds the attribute, checks it's a `DataBindingDataValue`, and calls `syncBindingValue(value)`, which updates the data model at the bound path.
Usage
- Action handling: triggered internally by the SDK when the platform calls `submitUIAction()`.
- Data sync: triggered internally when the platform calls `submitUIDataModel()`.
- Context actions: platform can pass `contextJson` with an action override for sub-region interactions.
Code Reference
Source Location
- Repository: AGenUI
- executeAction: `core/src/surface/component_manager/agenui_component_model.cpp:L456-513`
- syncValue: `core/src/surface/component_manager/agenui_component_model.cpp:L91-106`
- handleAction entry: `core/src/surface/agenui_surface_coordinator.cpp:L193-212`
Signature
// ComponentModel methods
namespace agenui {
class ComponentModel {
// Execute the component's action (event or function call)
// @param surfaceId Surface context
// @param dispatcher Event fan-out
// @param contextJson Optional caller-supplied action override
void executeAction(const std::string& surfaceId,
EventDispatcher* dispatcher,
const std::string& contextJson = "");
// Synchronize a bound data attribute with a new value (user input → data model)
// Only affects DataBindingData attributes
void syncValue(const std::string& attributeName,
const std::string& value);
};
} // namespace agenui
Import
#include "surface/component_manager/agenui_component_model.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| surfaceId | `const std::string&` | Yes | Surface context for the action |
| dispatcher | `EventDispatcher*` | Yes | Event fan-out for dispatching events |
| contextJson | `const std::string&` | No | Caller-supplied action override (for sub-region actions) |
| attributeName | `const std::string&` | Yes (syncValue) | Bound data attribute name |
| value | `const std::string&` | Yes (syncValue) | New value from user input |
Outputs
| Name | Type | Description |
|---|---|---|
| (executeAction) | Dispatches event via dispatcher or executes function call | |
| (syncValue) | Updates DataBindingDataValue, propagates to data model |
Usage Examples
Action Flow (SDK Internal)
// User clicks a Button component → platform calls:
surfaceManager->submitUIAction(actionMsg);
// SDK internal flow:
// SurfaceManager::submitUIAction → posts to worker thread
// → SurfaceCoordinator::handleAction(msg)
// → Surface::handleUserAction(componentId, actionType, contextJson)
// → ComponentModel::executeAction(surfaceId, dispatcher, contextJson)
// → if contextJson has action: execute it (sub-region action)
// → else: execute component's "action" attribute
// → EventActionData: dispatcher->dispatchActionEventRouted(content)
// → FunctionCallActionData: functionCallAction->execute()
Data Sync Flow (SDK Internal)
// User types in TextField → platform calls:
surfaceManager->submitUIDataModel(syncMsg);
// SDK internal flow:
// SurfaceManager::submitUIDataModel → posts to worker thread
// → SurfaceCoordinator::handleSyncUIToData(msg)
// → Surface::syncUIToData(componentId, change)
// → ComponentModel::syncValue("value", newText)
// → DataBindingDataValue.syncBindingValue(newText)
// → DataModel updated at bound path
// → Other components bound to same path re-evaluate