ActionBuilder
@rotorsoft/act-root / act/src / ActionBuilder
Type Alias: ActionBuilder<S, E, A>
ActionBuilder<
S,E,A> =object
Defined in: libs/act/src/state-builder.ts:47
Type Parameters
S
S extends Schema
E
E extends Schemas
A
A extends Schemas
Properties
build()
build: () =>
State<S,E,A>
Defined in: libs/act/src/state-builder.ts:96
Finalize and build the state machine definition.
Returns
State<S, E, A>
The strongly-typed State definition
on()
on: <
K,AX>(action,schema) =>object
Defined in: libs/act/src/state-builder.ts:58
Define an action for the state machine.
Type Parameters
K
K extends string
AX
AX extends Schema
Parameters
action
K
The action name
schema
ZodType<AX>
The Zod schema for the action payload
Returns
An object with .given() and .emit() for further configuration
emit()
emit: (
handler) =>ActionBuilder<S,E,A&{ [P in K]: AX }>
Finalize the action by providing the event emission handler.
Parameters
handler
ActionHandler<S, E, { [P in K]: AX }, K>
The action handler function
Returns
ActionBuilder<S, E, A & { [P in K]: AX }>
The ActionBuilder for chaining
given()
given: (
rules) =>object
Constrain the action with invariants (business rules).
Parameters
rules
Invariant<S>[]
Array of invariants
Returns
An object with .emit() to finalize the action
emit()
emit: (
handler) =>ActionBuilder<S,E,A&{ [P in K]: AX }>
Finalize the action by providing the event emission handler.
Parameters
handler
ActionHandler<S, E, { [P in K]: AX }, K>
The action handler function
Returns
ActionBuilder<S, E, A & { [P in K]: AX }>
The ActionBuilder for chaining
snap()
snap: (
snap) =>ActionBuilder<S,E,A>
Defined in: libs/act/src/state-builder.ts:91
Define a snapshotting strategy to reduce recomputations.
Parameters
snap
(snapshot) => boolean
Function that determines when to snapshot
Returns
ActionBuilder<S, E, A>
The ActionBuilder for chaining