Setting Up the Pubsub SDK (Winter ‘20)

The Vlocity Digital Commerce SDK includes the pubsub SDK, which supports communication between Digital Commerce components, including Digital Commerce Lightning Web Components, Digital Commerce Web Components, JavaScript-based framework, and so on. For more details, see the PubSub SDK reference.

Registering an Event 

Use the following example Digital Commerce pubsub register method to add a callback function to the list of subscribers for a particular event:

1// registering pub-sub event
2this.callbackEventHandler = {
3      result: this.callbackFunction.bind(this)
4};
5callbackFunction(data) {/* callback triggered by the pubsub event */}
6this.digitalCommerceSDK.register("event-name",this.callbackEventHandler);

Firing an Event 

Use the following example fire method to publish the occurrence of an event:

1this.digitalCommerceSDK.fire("event-name",action,payloadObject);

Unregistering an Event 

Use the following example unregister method to cancel subscription of an event:

1// un-registering pub-sub event
2this.digitalCommerceSDK.unregister("event-name",this.callbackEventHandler);