import { Subject } from "rxjs"; import { getCommand } from "./helpers"; import { MessageSender } from "./message.sender"; import { CommandDefinition, Message } from "./types"; export class SubjectMessageSender implements MessageSender { constructor(private readonly messagesSubject: Subject>>) {} send>( commandDefinition: string | CommandDefinition, payload: Record | T = {}, ): void { const command = getCommand(commandDefinition); this.messagesSubject.next(Object.assign(payload ?? {}, { command: command })); } }