slice
@rotorsoft/act-root / act/src / slice
Function: slice()
slice<
TSchemaReg,TEvents,TActions,TStateMap,TActor>(states?,actions?,events?,projections?):SliceBuilder<TSchemaReg,TEvents,TActions,TStateMap,TActor>
Defined in: libs/act/src/slice-builder.ts:180
Creates a new slice builder for composing partial states with scoped reactions.
Slices enable vertical slice architecture by grouping related states and reactions into self-contained feature modules. Reactions defined in a slice are type-scoped to events from that slice's states only.
Type Parameters
TSchemaReg
TSchemaReg extends SchemaRegister<TActions> = { }
TEvents
TEvents extends Schemas = { }
TActions
TActions extends Schemas = { }
TStateMap
TStateMap extends Record<string, Schema> = { }
TActor
TActor extends Readonly<{[key: string]: unknown; id: string; name: string; }> = Readonly<{[key: string]: unknown; id: string; name: string; }>
Parameters
states?
Map<string, State<any, any, any>> = ...
actions?
Record<string, any> = {}
events?
EventRegister<TEvents> = ...
projections?
Projection<any>[] = []
Returns
SliceBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor>
Examples
const CounterSlice = slice()
.withState(Counter)
.on("Incremented")
.do(async (event, _stream, app) => {
await app.do("reset", target, {});
})
.void()
.build();
const CreationSlice = slice()
.withState(TicketCreation)
.withState(TicketOperations) // handler can dispatch AssignTicket
.on("TicketOpened").do(async (event, _stream, app) => {
await app.do("AssignTicket", target, payload, event);
})
.build();
See
- SliceBuilder for builder methods
- Slice for the output type