Manual Reference Source Test
import IdentityEventbus from 'src/modules/identity-eventbus.js'
public class | source

IdentityEventbus

Identity event bus

Allows consumers to subscribe to generic events that may be interpreted to trigger specific calls. Events are dispatched when the IdentityEventbus#track method is called by implementors of the SDK.

Example:

const analytics = new IdentityEventbus({name: 'analytics'});
const unsubscribe = analytics.subscribe((event) => {
  { eventType = 'track', eventName, timestamp, properties = {} } = event;
  // interpret and send to analytics platform
});

// to stop observing at a later time:
unsubscribe();

// to dispatch an analytics event (by SDK implementors):
analytics.track('page_view', { foo: 'bar' });

Constructor Summary

Public Constructor
public

constructor(options: Object)

IdentityEventbus constructor

Method Summary

Public Methods
public

subscribe(callback: Function, options: Object): Function | Error

Subscribes a callback to receive all events.

public

track(eventName: String, properties: Object): Error

Adds a generic event to the event queue and publishes it to all subscribers

Public Constructors

public constructor(options: Object) source

IdentityEventbus constructor

Params:

NameTypeAttributeDescription
options Object
  • optional
  • default: {}

Options

options.maxQueuedEvents string
  • optional
  • default: 50

Maximum queue length

options.name string
  • optional

Observable name

Public Methods

public subscribe(callback: Function, options: Object): Function | Error source

Subscribes a callback to receive all events. If the deliverQueue option is set to true, the callback will immediately be invoked for all passed events in the event queue, limited to (by default) the last 50 events.

Params:

NameTypeAttributeDescription
callback Function
options Object
  • optional
options.deliverQueue boolean
  • optional
  • default: false

Return:

Function | Error

unsubscribe | error

public track(eventName: String, properties: Object): Error source

Adds a generic event to the event queue and publishes it to all subscribers

Params:

NameTypeAttributeDescription
eventName String
properties Object

Return:

Error

conditional error