Tide · Triggers and selection

Write trigger (on.fact)

A write trigger (on.fact with an entity) fires a reflex on a write to a table: any write, or only one op. The host reports each write with ingest, and the fact carries the row. A reflex with no select runs for that row, which a template reads as $.row.

Reflex
{
  id: 'booking.cancelled',
  intent: 'Confirm a cancellation to the member who cancelled.',
  on: { fact: { entity: 'bookings', op: 'delete' } },
  effect: {
    name: 'mail.send',
    input: {
      to: { $ref: '$.row.member' },
      cancelled: { $ref: '$.row.id' },
    },
  },
}
Ingested writes to bookings
[
  { op: 'insert', row: { id: 'B-2045', member: 'mia' } },
  { op: 'update', row: { id: 'B-2042', member: 'linus' } },
  { op: 'delete', row: { id: 'B-2039', member: 'ruth' } },
]
Mail sent
[{ to: 'ruth', cancelled: 'B-2039' }]
Output matches the expected value

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