Overview
The Messaging Service provides a type-safe mechanism for sending and receiving messages across different components of the application. It supports both legacy string-based commands and modern type-safe command definitions.MessageSender
The abstract base class for sending messages throughout the application.Interface
Methods
send() (Type-Safe)
commandDefinition(CommandDefinition<T>): The command definition that specifies the message type and payload structurepayload(T): The message payload, which must match the type defined in the command definition
void
Example:
send() (Legacy)
command(string): The command identifierpayload(Record<string, unknown>, optional): The message payload
void
Example:
Consider using CommandDefinition instead of string-based commands to get compilation errors when defining an incompatible payload.
Static Methods
combine()
messageSenders(...MessageSender[]): The message senders to combine
MessageSender - A composite message sender
Example:
Static Properties
EMPTY
MessageListener
A class for listening to messages coming through the application.Interface
Constructor
messageStream(Observable<Message<Record<string, unknown>>>): The underlying observable stream of messages
Properties
allMessages$
Methods
messages$<T>()
commandDefinition(CommandDefinition<T>): The command definition to filter for
Observable<T> - Stream of messages matching the command definition
Example:
Static Properties
EMPTY
Types
CommandDefinition
command(string): The command identifier
Message
Usage Examples
Type-Safe Messaging
Legacy String-Based Messaging
Combining Message Senders
Using Empty Implementations
Best Practices
Consider NOT using messaging at all if you can. State Providers offer an observable stream of data that is persisted. This can serve use cases that might have previously used messages to notify of settings changes or vault data changes, and those observables should be preferred over messaging.
When to Use Messaging
- Cross-component event notifications that don’t require persistence
- Triggering actions in response to user events
- Broadcasting system-wide state changes
When NOT to Use Messaging
- Persisting data (use State Providers instead)
- Notifying about data changes (use State Provider observables)
- Sharing configuration (use State Providers)