Actions Overview

All available action types

Actions define what happens in response to events. They are the building blocks of interactivity in Orbis plugins.

Action Structure

Every action has a type and type-specific properties:

json
{
  "type": "update_state",
  "path": "count",
  "value": "{{state.count}} + 1"
}

Action Types

TypePurpose
update_stateModify page state
call_apiMake API requests
navigateChange routes
show_toastDisplay notifications
show_dialogShow confirmation dialogs
close_dialogClose dialogs
debounced_actionDebounce actions
validate_formValidate forms
reset_formReset form values
set_loadingSet loading state
downloadDownload files
copyCopy to clipboard
open_urlOpen external URLs
emitEmit custom events
conditionalConditional execution
sequenceSequential execution

Using Actions

In Event Handlers

json
{
  "type": "Button",
  "label": "Click Me",
  "events": {
    "on_click": [
      { "type": "update_state", "path": "clicked", "value": true },
      { "type": "show_toast", "message": "Button clicked!" }
    ]
  }
}

In Lifecycle Hooks

json
{
  "on_mount": [
    { "type": "call_api", "api": "getData" }
  ],
  "on_unmount": [
    { "type": "update_state", "path": "selectedItem", "value": null }
  ]
}

Chaining Actions

Actions execute in sequence:

json
{
  "events": {
    "on_click": [
      { "type": "set_loading", "loading": true },
      { "type": "call_api", "api": "save" },
      { "type": "show_toast", "message": "Saved!" },
      { "type": "set_loading", "loading": false }
    ]
  }
}

Event Context

Actions have access to event context via special variables:

VariableContextDescription
$eventAll eventsRaw event object
$valueon_changeNew field value
$rowTable on_row_clickRow data
$indexList item eventsItem index
$itemList item eventsItem data
$responsecall_api on_successAPI response
$errorcall_api on_errorError object
$pageon_page_changePage number

Example

json
{
  "type": "Table",
  "dataSource": "state:items",
  "events": {
    "on_row_click": [
      { "type": "update_state", "path": "selectedId", "value": "{{$row.id}}" },
      { "type": "navigate", "to": "/items/{{$row.id}}" }
    ]
  }
}

Error Handling

With call_api

json
{
  "type": "call_api",
  "api": "saveData",
  "on_success": [
    { "type": "show_toast", "message": "Saved!", "level": "success" }
  ],
  "on_error": [
    { "type": "show_toast", "message": "Error: {{$error.message}}", "level": "error" }
  ]
}

Fallback Pattern

json
{
  "type": "call_api",
  "api": "primaryApi",
  "on_error": [
    {
      "type": "call_api",
      "api": "fallbackApi",
      "on_error": [
        { "type": "show_toast", "message": "All APIs failed", "level": "error" }
      ]
    }
  ]
}

Conditional Actions

Execute actions based on conditions:

json
{
  "type": "conditional",
  "condition": "{{state.isValid}}",
  "then": [
    { "type": "call_api", "api": "submit" }
  ],
  "else": [
    { "type": "show_toast", "message": "Please fix errors", "level": "warning" }
  ]
}

Common Patterns

Loading State

json
[
  { "type": "set_loading", "loading": true },
  {
    "type": "call_api",
    "api": "fetchData",
    "on_success": [
      { "type": "update_state", "path": "data", "value": "$response.data" }
    ],
    "finally": [
      { "type": "set_loading", "loading": false }
    ]
  }
]

Optimistic Update

json
[
  { "type": "update_state", "path": "items", "value": "{{state.items.filter(i => i.id !== $itemId)}}" },
  {
    "type": "call_api",
    "api": "deleteItem",
    "on_error": [
      { "type": "call_api", "api": "getItems" },
      { "type": "show_toast", "message": "Failed to delete", "level": "error" }
    ]
  }
]

Form Submission

json
[
  { "type": "validate_form", "form": "myForm" },
  {
    "type": "conditional",
    "condition": "{{state.$formValid}}",
    "then": [
      { "type": "set_loading", "loading": true },
      {
        "type": "call_api",
        "api": "submitForm",
        "args": "{{state.formData}}",
        "on_success": [
          { "type": "show_toast", "message": "Submitted!", "level": "success" },
          { "type": "reset_form", "form": "myForm" },
          { "type": "navigate", "to": "/success" }
        ]
      },
      { "type": "set_loading", "loading": false }
    ]
  }
]

Next Steps

Explore each action type in detail: