mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 09:43:23 +00:00
18 lines
609 B
TypeScript
18 lines
609 B
TypeScript
import { Subject } from "rxjs";
|
|
|
|
import { CommandDefinition, Message, MessageSender } from "@bitwarden/messaging";
|
|
|
|
import { getCommand } from "./helpers";
|
|
|
|
export class SubjectMessageSender implements MessageSender {
|
|
constructor(private readonly messagesSubject: Subject<Message<Record<string, unknown>>>) {}
|
|
|
|
send<T extends Record<string, unknown>>(
|
|
commandDefinition: string | CommandDefinition<T>,
|
|
payload: Record<string, unknown> | T = {},
|
|
): void {
|
|
const command = getCommand(commandDefinition);
|
|
this.messagesSubject.next(Object.assign(payload ?? {}, { command: command }));
|
|
}
|
|
}
|