Skip to main content

DSL Overview

The fluent builder API for defining sagas.

Creating a Saga​

import { createSagaMachine } from '@saga-bus/core';

const saga = createSagaMachine<MyState, MyMessages>()
.name('MySaga')
.correlate('StartEvent', msg => msg.id, { canStart: true })
.initial<StartEvent>(msg => ({ /* initial state */ }))
.on('SomeEvent').handle(async (msg, state, ctx) => state)
.build();

Builder Chain​

Type Parameters​

createSagaMachine<TState, TMessages>()
  • TState - Your saga state interface (must extend SagaState)
  • TMessages - Union of all message types

Sections​