TriggerBuilder
The builder returned by createTrigger<S>() (called with no arguments).
Accumulates configuration through chainable methods and finalizes with
.handle(handler). The handler sees conditions.<key> as NonNullable<...>
for every key passed to .require(...) — no !, no early-return narrowing.
Import
Section titled “Import”The chainable createTrigger<S>() form lives in the @triggery/core/builder subpath (v0.10+) so apps that only use the imperative createTrigger({...}) form don’t pay for the ~250 B gz builder machinery in their main bundle. The TriggerBuilder<S, R> type is exported from the main @triggery/core for ergonomic type references.
Signature
Section titled “Signature”The type parameter R carries the union of required condition keys accumulated by .require(...). It’s threaded into TriggerHandler<S, R>, which narrows the handler’s conditions.<key> accordingly.
Methods
Section titled “Methods”| Method | Required | Description |
|---|---|---|
.id(string) | yes | Unique trigger id within the runtime. Must be a string literal. |
.events([...]) | yes | Event names from S['events'] this trigger reacts to. |
.conditions({...}) | no | Initial values for conditions held by this trigger. Same shape as the conditions: field on the imperative config. |
.require(...keys) | no | Add condition keys to the required set. Narrows conditions.<key> to NonNullable<...> inside .handle(...). Multiple .require(...) calls accumulate. |
.schedule(strategy) | no | Override the scheduler — 'microtask' (default) or 'sync'. |
.concurrency(strategy) | no | Override concurrency — 'take-latest' (default), 'take-every', 'take-first', 'queue', 'exhaust', 'sync'. |
.scope(string) | no | Set the scope id (for <TriggerScope id="…"> isolation). |
.handle(handler) | yes | Finalize and register the trigger. Returns Trigger<S>. Throws if .id or .events were not called. |
The chained order does not affect behaviour — .handle(...) validates that id and events are set.
Example
Section titled “Example”conditions.user and conditions.settings are NonNullable<...> inside .handle(...) — no !, no if (!conditions.user) return; guards.
Comparison: builder vs imperative
Section titled “Comparison: builder vs imperative”Both forms compile to the same Trigger<S> and use the same internal hot path — pick whichever reads better in your codebase.
The ESLint rule prefer-builder-trigger (enabled as warn in the strict preset) flags the imperative form when it carries required: [...].