Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 2 #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Version 2 #1

wants to merge 5 commits into from

Conversation

XanderEmu
Copy link
Contributor

No description provided.

Copy link

@czuba-artur czuba-artur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review was done without starting an IDE, so some comments you can ignore if I was wrong


export abstract class BaseMessageBus implements MessageBus {
protected handlersMap: HandlersMap = {};
protected middlewareList: MessageBusMiddleware<any>[] = [];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Middlewares should match some interface. It can be a single functions where message is passed or classes with ex. handle function which accepts message as a parameter. For now if middleware class will not have a handle method handle will throw an error about calling undefined function.

if (isMessageHandlerObject(args[0])) {
handler = args[0];
type = handler.getSupportedType();
} else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe else if? Here you can check if args[0] is a message.

? args[0].type
: args[0];
handler = args[1];
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can have an else statement and throw an error inside if type is not a string, or is empty. This will make this code more readable.

}

if (!isMessageHandler(handler)) {
throw new Error('handler must be a function or an object of type MessageHandlerObject');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unify error messages. Handler must be.... Capital letters

import {isMessageHandlerObject} from './TypeCheckers/isMessageHandlerObject';

export abstract class BaseMessageBus implements MessageBus {
protected handlersMap: HandlersMap = {};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can use a Map here? It will add more typing to this class.

await middleware.handle(message);
}

if (!this.handlersMap[type]) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use a Map class in handlersMap you can assign handlers to const and check this condition.

): [string, MessageHandler<P>] {
const [type, handler] = this.getTypeAndHandlerFromArgs([arg1, arg2]);
if (this.handlersMap[type]) {
throw new Error('There can be only one handler per type in CommandBus');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? I cannot handle the same message types in more than one place?

const message2: Message<{lorem: string}> = {type: 'bar', payload: {lorem: 'ipsum'}};

class TestMessage implements Message<{dolor: string}> {
readonly type: string;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type can be initialized here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants