Process of registering, requesting handlers.
Things to consider:
- Registering the same name will overwrite the existing handler.
- Request is supposed to have an name property.
With <handler-name>
being the name we use to handle requests with, the <callback>
being the callback that will handle the request, TRequest
being the type of request and TRequestResponse
being the type of response, we register an handler like so:
mediator.register.handler<TRequest, TRequestResponse>(
handler-name: string,
callback: (request: TRequest) => TRequestResponse
);
Things to consider:
- The request needs to have a name property that corresponsds to the name of the handler.
With <request>
being the request object that is passed to handler, TRequest
being the type of request and TRequestResponse
being the type of response, we handle an request like so:
let response = mediator.handle<TRequest, TRequestResponse>(
request: TRequest
);