Skip to content

Reactor Component Structure

Reactor components are typically defined as .hrc files and provide imperative backend logic within an app.

Reactor components follow a common shape:

  1. Declare input parameters (param) to define what the ingress must provide.
  2. Transform incoming payloads into structured commands.
  3. Send the command set to an actor using messageActor.

They may also query graph state or read values from the registry as part of their logic. Reactor components do not persist state directly. Instead, they emit commands to actors, and the actors are responsible for validating and storing data in the graph.

Input parameters

Parameters define the component’s expected inputs. They can be primitives or nested structures.

filtrera
param debug: boolean = false
param order: { ... }
param secret: text

Building actor commands from the payload

Components do not persist state directly. Instead, they assemble the command objects required by an actor.

In Create Your first app, the component creates an order by sending a create message to the order actor. That create message contains the commands needed to build the order.

For example, order lines are created from the incoming cart items:

filtrera
let orderLineCommands =
  order.get.cart
  select cartItem =>
    let orderLineId = newid
    from [
      { type = 'createOrderLine' ... },
      { type = 'setOrderLineTax' ... }
    ]
  flatten

Dependency chain inside commands

Some commands depend on earlier state.

Order lines require a deliveryId, so delivery must be created first:

filtrera
let deliveryId = newid

let deliveryCommands =
  [[{ type = 'createDelivery', deliveryId = deliveryId }], deliveryAddressCommands]
  flatten

The final order message composes both command sets:

filtrera
commands = [deliveryCommands, orderLineCommands] flatten

For details on Filtrera syntax (match, flatten, select, etc.), see the Filtrera reference.

© 2024 Hantera AB. All rights reserved.