Skip to content

basketPreview.opened

basketPreview.opened is an event on the Event Bus that occurs whenever a basket preview dropdown is being opened.

Event body

The basketPreview.opened body has a TBasketPreviewOpenedBody type which represents the details of a basket preview that is currently being opened. It is optional so it might not exist.

Example

In this example we listen to basketPreview.opened event and perform an action whenever it's emitted.

useStorefront(async (storefront) => {
    storefront.eventBus.on('basketPreview.opened', ({ body }) => {
        if (!body.dropdown) return;

        console.log('Some basket-preview has been opened:', body.dropdown);
    });
});

Example

In this example we use a Message Storage API to retrieve an array of past basketPreview.opened events.

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

    const pastOpenedEvents = messageStorageApi.getChannelMessages('basketPreview.opened');

    if (pastOpenedEvents.length > 0) {
        pastOpenedEvents.forEach(({ body: eventBody }) => {
            console.log('perform action on every past event');
        });
    }
});

JS API reference