npm-packages/components/triggers/README.md
This is a component built for build-on-components-day.
Run code whenever a table changes.
Example usages:
Copy installation pattern from convex/triggers.ts.
Copy usage pattern from convex/messages.ts.
Each triggered function runs within the same mutation, immediately after the
document write. If you want async triggers, you can use
ctx.scheduler.runAfter(0, ...);
All of your functions that modify the table must be wrapped in
mutationWithTriggers instead of mutation, in order to trigger the triggers.
Triggers do not run when the table changes through a plain mutation or through
the Convex Dashboard.
Triggers are called with arguments matching triggerArgsValidator, so you know
whether it was an insert, patch, replace, or delete. You are also given the
document ID and the full document contents before and after the write.
The usage of components allows the oldDoc and newDoc to be computed
atomically, unlike the DatabaseWriter wrapper from the Row Level Security
helpers.