Skip to content
← Back to Index

triggerHook

json
{ text -> value } triggerHook (
  hook: text
): [{ text -> value }]

The triggerHook filter triggers a secondary Rule evaluation with the given data and hook name. All rules whose param input type matches the constructed hook input are evaluated, and their effects are returned as an iterator.

This enables apps to define custom hook points that other rules can listen to.

For full documentation, see Custom Hooks - triggerHook.

Availability

DiscountRuleReactor

Input

Any record value. The runtime adds a hook field with the hook name before evaluating rules:

filtrera
// What you write:
{ orderId = '...' } triggerHook 'OnOrderValidated'

// What rules receive:
{ hook = 'OnOrderValidated', orderId = '...' }

Return Value

An iterator of records — the effects emitted by all matching rules. Returns an empty iterator when called inside a secondary evaluation (recursion prevention).

Recursion Prevention

triggerHook is single-level only. If a rule triggered by triggerHook calls triggerHook itself, it immediately returns []. This prevents infinite loops.

Examples

In Rules

Effects returned by triggerHook can be forwarded, filtered, or batched by the calling rule:

filtrera
param input: OnOrderCreated

let hookEffects = { orderId = input.order.orderId } triggerHook 'OnOrderValidated'

// Forward only validation errors
from hookEffects where is { effect: 'validationError' }

In Reactors (Ingresses / Jobs)

In the reactor runtime, returned effects are not automatically processed. The caller must apply them explicitly:

filtrera
import 'iterators'

let hookEffects = { cartId = cartId, cart = cart } triggerHook 'OnCartMutation'
let effects = hookEffects buffer

let commandEffects = effects where is { effect: 'ticketCommand' } buffer
from commandEffects count > 0 match
  true |>
    from messageActor ('ticket', cartId, [{
      type = 'applyCommands'
      body = {
        commands = commandEffects
          select e => { type = e.type, fields = e.fields }
          as `list`
      }
    }])

See Also

© 2024 Hantera AB. All rights reserved.