The type of the MediatorContext that extends MediatorContext.
The type of the event names that extends string. Defaults to string.
The initial context for the Mediator.
Optional options: MediatorOptions<Context, EventName>Optional configuration including middlewares.
A Mediator instance with the specified context type and event names.
createMediator
type MyEvents = 'item:added' | 'item:removed'
interface MyContext extends MediatorContext {
items: number[]
}
// Basic usage
const myMediator = createMediator<MyContext, MyEvents>(initialContext)
// With middlewares
const myMediator = createMediator<MyContext, MyEvents>(initialContext, {
middlewares: [
{ event: '*', handler: logger },
{ event: 'item:added', handler: validator }
]
})
Creates a Mediator instance with a specific initial context and optional middleware configuration.