TomTom Maps for JavaScript
    Preparing search index...

    Class ModuleEvents<TConfig, TShownFeatures>

    Lifecycle event module for map modules.

    Provides a unified API for subscribing to module-level events that are not tied to user interaction with map features. Two event types are supported:

    • config-change: emitted whenever the module's configuration is updated (via applyConfig, resetConfig, or any module-specific setter that mutates config).
    • shown-features: emitted by modules that have a show method, immediately after features are displayed on the map.

    Each on() call returns an unsubscribe function so individual handlers can be removed without clearing the entire listener list.

    const unsubscribeConfig = trafficFlow.events.on('config-change', (config) => {
    console.log('New config:', config);
    });

    const unsubscribeShown = places.events.on('shown-features', (features) => {
    console.log('Shown:', features);
    });

    // Later:
    unsubscribeConfig();
    unsubscribeShown();

    Type Parameters

    • TConfig

      The module's configuration type.

    • TShownFeatures = never

      The type of data passed to show(). Use never for modules that have no show method.

    Index

    Constructors

    Methods

    Constructors

    Methods

    • Remove all handlers for the given event type at once.

      Prefer the unsubscribe function returned by on when you need to remove a single handler. Use off for bulk teardown — e.g. when unmounting a component that registered multiple handlers.

      Parameters

      • type: "config-change" | "shown-features"

        The event type whose handlers should all be cleared.

      Returns void

      // Clear all config-change listeners in one call
      trafficFlow.events.off('config-change');
    • Subscribe to config-change events.

      The handler is called with the module's full current configuration immediately after any mutation — whether through applyConfig, a module-specific setter, or resetConfig.

      Parameters

      • type: "config-change"

        'config-change'

      • handler: (config: TConfig | undefined) => void

        Receives the module's config (or undefined when config is cleared).

      Returns () => void

      An unsubscribe function. Call it to remove only this handler without affecting other registered handlers for the same event type.

      const unsub = trafficFlow.events.on('config-change', (config) => {
      toggle.checked = config?.visible ?? false;
      });

      // Later:
      unsub();
    • Subscribe to shown-features events.

      The handler is called immediately after a module's show() method (or equivalent) has updated the map with new data. Only available on modules that have a show method.

      Parameters

      • type: "shown-features"

        'shown-features'

      • handler: (features: TShownFeatures) => void

        Receives the data that was passed to show().

      Returns () => void

      An unsubscribe function. Call it to remove only this handler without affecting other registered handlers for the same event type.

      const unsub = places.events.on('shown-features', (features) => {
      fitMapToResults(features);
      });

      // Later:
      unsub();