OneToOneHandlingMixin

Hierarchy

Implements

Index

Constructors

Methods

Constructors

constructor

+ new OneToOneHandlingMixin(): OneToOneHandlingMixin

Inherited from HandlingMixin.constructor

Overrides void

Returns: OneToOneHandlingMixin

Methods

ensureHandleability

ensureHandleability(messageType: MessageTypeMessage›, handleableTypes?: MessageTypeMessage› | MessageTypeMessage›[]): boolean

Implementation of Controller

Inherited from HandlingMixin.ensureHandleability

Overrides CancelingEmployment.ensureHandleability

Parameters:

NameType
messageTypeMessageTypeMessage
handleableTypes?MessageTypeMessage› | MessageTypeMessage›[]

Returns: boolean


getHandleableTypes

getHandleableTypes(): MessageTypeMessage›[]

Implementation of Controller

Inherited from HandlingMixin.getHandleableTypes

Overrides CancelingEmployment.getHandleableTypes

Returns: MessageTypeMessage›[]


getHandled

getHandled(messageType: MessageTypeMessage›): MessageTypeMessage›[]

Implementation of Controller

Inherited from HandlingMixin.getHandled

Overrides CancelingEmployment.getHandled

Parameters:

NameType
messageTypeMessageTypeMessage

Returns: MessageTypeMessage›[]


getHandledCommands

getHandledCommands(): MessageTypeCommand›[]

Inherited from HandlingMixin.getHandledCommands

Overrides CancelingEmployment.getHandledCommands

Returns: MessageTypeCommand›[]


getHandledEvents

getHandledEvents(): MessageTypeEvent›[]

Inherited from HandlingMixin.getHandledEvents

Overrides CancelingEmployment.getHandledEvents

Returns: MessageTypeEvent›[]


getHandledMessages

getHandledMessages(): MessageTypeMessage›[]

Inherited from HandlingMixin.getHandledMessages

Overrides CancelingEmployment.getHandledMessages

Returns: MessageTypeMessage›[]


getHandledTypes

getHandledTypes(): MessageTypeMessage›[]

Implementation of Controller

Inherited from HandlingMixin.getHandledTypes

Overrides CancelingEmployment.getHandledTypes

Returns: MessageTypeMessage›[]


getHandledTypesNames

getHandledTypesNames(): TypeName[]

Inherited from HandlingMixin.getHandledTypesNames

Overrides CancelingEmployment.getHandledTypesNames

Returns: TypeName[]


getHandler

getHandler(messageType: MessageTypeMessage›): Handler | undefined

Implementation of Controller

Returns handler for message type.

throws {InvalidMessageableType} Thrown if the message type argument is not implementing Messageable interface.

Parameters:

NameTypeDescription
messageTypeMessageTypeMessageType implementing MessageableType interface.

Returns: Handler | undefined

Handler as a function if found, else undefined.


getHandlerOrThrow

getHandlerOrThrow(messageType: MessageTypeMessage›): Handler

Implementation of Controller

Return handler for message type or throws error if not found.

throws {HandlerNotFoundError} Thrown if handler for message type is not found.

Parameters:

NameTypeDescription
messageTypeMessageTypeMessageType implementing MessageableType interface.

Returns: Handler

Handler as a function if found, else throws.


getHandlers

getHandlers(): Map‹MessageTypeMessage›, Handler | Handler[]›

Implementation of Controller

Inherited from HandlingMixin.getHandlers

Overrides CancelingEmployment.getHandlers

Returns: Map‹MessageTypeMessage›, Handler | Handler[]›


getTypeByHandler

getTypeByHandler(handlerReference: Handler): any | undefined

Resolves message type by handler reference.

Parameters:

NameTypeDescription
handlerReferenceHandlerReference to handler function.

Returns: any | undefined

Message type if handler is matching one of handlers on class, else undefined.


handle

handle(message: Message): Promise‹any›

Handles message type instance.

async

throws {HandlerNotFoundError} Thrown if handler for type is not found.

Parameters:

NameTypeDescription
messageMessageType implementing Messageable interface.

Returns: Promise‹any›

Any value returned by successful or unsuccessful handling.


handles

handles(): Map‹MessageTypeCommand›, Handler

Implementation of Controller

Inherited from HandlingMixin.handles

Overrides CancelingEmployment.handles

Returns: Map‹MessageTypeCommand›, Handler


hasHandler

hasHandler(messageType: MessageTypeMessage›): boolean

Implementation of Controller

Inherited from HandlingMixin.hasHandler

Overrides CancelingEmployment.hasHandler

Parameters:

NameType
messageTypeMessageTypeMessage

Returns: boolean


initialize

initialize(): void

Implementation of Controller

Initializes OneToOneHandlingMixin.

remarks By defining handler mappings on metadata with annotations: @handle, @subscribe and resolving those mapping with handles, subscribes method - it ensures, that there is no leakage in between inheriting classes.

Returns: void


isHandleabe

isHandleabe(messageType: MessageTypeMessage›, handleableTypes?: MessageTypeMessage› | MessageTypeMessage›[]): boolean

Inherited from HandlingMixin.isHandleabe

Overrides CancelingEmployment.isHandleabe

Parameters:

NameType
messageTypeMessageTypeMessage
handleableTypes?MessageTypeMessage› | MessageTypeMessage›[]

Returns: boolean


overrideHandler

overrideHandler(messageType: MessageTypeMessage›, handler: Handler): void

Implementation of Controller

Inherited from HandlingMixin.overrideHandler

Overrides CancelingEmployment.overrideHandler

Parameters:

NameType
messageTypeMessageTypeMessage
handlerHandler

Returns: void


registerHandler

registerHandler(messageType: MessageTypeMessage›, handler: Handler, shouldOverride?: boolean): void

Implementation of Controller

Overrides HandlingMixin.registerHandler

Registers handler for message type.

throws {UnhandleableTypeError} Thrown if the type argument is not one of handleable types.

throws {InvalidHandlerError} Thrown if the handler argument is not a function.

throws {HandlerExistError} Thrown if handler would overridden without explicit call.

example

@define('MyCommand')
class MyCommand extends Command<MyCommand> {
key: string;
}
define('MyOtherCommand')
class MyOtherCommand extends Command<MyOtherCommand> {
key: string;
}
class MyClass extends OneToOneHandlingMixin {
MyCommand(command: MyCommand): void {
// ...
}
@handles()
MyOtherCommand(command: MyOtherCommand): void {
// ...
}
}
const myClass = new MyClass();
// Defined externally or during construction
myClass.registerHandler(MyCommand, myClass.MyCommand);

Parameters:

NameTypeDescription
messageTypeMessageTypeMessageType implementing MessageableType interface.
handlerHandlerHandler function that will executed upon handling message type.
shouldOverride?booleanFlag indicating that handler should be overridden if exist.

Returns: void


removeHandler

removeHandler(messageType: MessageTypeMessage›): void

Implementation of Controller

Inherited from HandlingMixin.removeHandler

Overrides CancelingEmployment.removeHandler

Parameters:

NameType
messageTypeMessageTypeMessage

Returns: void


setHandleableTypes

setHandleableTypes(handleableTypes: MessageTypeMessage› | MessageTypeMessage›[]): void

Implementation of Controller

Inherited from HandlingMixin.setHandleableTypes

Overrides CancelingEmployment.setHandleableTypes

Parameters:

NameType
handleableTypesMessageTypeMessage› | MessageTypeMessage›[]

Returns: void


subscribes

subscribes(): Map‹MessageTypeEvent›, Handler

Implementation of Controller

Inherited from HandlingMixin.subscribes

Overrides CancelingEmployment.subscribes

Returns: Map‹MessageTypeEvent›, Handler