ActBuilder
@rotorsoft/act-root / act/src / ActBuilder
Type Alias: ActBuilder<S, E, A>
ActBuilder<
S
,E
,A
> =object
Defined in: libs/act/src/act-builder.ts:42
Fluent builder for composing event-sourced state machines with actions and reactions.
Provides a chainable API for registering states, events, and reaction handlers, enabling you to declaratively build complex, reactive applications.
Example
const app = act()
.with(Counter)
.on("Incremented").do(async (event) => { ... })
.to(() => "OtherStream")
.build();
Type Parameters
S
S
extends SchemaRegister
<A
>
SchemaRegister for state
E
E
extends Schemas
Schemas for events
A
A
extends Schemas
Schemas for actions
Properties
build()
build: (
drainLimit?
) =>Act
<S
,E
,A
>
Defined in: libs/act/src/act-builder.ts:99
Build the application and return an Act orchestrator.
Parameters
drainLimit?
number
(Optional) The maximum number of events to drain per cycle (default: 10)
Returns
Act
<S
, E
, A
>
The Act orchestrator instance
events
readonly
events:EventRegister
<E
>
Defined in: libs/act/src/act-builder.ts:103
The registered event schemas and reaction maps.
on()
on: <
K
>(event
) =>object
Defined in: libs/act/src/act-builder.ts:66
Register a reaction handler for a given event.
Type Parameters
K
K
extends keyof E
The event name
Parameters
event
K
The event to react to
Returns
An object with .do(handler) to register the handler
do()
do: (
handler
,options?
) =>ActBuilder
<S
,E
,A
> &object
Register a reaction handler for the event.
Parameters
handler
ReactionHandler
<E
, K
>
The reaction handler function
options?
Partial
<ReactionOptions
>
(Optional) Reaction options (retries, blocking, etc.)
Returns
The builder (for chaining), with .to(resolver) and .void() for advanced routing
with()
with: <
SX
,EX
,AX
>(state
) =>ActBuilder
<S
&{ [K in keyof AX]: SX }
,E
&EX
,A
&AX
>
Defined in: libs/act/src/act-builder.ts:56
Register a state machine with the builder.
Type Parameters
SX
SX
extends Schema
The type of state
EX
EX
extends Schemas
The type of events
AX
AX
extends Schemas
The type of actions
Parameters
state
State
<SX
, EX
, AX
>
The state machine to add
Returns
ActBuilder
<S
& { [K in keyof AX]: SX }
, E
& EX
, A
& AX
>
The builder (for chaining)