slice
@rotorsoft/act-root / act/src / slice
Function: slice()
slice<
TSchemaReg,TEvents,TActions,TStateMap,TActor>():SliceBuilder<TSchemaReg,TEvents,TActions,TStateMap,TActor>
Defined in: libs/act/src/builders/slice-builder.ts:172
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; }>
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, {});
})
.to("counter-target")
.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