Understand the
PubSub
library
The PubSub
library is a publishing and subscription system
based on jQuery.Callbacks
functions.
With the PubSub
library, messages can be published by any object in the system when events happen and subscribers can listen for those messages and perform additional tasks as needed. The backbone of the PubSub
library is a list of topics identified by ID
, for example, PAGE_READY
and CART_ADD
. Publishers (which are typically Commerce widgets) publish messages to these topics when events happen. Subscribers to a given topic receive the messages published to that topic along with supporting data.
You can create custom topics and add them to the PubSub
library;
however, these custom topics may only be used by custom widgets that you build.
Out-of-the-box widgets will not have awareness of or access to custom
PubSub
topics.