0.2.0

The event emitter provides a typed pub/sub system for listening to tour, widget, and feature events. Access it through instance.api.events.

Methods

MethodDescription
on(eventName, handler)Subscribe a handler to an event
once(eventName, handler)Subscribe; auto-unsubscribes after first call
off(eventName, handler)Unsubscribe a specific handler
emit<T>(eventName, data?)Emit an event with optional data
remove(eventName)Remove all handlers for a specific event
clear()Remove all handlers for all events

Usage

import { BordaEvent } from '@retoo/borda';

// Subscribe
instance.api.events.on(BordaEvent.ON_TOUR_START, () => {
  console.log('Tour started');
});

// Unsubscribe
const handler = () => console.log('finished');
instance.api.events.on(BordaEvent.ON_TOUR_FINISH, handler);
instance.api.events.off(BordaEvent.ON_TOUR_FINISH, handler);

// One-time subscription
instance.api.events.once(BordaEvent.ON_TOUR_CLOSE, () => {
  console.log('Tour closed (once)');
});

Cleanup

All handlers are automatically cleared when the instance is unmounted. There is no need to unsubscribe manually before calling borda.unmount().

Events list

See the Events section for the full list of available events organized by category.