Skip to main content

slice

@rotorsoft/act-root


@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:214

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โ€‹