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
| Discount | Rule | Reactor |
|---|---|---|
| ✓ | ✓ |
Input
Any record value. The runtime adds a hook field with the hook name before evaluating rules:
// 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:
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:
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
- triggerHook — Custom Hooks — Full documentation
- Rule Effects — Available effect types
- Rule Hooks — Built-in lifecycle hooks