State
Defining the state
import { WorkflowState } from '@node-ts/bus-core'
export class FulfilmentWorkflowState extends WorkflowState {
static NAME = 'FulfilmentWorkflowState'
$name = FulfilmentWorkflowState.NAME
// Set of user-defined state properties
itemId: string
customerId: string
status: 'posting-item' | 'sending-receipt' | 'complete'
}Accessing the state
import { Workflow } from '@node-ts/bus-core'
export class FulfilmentWorkflow extends Workflow<FulfilmentWorkflowState> {
configureWorkflow (
mapper: WorkflowMapper<FulfilmentWorkflowState, FulfilmentWorkflow>
): void {
mapper
.withState(FulfilmentWorkflowState)
// ...
.when(ItemShipped, 'emailReceipt')
}
// Workflow state is passed in as the second parameter to a workflow handler
async emailReceipt (_: ItemShipped, state: FulfilmentWorkflowState) {
// ...
}
}Updating the state
Discarding state
Last updated