1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-19 01:33:33 +00:00

Add messaging & messaging-internal libraries (#15711)

This commit is contained in:
Justin Baur
2025-07-22 11:47:25 -04:00
committed by GitHub
parent e99abb49ec
commit a563e6d910
39 changed files with 347 additions and 105 deletions

View File

@@ -0,0 +1,17 @@
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 }));
}
}