Events
The AuraWidget communicates through an event-driven architecture. Understanding the event model is essential for integrating and interacting with the widget effectively.
Event Philosophy
The Aura Widget uses three distinct types of events to enable bi-directional communication:
1. Commands
Commands are events that you push to the widget to trigger actions. Think of these as instructions you send to control the widget’s behavior.
- Direction: Your App → Widget
- Method:
AuraWidget.command() - Purpose: Trigger actions, open views, send data
- Naming Convention:
Namespace.Action(e.g.,Encounter.Open)
// Example: Opening an encounter
AuraWidget.command({
type: 'Encounter.Open',
payload: { encounterId: '12345', ... },
});2. Events
Events are notifications that the widget broadcasts back to you. Subscribe to these to react to state changes, user actions, or completed operations within the widget.
- Direction: Widget → Your App
- Method:
AuraWidget.on() - Purpose: Listen to state changes, user interactions, operation completions
- Naming Convention:
Namespace.EventName(e.g.,Encounter.Loaded)
// Example: Listening for encounter loaded
AuraWidget.on('Encounter.Loaded', (data) => {
console.log('Encounter ready:', data);
});3. Errors
Errors are a special category of events that notify you when something goes wrong. They follow the same subscription pattern as Events but carry error information.
- Direction: Widget → Your App
- Method:
AuraWidget.on() - Purpose: Handle failures, validation errors, and exceptions
- Naming Convention:
Namespace.Error(e.g.,Encounter.LoadedFailed)
// Example: Handling encounter errors
AuraWidget.on('Encounter.Error', ({ message, code }) => {
console.error('Encounter failed:', message, code);
});Common Error Properties
Each error event will include the following properties as part of the payload along with the namespace specific error properties:
| Property | Type | Description |
|---|---|---|
message* | string | Description of the error. |
code* | string | Unique identifier for the error type. |
Understanding this distinction helps you architect your integration correctly:
use command() to send Commands, and on() to subscribe to Events
and Errors.
API Reference
Sending Commands
Use the command method to send commands to the widget:
AuraWidget.command({
type: 'Command.Name',
payload: {
/* command data */
},
});For CDN usage:
InsightAura.AuraWidget.command({
type: 'Command.Name',
payload: {
/* command data */
},
});emit() is also available as an alias to command() for convenience.
Subscribing to Events & Errors
Use the on method to subscribe to events and errors:
AuraWidget.on('Event.Name', (data) => {
console.log(data);
});For CDN usage:
InsightAura.AuraWidget.on('Event.Name', (data) => {
console.log(data);
});Namespace-Specific Documentation
Events are organized by namespace. Each namespace groups related commands, events, and errors together. Explore the documentation for each namespace to see the full list of available interactions starting with the Encounter namespace.