Provides a lightweight publish-subscribe mechanism for sibling Lightning web components to communicate without direct references.
For Use In
Lightning Experience, Experience Builder Sites
Share data and pass messages between components that don’t have a parent-child relationship using the lightning/omnistudioPubsub module. Using this module, you can register, unregister, and fire events dynamically.
To use Omnistudio PubSub directly in your custom Lightning web component, use the lightning/omnistudioPubsub module.
The lightning/omnistudioPubsub module is a wrapper for the Omnistudio PubSub property.
To use the pubsub functionality, import pubsub from the lightning/omnistudioPubsub module in the component.
1import pubsub from "lightning/omnistudioPubsub";23// Register a callback4pubsub.register("eventName", callbackObject);56// Fire an event7pubsub.fire("eventName", action, payload);89// Unregister a callback10pubsub.unregister("eventName", callbackObject);
This utility component doesn’t have a template and can’t be directly accessed via Lightning App Builder. A custom component that uses the utility component can be accessed via Lightning App Builder. To make your component available in Lightning App Builder, see Configure a Component for Lightning App Builder. To make your component available in Experience Builder, see Configure a Component for Experience Builder.
This example uses the lightning/omnistudioPubsub module to register, unregister, and fire a test event dynamically.
Register a set of event handlers to a specific channel.
Parameter
Type
Description
eventName
string
The name of the event to register for
callbackobj
object
The callback object to register
unregister(eventName, callbackobj)
Unregister your set of event handlers from a channel. To avoid memory leaks or potential errors, always unregister event handlers when a component is disposed or disconnected. In addition, to properly unregister event handlers, pass both the channel name and instance of your event handler objects.
Parameter
Type
Description
eventName
string
The name of the event to unregister from
callbackobj
object
The callback object to unregister
fire(eventName, action, payload)
Fire an event over a specific channel to all registered handlers. The payload can be any object. However, make sure your handlers expect that particular structure. For example, if you intend to send a JSON object with various keys, your handlers should know what those keys are.
Parameter
Type
Description
eventName
string
The name of the event to fire
action
string
The action to perform
payload
object
The payload data for the event
Attributes
Name
Description
Type
Default
Required
direction
Text direction.
string
'ltr'
display
String translated label to identify if we need to display as button.
string
inline-label
Label when displayed as button.
string
'DefaultLabel'
inline-variant
Button variant when displayed as button.
string
'brand'
language
Language in which the omniscript was created.
string
'English'
lwr
Determines which component to use for rendering. When true, uses runtime_omnistudio-generated-omniscript-lwr for LWR compatibility. When false or not provided, uses the standard runtime_omnistudio-generated-omniscript.
boolean
false
offline
Whether this omniscript should use the offline renderer. When true, delegates to runtime_omnistudio_offline-offline-renderer which is suported runtime for offline usage