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:
17
libs/messaging-internal/src/subject-message.sender.ts
Normal file
17
libs/messaging-internal/src/subject-message.sender.ts
Normal 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 }));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user