HandlingMixin

Hierarchy

Index

Constructors

Methods

Constructors

constructor

+ new HandlingMixin(): HandlingMixin

Creates an instance of HandlingMixin. Creates an instance of HandlingMixin.

Returns: HandlingMixin

Methods

ensureHandleability

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

Ensures that provided type can be handled by verifying it against handleable types.

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

Parameters:

NameTypeDescription
messageTypeMessageTypeMessageType implementing MessageableType interface.
handleableTypes?MessageTypeMessage› | MessageTypeMessage›[]Optional handleable types to be verified against on runtime.

Returns: boolean

Returns true if type is handleable, else false.


getHandleableTypes

getHandleableTypes(): MessageTypeMessage›[]

Returns handleable message types.

Returns: MessageTypeMessage›[]

Returns handleable message types as a list with message types.


getHandled

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

Returns all message types that matches evaluated one by equal constructor or subclassing.

Parameters:

NameTypeDescription
messageTypeMessageTypeMessageType implementing MessageableType interface.

Returns: MessageTypeMessage›[]

List of all handled types matching evaluated one.


getHandledCommands

getHandledCommands(): MessageTypeCommand›[]

Returns all commands that can be handled.

Returns: MessageTypeCommand›[]

List of all handled types matching Command.


getHandledEvents

getHandledEvents(): MessageTypeEvent›[]

Returns all commands that can be handled.

Returns: MessageTypeEvent›[]

List of all handled types matching Event.


getHandledMessages

getHandledMessages(): MessageTypeMessage›[]

Returns all messages that can be handled.

Returns: MessageTypeMessage›[]

List of all handled types matching Message.


getHandledTypes

getHandledTypes(): MessageTypeMessage›[]

Returns all handled message types.

Returns: MessageTypeMessage›[]

List of all handled message types.


getHandledTypesNames

getHandledTypesNames(): TypeName[]

Returns all type names that can be handled.

Returns: TypeName[]

List of all handled type names


getHandlers

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

Returns all available handler mappings.

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

Returns mappings of all available handlers by message type: handler(s) relation.


handles

handles(): Map‹MessageTypeCommand›, Handler

Returns all handled Command mappings.

example

class MyController extends HandlingMixin {
initialize(): void {
this.setupHandlers({
handlers: this.handles(),
});
}
// ...
MyCommandHandlerMethod(@handle command: MyCommand): boolean {
return command.key === 'my-string';
}
}
const controller = new MyController();
controller.registerHandler = sinon.stub();
controller.initialize();
expect(controller.registerHandler).to.be.calledOnce;
expect(controller.registerHandler).to.be.calledWithExactly(
MyCommand,
controller.MyCommandHandlerMethod
);

Returns: Map‹MessageTypeCommand›, Handler

Returns all handled Command(s) defined with @handle annotation or allows developer to define manually handlers.


hasHandler

hasHandler(messageType: MessageTypeMessage›): boolean

Evaluates if handler for message type is registered.

Parameters:

NameTypeDescription
messageTypeMessageTypeMessageType implementing MessageableType interface.

Returns: boolean

Returns true if handler for message type is registered, else false.


isHandleabe

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

Evaluates if type can be handled.

Parameters:

NameTypeDescription
messageTypeMessageTypeMessageType implementing MessageableType interface.
handleableTypes?MessageTypeMessage› | MessageTypeMessage›[]Optional handleable types to be verified against on runtime.

Returns: boolean

Returns true if message type can be handled, else false.


overrideHandler

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

Overrides already existing handler for message type.

Parameters:

NameTypeDescription
messageTypeMessageTypeMessageType implementing MessageableType interface.
handlerHandlerHandler function that will executed upon handling message type.

Returns: void


registerHandler

registerHandler(_messageType: MessageTypeMessage›, _handler: Handler, _shouldOverride?: boolean): void

[!] Placeholder for registering handler for message type.

Parameters:

NameType
_messageTypeMessageTypeMessage
_handlerHandler
_shouldOverride?boolean

Returns: void


removeHandler

removeHandler(messageType: MessageTypeMessage›): void

Removes handler by type.

Parameters:

NameTypeDescription
messageTypeMessageTypeMessageType implementing MessageableType interface.

Returns: void


setHandleableTypes

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

Sets the only allowed handleable message types.

Parameters:

NameTypeDescription
handleableTypesMessageTypeMessage› | MessageTypeMessage›[]List of allowed types for handling.

Returns: void


subscribes

subscribes(): Map‹MessageTypeEvent›, Handler

Returns all handled Event mappings.

example

class MyController extends HandlingMixin {
initialize(): void {
this.setupHandlers({
handlers: this.subscribes(),
});
}
// ...
MyEventHandlerMethod(@subscribe event: MyEvent): boolean {
return event.key === 'my-string';
}
}
const controller = new MyController();
controller.registerHandler = sinon.stub();
controller.initialize();
expect(controller.registerHandler).to.be.calledOnce;
expect(controller.registerHandler).to.be.calledWithExactly(
MyEvent,
controller.MyEventHandlerMethod
);

Returns: Map‹MessageTypeEvent›, Handler

Returns all handled Events(s) defined with @subscribe annotation or allows developer to define manually handlers.