eventBus.off¶
The off method allows to remove a listener from the event similarly to how removeEventListener works for DOM events.
Input parameters¶
messageName¶
messageName is a mandatory parameter of the string type which represents the name of the targeted message.
listenerToRemove¶
listenerToRemove is a mandatory parameter of type TMessageListener which represents a callback that should be removed from the given event
Example¶
To remove a listener from any event of the Event Bus you can use the off method:
useStorefront(async (storefront) => {
function myFunction(event) {
console.log('Event:', event.name);
}
storefront.eventBus.on('event-name', myFunction);
storefront.eventBus.off('event-name', myFunction);
});