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:
// registering pub-sub event
this.callbackEventHandler = {
result: this.callbackFunction.bind(this)
};
callbackFunction(data) {/* callback triggered by the pubsub event */}
this.digitalCommerceSDK.register("event-name",this.callbackEventHandler);
Firing an Event
Use the following example fire method to publish the occurrence of an event:
this.digitalCommerceSDK.fire("event-name",action,payloadObject);
Unregistering an Event
Use the following example unregister method to cancel subscription of an event:
// un-registering pub-sub event
this.digitalCommerceSDK.unregister("event-name",this.callbackEventHandler);