Tide · Triggers and selectionTrigger condition (
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.
{
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'] },
}[
{ member: 'ada', status: 'declined' },
{ member: 'alan', status: 'succeeded' },
]{
mailed: [{ to: 'alan', kind: 'receipt' }],
unmatched: [
{
row: { member: 'ada', status: 'declined' },
reason: '`when` did not match',
},
],
}Runs in this page on the installed package. The input and the expected output are defined by the example.