@one-view/event-broker
    TypeScript icon, indicating that this package has built-in type declarations

    1.3.3 • Public • Published

    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);

    Keywords

    Install

    npm i @one-view/event-broker

    DownloadsWeekly Downloads

    49

    Version

    1.3.3

    License

    MIT

    Unpacked Size

    25.4 kB

    Total Files

    6

    Last publish

    Collaborators

    • alipsidik
    • ramadimasatria
    • forex
    • ichsanrp
    • alicanakyuz
    • gabrielang-fp
    • hendra.wijaya
    • fp_apac_jonathan.sudibya
    • jianann-fp
    • shing-fp