Wix.PubSub

publish

Broadcasts an event to other Site components of a multicomponent app. If the app’s Site components span multiple pages, they will be notified when they are rendered.

SDK Version: SDK 1.25.0+
Editor Version: New Editor, Old Editor
Display: Live Site, Preview
Components: Widget, Pinned (aka Fixed-Position) Widget, Page, Modal, Popup

Note:
For the Worker component, use the Worker.PubSub.publish method instead.

Syntax:

Copy

Parameters:

NameTypeDescription
eventName (required)StringThe name of the event to publish
data (required)ObjectThe object to send to subscribers for this event type
isPersistent (required)BooleanIndicates whether this event is persisted for event subscribers who have not yet subscribed

Example:

Copy

subscribe

Subscribes to events from other site components of a multicomponent app. If the components span multiple pages, they will be notified once they are rendered. It is also possible to receive all notifications prior to rendering by specifying a flag when subscribing to events. If the flag is set, the component will be notified immediately of any prior events of the type it is registered to receive.

SDK Version: SDK 1.25.0+
Editor Version: New Editor, Old Editor
Display: Live Site, Preview
Components: Widget, Pinned (aka Fixed-Position) Widget, Page, Modal, Popup

Note:
For the Worker component, use the Worker.PubSub.subscribe method instead.

Syntax:

Copy

Parameters:

NameTypeDescription
eventName (required)String The name of the event to subscribe to
callBack (required)FunctionFunction that will respond to events sent from other components of the broadcasting app. It will be given the event object itself and the source of the event
receivePastEventsBooleanA flag to indicate that all past instances of the registered event should be sent to registered listener. This will happen immediately upon registration.

Example:

Copy

unsubscribe

Unsubscribes from receiving further events. The id from the initial subscribe call is used to unsubscribe from further notifications.

SDK Version: SDK 1.25.0+
Editor Version: New Editor, Old Editor
Display: Live Site, Preview
Components: Widget, Pinned (aka Fixed-Position) Widget, Page, Modal, Popup

Syntax:

Copy

Parameters:

NameTypeDescription
eventName (required)String The name of the event to unsubscribe from
function (required)Function The function that will respond to events sent from other extensions of the broadcasting app. It will be given the event object itself and the source of the event.

Example:

Copy
Was this helpful?
Yes
No