Tide · Triggers and selection

Trigger condition (when)

when is a condition on a reflex that a fact triggers: a template evaluated against that fact. The reflex runs only if the result is truthy. A fact that fails the condition creates no run, and the host receives a fact.unmatched event with the reason.

Reflex
{
  id: 'billing.receipt',
  intent: 'Send a receipt when a charge goes through.',
  on: { fact: { entity: 'charges', op: 'insert' } },
  effect: {
    name: 'mail.send',
    input: { to: { $ref: '$.row.member' }, kind: 'receipt' },
  },
  when: { $eq: [{ $ref: '$.fact.row.status' }, 'succeeded'] },
}
Rows written to charges
[
  { member: 'ada', status: 'declined' },
  { member: 'alan', status: 'succeeded' },
]
Mail sent and unmatched events
{
  mailed: [{ to: 'alan', kind: 'receipt' }],
  unmatched: [
    {
      row: { member: 'ada', status: 'declined' },
      reason: '`when` did not match',
    },
  ],
}
Output matches the expected value

Runs in this page on the installed package. The input and the expected output are defined by the example.