Skip to content

removeChannelMessages(channelName: string): void

The removeChannelMessages is a method that allows to remove all past events from a given channel.

Sometimes, you'll need to clear the history of past events. This is useful when a web component or a feature that manages specific events is removed or no longer needed.

Example

Imagine a scenario with webcomponent which listens to all past FlashMessengerApi.addFlashMessage events when it loads. This ensures that if there were flash messages added before the component loaded, they will still be displayed.

However, if this <flash-messenger> component is removed and then added back to the page later, you likely don't want it to process all the old messages that users have already seen. Displaying them again could be confusing.

In this situation, the solution is to use the removeChannelMessages method. This will clear the event history for the flash messages. So, when the <flash-messenger> is added back, it won't process any previously displayed messages.

Input parameters

channelName

channelName is a mandatory parameter of the string type which represents the name of the event.

Returned value

A returned value has a type of void as this method does not return anything.

Example

In this example we make a messageStorageSystemApi call to remove an array of past events.

useStorefront((storefront) => {
    const messageStorageApi = storefront.getApiSync('messageStorageSystemApi');

    messageStorageApi.removeChannelMessages('product.stockChanged');
});

Webcomponent events reference

Webcomponents reference