FlashMessengerApi.removeAllFlashMessages¶
FlashMessengerApi.removeAllFlashMessages
is an event on the Event Bus that occurs whenever the Flash Messenger is ordered to remove all its messages.
Event body¶
The FlashMessengerApi.removeAllFlashMessages
body has a TFlashMessageEvent type which represents the details about the <flash-messenger>
from which the messages will be removed. It is optional so it might not exist.
Example¶
In this example we listen to FlashMessengerApi.removeAllFlashMessages
event and perform an action whenever it's emitted.
useStorefront(async (storefront) => {
storefront.eventBus.on('FlashMessengerApi.removeAllFlashMessages', ({ body }) => {
console.log('Flash messages will be removed from flash-messenger with name:', body.containerName);
});
});
Example¶
In this example we use a Message Storage API to retrieve an array of past FlashMessengerApi.removeAllFlashMessages
events.
useStorefront((storefront) => {
const messageStorageApi = storefront.getApiSync('messageStorageSystemApi');
const pastRemoveAllFlashMessagesEvents = messageStorageApi.getChannelMessages('FlashMessengerApi.removeAllFlashMessages');
if (pastRemoveAllFlashMessagesEvents.length > 0) {
pastRemoveAllFlashMessagesEvents.forEach(({ body: eventBody }) => {
console.log('perform action on every past event');
});
}
});