Function createMediator

  • Creates a Mediator instance with a specific initial context and optional middleware configuration.

    Type Parameters

    • Context extends JSONObject

      The type of the MediatorContext that extends MediatorContext.

    • EventName extends string = string

      The type of the event names that extends string. Defaults to string.

    Parameters

    Returns Mediator<Context, EventName>

    A Mediator instance with the specified context type and event names.

    Function

    createMediator

    Example

    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 }
    ]
    })