Events

Principle

The bGDPR core object is an event manager. You can listen and dispatch events using it.

Only listened events are dispatched. So no event is dispatched until a related event is declared.

How to listen an event

To listen an event, you can use the on method. It returns a PseudoPromise that has to be subscribed. The subscription function get a parameters that contains the name of the event and contextual data.

import { ServiceEvents } from 'bim-gdpr/src/services/ServiceEvents'

bGDPR.on(ServiceEvents.serviceStart).then( data => {
        console.log('data', data);
    })

A list of available events can be found :

How to dispatch an event

You can dispatch your own events using the trigger method. This methods needs the name of the event trigger. You can also send contextual data.

For better use, please export the name of your custom event. By this way, you facilitate the use of your event by third-party users.

    export const MY_OWN_EVENT='bgdpr-my-own-event'
    bGDPR.trigger(
        MY_OWN_EVENT, 
        { 
            my_own_data_1: 'my_own_value_1',
            my_own_data_2: 'my_own_value_2'
        })