How Actions Work
This page explains the generic lifecycle of the actions package.
The forms package uses these primitives for form actions.
Lifecycle
- Build an
ActionRegistryfrom your action registrations. - Provide action configs to the dispatcher.
- Trigger execution with a trigger value and base context.
- The dispatcher resolves matching registrations.
- The dispatcher enriches the provided context with
config,triggerand a cancellationsignal. - Sequence entries run in order; actions in an inner array run concurrently and return identified results.
Registration Example
const registration = {
$type: 'log',
schema: LogActionSchema,
metadata: {
name: 'Log Action',
defaultTriggers: ['submit'],
},
execute: async (context) => {
console.log(context.trigger, context.config.message);
return { success: true };
},
};Trigger Matching
The dispatcher checks action configs in order.
- If the config has a
triggersarray, that list is used. - Otherwise the registration
metadata.defaultTriggersis used.
Context Enrichment
The key runtime behavior is this merge:
execute({
...context,
config: action,
trigger,
signal,
...(triggeredBy ? { triggeredBy } : {}),
});That is why actions usually read context.config and context.trigger directly.
Execution Order
Sequence entries run in array order, not registry registration order. Inner arrays run as parallel groups.
await dispatcher.dispatch({
actions: [
{ id: 'a', $type: 'log', message: 'first' },
{ id: 'b', $type: 'log', message: 'second' },
],
trigger: 'submit',
context,
});Control Flow
An action result can stop the chain:
return {
success: false,
error: 'Stop here',
shouldContinue: false,
};Form Integration
Form action handlers receive a context with formData, errors, form state, and controller methods in addition to the action config and trigger. errors is keyed by dotted field path in both renderers, so a handler reads context.errors['address.street'].