commandBus.off¶
The off
method allows to remove a listener from the command 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 command
Example¶
To remove a listener from any command of the Command Bus you can use the off
method:
useStorefront(async (storefront) => {
function myFunction(commandMessage) {
console.log('Message name:', commandMessage.name);
}
storefront.commandBus.on('command-name', myFunction);
storefront.commandBus.off('command-name', myFunction);
});