1.3.3 • Published 4 years ago

@one-view/event-broker v1.3.3

Weekly downloads
162
License
MIT
Repository
github
Last release
4 years ago

Purpose

Provide a consistent manner in using the CustomEvent in DOM for message passing.

Usage

Example

import * as eventBroker from '@one-view/event-broker';

// Register an event listener
// Event are group by the 'event-group' namespace and identified by 'event-name'
// Behind the scene the event dom string is event-group.event-name
eventBroker.register('event-group', 'event-name', (payload) => {
    console.log('Event fired');
    return 'Event successfully fired';
});

// Emit an event
// Allows you to pass in data to the listening handler
// Using the example above, payload will be MyPayloadData
//
// Callback handler will be executed after the event is processed
//      reply: contain the return value of the listener handler. null if nothing.
//      err: contain the error if any error occur. null if nothing.
eventBroker.emit('event-group', 'event-name', MyPayloadData, (reply, err) => {
    console.log('Callback after event was handled');
});

const data = await eventBroker.emit('event-group', 'event-name', MyPayloadData);

// Unregister all handler associated with the event-group
eventBroker.unregisterByGroup('event-group');

// Unregister all event handler associated with the event-group and event-name
eventBroker.unregisterByName('event-group', 'event-name');

// Unregister a specific handler associated with the event-group and event-name
eventBroker.unregisterByName('event-group', 'event-name', handler);
1.3.3

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

5 years ago